允许用户在消息传递应用程序中同时向多个用户发送消息 [英] Allow users to send messages to multiple users simultaneously in a messaging app

查看:164
本文介绍了允许用户在消息传递应用程序中同时向多个用户发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在消息传递应用程序中将一条消息同时发送给几个朋友?我在Django问题中读到,这种设计是M2M关系.您定义了2个模型(User和SentMessage),后端创建了第三个对象?

How is a single message sent to several friends simultaneously in messaging applications? I read in a Django question that this design is a M2M relation. You define 2 models (User and SentMessage) and the backend creates a third object?

例如,微信和Facebook Messenger允许您选择多个朋友并同时向他们发送一条消息.在iOS,Parse或您自己的Node.js后端中如何完成?

For example, Wechat and Facebook Messenger allow you to select multiple friends and send a single message to them simultaneously. How is this done in iOS, Parse or your own Node.js backend?

您定义自己的课程.

user["username"] = String
user["sex"] = String
user["age"] = Int

///

let messageObj = PFObject(className: "Messages")   
messageObj["sender"] = PFUser.current()?.username
messageObj["message"] = messageTextView.text
messageObj["likes"] = [String]()

您如何允许将消息发送到:
答:所有用户同时.
B.具有特定属性的用户,例如["age"]或["sex"]同时出现.

How would you allow for the sending of messages to:
A. All users simultaneously.
B. Users with specific attributes e.g. ["age"] or ["sex"] simultaneously.

随时为其他服务器提供解决方案.

Feel free to contribute solutions for other servers.

推荐答案

在Firebase中,您也使用第三个表"对多对多关系进行建模,在该表中,您将实体1的项目连接到实体2的项目.有关更多信息,请参见 Firebase中的多对多关系

In Firebase you model many-to-many relationships with a third "table" too, where you connect items from entity1 one to items of entity2. For more on this see Many to Many relationship in Firebase

但是对于聊天应用程序,我通常会对该用例进行不同的建模.向一组用户发送消息通常会在这些应用程序中启动一个临时聊天室.如果其中一个用户回答,则该回答将发送给该​​组中的其他所有人.因此,您实际上已经启动了一个临时聊天室,该聊天室由其中的人标识.

But in the case of a chat app, I'd typically model this use-case differently. Sending a message to a group of users typically starts an ad-hoc chat room in those apps. If one of the users answers, that answer goes to everyone else in the group. So you've essentially started a temporary chat room, one that is identified by the people in it.

我通常建议以参与者的身份在Firebase中命名该临时聊天室.有关更多信息,请参见: http://stackoverflow.com/questions /33540479/在火力发电厂中管理聊天频道的最佳方法.在该模型中,如果您和我开始聊天,我们的房间将是:uidOfMat_uidOfPuf.因此,我们的JSON如下所示:

I typically recommend naming this ad-hoc chat room in Firebase after its participants. For more on this, see: http://stackoverflow.com/questions/33540479/best-way-to-manage-chat-channels-in-firebase. In that model, if you and I start a chat our room would be: uidOfMat_uidOfPuf. So our JSON would look like:

chats: {
  "uidOfMat_uidOfPuf": {
    -Labcdefgh1: {
      sender: "uidOfMat",
      text: "How is a single message sent to several friends simultaneously in messaging applications?"
    }
    -Labcdefgh2: {
      sender: "uidOfPuf",
      text: "In Firebase you model many-to-many relationships with a third "table" too..."
    }

由于聊天室是由参与者定义的,因此无论您和我何时聊天,我们最终都将位于同一聊天室中.很方便!

Since the chat room is defined by its participants, any time you and I chat, we end up in this same chat room. Quite handy!

现在说,我要求某人帮助,通过将他们拉入聊天室来回答您的问题.由于聊天室是由其参与者定义的,因此添加新参与者将创建一个新的聊天室:uidOfMat_uidOfPuf_uidOfThird.所以我们最终得到:

Now say that I ask someone for help answering your question by pulling them into the chat. Since the chat room is defined by its participants, adding a new participant creates a new chat room: uidOfMat_uidOfPuf_uidOfThird. So we end up with:

chats
  uidOfMat_uidOfPuf
    -Labcdefgh1: {
      sender: "uidOfMat",
      text: "How is a single message sent to several friends simultaneously in messaging applications?"
    }
    -Labcdefgh2: {
      sender: "uidOfPuf",
      text: "In Firebase you model many-to-many relationships with a third "table" too..."
    }
  }
  "uidOfMat_uidOfPuf_uidOfThird": {
    -Labcdefgh3: {
      sender: "uidOfPuf",
      text: "Hey Third. Puf here. Mat is wondering how to send a single message to several friends simultaneously in messaging applications. Do you have an idea?"
    }
    -Labcdefgh4: {
      sender: "uidOfThird",
      text: "Yo puf. Long time no see. Let me think for a moment..."
    }

这里需要注意的几件事:

A few things to notice here:

  • 在到目前为止使用的模型中,如果将另一个人添加到uidOfMat_uidOfPuf_uidOfThird聊天室中,则会再次创建一个新的聊天室.

  • In the model we've used so far, if we'd add yet another person to the uidOfMat_uidOfPuf_uidOfThird chat room, that would again create a new chat room.

许多聊天应用程序为您提供了命名群组聊天室的选项.在许多情况下,将用户添加到这样的命名聊天室中确实可以使他们访问消息历史记录.我倾向于将这些房间称为永久聊天室,因为它们可以访问历史聊天消息.

Many chat apps give you the option to name a group chat room. In many cases adding a user to such a named chat room does give them access to the message history. I tend to refer to such rooms as persistent chat rooms, since they give access to the historical chat messages.

在上面的示例中,假设我们将1:1房间命名为"model_chat_room".这意味着将第三人添加到会议室中,将使他们能够立即访问我们的消息历史记录.

In our above sample, say that we'd named our 1:1 room "model_chat_room". That would mean that adding the third person to the room, would have given them access to our message history straight away.

一方面很方便,因为我不必重复您的问题.另一方面,Matt还可以查看我们的整个对话历史记录.许多人认为1:1聊天对话是私人的,这就是为什么只有在3个或更多参与者的情况下才进行持久聊天室"模型的原因.

On the one hand that is handy, because I wouldn't have had to repeat your question. On the other hand, Matt could have also seen our entire conversation history. Many people consider 1:1 chat conversations private, which is why the "persistent chat room" model is usually only followed for named chats with 3 or more participants.

这篇关于允许用户在消息传递应用程序中同时向多个用户发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆