[英]Read unread message in JSQMessagesViewController using Swift 3
I'm trying this method on button click but not get result: 我正在按钮单击时尝试此方法,但未获得结果:
@IBAction func childAdded(_ sender: Any) {
let ref = Constants.refs.databaseChats.childByAutoId()
ref.observe(DataEventType.childAdded , with: { (snapshot) in
let msgData = snapshot.value as? NSDictionary
let msg = msgData?["status"] as? String
if msg == "sent" {
let prntRef = Constants.refs.databaseChats.child("chats").child(ref.key)
prntRef.updateChildValues(["status":"Read"])
print("Message Read")
}
}) { (e) in
print(e.localizedDescription)
}
}
There are a few ways of doing this and some have advantages over others. 有几种方法可以做到这一点,有些方法比其他方法更具优势。 One solution would be to store a variable like
lasReadVariable
or something, in firebase
. 一个解决办法是存储像变量
lasReadVariable
什么的, firebase
。 that is the last read message for user1 then every time the chatView
is opened update that lasReadVariable
for last read message on this thread. 这是user1的最后读取消息,然后每次打开
chatView
时, chatView
更新该线程上最后读取的消息lasReadVariable
。 Have an observer
for user2 in the conversation on the lasReadVariable
and update the messageState
accordingly. 在
lasReadVariable
上的对话中有一个user2的observer
,并相应地更新messageState
。
Let me know if there is more clarification I can give. 让我知道是否还有更多需要澄清的地方。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.