使用Firebase设置群聊的阅读状态 [英] Set read status for a group chat using Firebase

查看:76
本文介绍了使用Firebase设置群聊的阅读状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个聊天应用程序,其中包含用户之间的单独聊天以及使用Firebase进行的群聊.我想为每条消息设置一个读取状态,现在的问题是,考虑群聊中有一个节点

I am trying to make a chat application containing individual chat between users and group chat using Firebase. And I would like to make a read status for each message, Now the problem is, consider a group chat have a node

> groupId---->
>         --->messageId
>                  -->userId
>                  -->messageType
>                  -->text

我的意思是,如果某用户向某组发送一条消息,该消息将添加到具有消息ID节点的组ID下,并且所有正在收听该组的用户现在都将收到该子消息,我想保持谁的状态都阅读了邮件.我可以通过保持本地状态来处理它,但是如果用户从另一台设备登录,该如何处理呢?

My implimentation is like if a user sending a message to a group that will be added under group id with message id node and who are all listening to the group will get that child message now I want to keep a status for who are all read the message. I can handle it by keeping a local status, But if the user logging from another device how can I handle that?

推荐答案

如果要跟踪用户是否已阅读每条消息,则需要将其存储在数据库中:

If you want to track whether a user had read each message, you'll need to store that in your database:

read_messages_per_user
  <userId>
    <messageId>: true

随着时间的流逝,这可能会变成大量数据.因此,一种更有效(但不太具体)的变体是存储用户阅读的最后一条消息.

This may become a lot of data over time. So a more efficient (but less specific) variant is to store the last message that the user read.

last_read_messageId_per_user
  <userId>: <messageId>

这篇关于使用Firebase设置群聊的阅读状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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