简体   繁体   English

Firebase 社交媒体聊天应用

[英]Firebase Chat Application with Social Media

I have a social media app written in Flutter. Users can see the profiles each other and block/unblock them.我有一个用 Flutter 编写的社交媒体应用程序。用户可以互相查看个人资料并阻止/取消阻止他们。 I'm using MySQL to keep that data.我正在使用 MySQL 来保存该数据。 Now I want to implement chat feature using Firebase Firestore (or maybe MongoDB).现在我想使用 Firebase Firestore(或者 MongoDB)来实现聊天功能。 When a user sends a message to another user, should I check if user blocked another user from MySQL every time, so user can't send new message.当用户向另一个用户发送消息时,我是否应该每次都检查用户是否从 MySQL 阻止了另一个用户,以便用户无法发送新消息。 Is this a good practice in chat application, or should I store the "blocked" data at Firebase also.这是聊天应用程序中的一个好习惯,还是我也应该将“阻止的”数据存储在 Firebase。

I researched this subject deeply but didn't find any solution.我深入研究了这个主题,但没有找到任何解决方案。

So you can code like most of the current social media works.所以你可以像当前大多数社交媒体作品一样编码。

Simply let the user send a message but put a condition on the receiver user side so if the user is blocked by the receiver then it should not show the chat in the user chat list also should not send a notification if the user is blocked by the receiver.简单地让用户发送一条消息,但在接收方用户端设置一个条件,这样如果用户被接收方阻止,那么它不应该在用户聊天列表中显示聊天,如果用户被阻止,也不应该发送通知接收者。

Like when user is trying to send a message to another user so in the list of the recipients you are also retrieving the value for (is particular user is blocked by the current user), if it's so you are checking this on that time.就像当用户试图向另一个用户发送消息时,您也在收件人列表中检索值(特定用户是否被当前用户阻止),如果是这样,您当时正在检查它。

Secondly, if you want this to check when sending to server.其次,如果您希望在发送到服务器时进行检查。 So, you can manage this using firestore transaction in which you might get the object of the sender and check to whom the sender has blocked and you may throw an exception.因此,您可以使用 firestore 事务来管理此事务,在该事务中您可能会获得发件人的 object 并检查发件人阻止了谁,您可能会抛出异常。 The other thing you might manage it using Firestore Security Rules as well.另一件事你也可以使用 Firestore 安全规则来管理它。

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

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