Karthick
Karthick

Reputation: 443

Rails 4 mailboxer conversation delete a participant

I have used to mailboxer gem for messages in rails.I want to remove a participant from a conversation.How do delete it? anyone can tell me.

Upvotes: 0

Views: 422

Answers (2)

David Lin
David Lin

Reputation: 1

You can try opt_out(participant). It removes the participant from the conversation. This worked for me.

Here is the source

@conversation.opt_out(@user)

Upvotes: 0

Donald
Donald

Reputation: 1

In case you're still looking for an answer, I just came across the same issue and found something interesting.

In my scenario, I have teams of users, who share a common conversations. Hence, the team object holds a conversatoin_id. Every time a team is created or a person joins the team, a new conversation is created or that new person is added to the existing conversation with the add_participant(user) function.

I came across this issue, since my users now need to be able to leave a team, which implies them being ejected from the team_conversation.

Looking into the source code of the Mailboxer Gem, it's possible to see that add_participant(user) function actually creates a new receipt, for every message ever created in the conversation, and uses the user from the add_participant(user) call as the receiver.

Hence, in order to reverse this and, thereby, to delete someone from a conversation, you can do

@user_receipts = @conversation.receipts_for(user)
@user_receipts.destroy_all

That worked out fine for me. However, watch out. Since this deletes all the receipts of that user for the given conversation, should you ever wish to check out what the user wrote in the conversation, you'd have to find another user who is still active and who was active at the time when the user-who-left was active. Anyway, I hope it fixes your problem and if you have any more questions, let me know. D

Upvotes: 0

Related Questions