0

I need to implement very simple messaging system between 2 users, and the only requirement is to keep every conversation between 2 users separate. I wonder whether it's possible and reasonable to use only one model Message(sender_id, recipient_id ) to achieve the goal.

Suppose, I want to get index of all conversations.

  • Join on user.id = recipient_id and user.id = sender_id to get all messages associated with specific user
  • Order results by id of opposed participants(whether it is sender_id or recipient_id) to form groups of messages - chatboxes. This is I think the most difficult step, since opposed user might be a sender or a receiver in one conversation.
  • Further order results inside each group by date of creation to show messages in their original order. Each group denotes a different conversation.

I tried Mailboxer gem, but it seems to be overkill for this case. I also think of a different solution based on introduction of new Conversation entity with one-to-many relation with messages.

tshepang
  • 12,111
  • 21
  • 91
  • 136
user1756971
  • 155
  • 1
  • 8

3 Answers3

0

I think simple-private-messages will solve your problem. It seems simple and looks exactly like what you are looking for.

usha
  • 28,973
  • 5
  • 72
  • 93
  • Seems to be good one, but what i'm exactly looking for is the way to group messages that belong to one conversation between 2 people, like `@user.conversations[0].messages` – user1756971 Sep 20 '13 at 20:00
0

It seems that there is no such lightweight implementation of messaging that involves grouping them by conversation. The best solution seems to be implementing it from scratch.

user1756971
  • 155
  • 1
  • 8
-1

You should also give a look at faye server https://github.com/jamesotron/faye-rails & http://railscasts.com/episodes/260-messaging-with-faye

techvineet
  • 5,041
  • 2
  • 30
  • 28