Question

I can get the last sender of a message:

conversation.receipts_for(current_user).last.message.sender.name

but cannot get the recipient(s) of that same message. I would like to display gmail-esk:

Sender name, Recipient name | Subject | Date

Any ideas?

Was it helpful?

Solution 2

I created this method in a helper file:

  def participant_names(conversation)
    conversation.receipts.reject { |p| p.receiver == current_user }.collect {|p| p.receiver.name }.uniq.join(" ,")
  end

What this is doing is, removing the current_user from the conversation object, then creates a new array that contains the names for (in this case users) that conversation object. the '.uniq' method ensures that each users name is only displayed once (in the case there have been many message back and forth conversation). Finally comma separates them.

OTHER TIPS

There is a participants method with mailboxer, but I believe there is no recipient(s). Instead, I created this:

recipient = conversation.participants.find { |p| p != current_user }

Note that current_user comes from devise.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top