简体   繁体   English

Rails一对一消息传递

[英]Rails messaging one to one

Want to create real time direct messaging with user to user association, Though cant see exactly how to create this. 要创建与用户到用户关联的实时直接消息传递,尽管无法确切知道如何创建它。

Example: User1 clicks the image of User2 from their contacts list, User1 creates a message and it sends to User2. 示例:User1从其联系人列表中单击User2的图像,User1创建一条消息并将其发送给User2。 User2 can see the message and replies back (like instant messaging) and both users see the same messages. User2可以看到该消息并进行回复(例如即时消息),并且两个用户都可以看到相同的消息。

The message would have a title, image and body (each being available but not mandatory) The old messages and new message ability would be on the same page with old messages above the new message ability. 该消息将具有标题,图像和正文(均可用,但不是必需的)。旧消息和新消息功能将在同一页面上,而旧消息则高于新消息功能。

There is also the idea of how the messages are represented when reaching a user, if they are in conversation the messages appear in real time, if not in conversation then the contacts image would appear on the conversation page. 还有一个想法是,消息在到达用户时如何表示,如果它们在对话中,则消息实时显示,如果不在对话中,则联系人图像将出现在对话页面上。 Where you click a user to see the conversation. 您在其中单击用户以查看对话的位置。

I think part of the trouble is how do you identify the second user. 我认为麻烦的一部分是如何识别第二个用户。 Thinking along the below lines: 按照以下思路思考:

model User: 模型用户:

has_many :conversations
has_many :messages through => conversations

model Conversation: 模型对话:

has_many :messages
has_many :users

model Message: 型号留言:

belongs_to :users through => conversations
has_many :conversations

The tables would be along the line of: 这些表将遵循以下路线:

message: 信息:

body
title
image
conversation_id

conversation: 会话:

message_id
user_id

user: 用户:

id

Any ideas/thoughts? 有什么想法/想法吗?

Try this: 尝试这个:

user.rb: user.rb:

has_many :messages
has_and_belongs_to_many :conversations
# id

message.rb message.rb

belongs_to :user
belongs_to :conversation
# body
# title
# image
# conversation_id
# user_id

conversation.rb talk.rb

has_many :messages
has_and_belongs_to_many :users
# id

conversations_users.rb sessions_users.rb

belongs_to :user
belongs_to :conversation
# conversation_id
# user_id

Note: With this structure can also have more than two members. 注意:使用此结构还可以具有两个以上的成员。

Hope this help. 希望对您有所帮助。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM