admin管理员组文章数量:1401660
I'm trying to get the number of messages unread for a specific member in a specific channel. To do this I was hoping to use channel.getUnconsumedMessagesCount() as defined in the documentation.
myChannel.join()
.then(function(c) {
console.log('Joined channel ' + c.sid);
return myChannel.getUnconsumedMessagesCount();
})
.then(m => {
console.log('current count unread: ' + m);
});
The unread count always return 0. To test, I do the following:
- user 2 submitting a message to myChannel in another chrome tab
- user 2 myChannel get's updated with the message from (1) via .on('messageAdded', [...])
- refresh user 1 chrome tab, and get getUnconsumedMessagesCount with value of 0
- If I call myChannel.getMessages() for user1, I see the message from user2
Initially I called .getUnconsumedMessagesCount() without doing join() first, I thought this could be the issue, but even with join still nothing.
I'm trying to get the number of messages unread for a specific member in a specific channel. To do this I was hoping to use channel.getUnconsumedMessagesCount() as defined in the documentation.
myChannel.join()
.then(function(c) {
console.log('Joined channel ' + c.sid);
return myChannel.getUnconsumedMessagesCount();
})
.then(m => {
console.log('current count unread: ' + m);
});
The unread count always return 0. To test, I do the following:
- user 2 submitting a message to myChannel in another chrome tab
- user 2 myChannel get's updated with the message from (1) via .on('messageAdded', [...])
- refresh user 1 chrome tab, and get getUnconsumedMessagesCount with value of 0
- If I call myChannel.getMessages() for user1, I see the message from user2
Initially I called .getUnconsumedMessagesCount() without doing join() first, I thought this could be the issue, but even with join still nothing.
Share Improve this question asked Jan 29, 2017 at 7:33 guiomieguiomie 5,1488 gold badges40 silver badges67 bronze badges 2- 1 Sorry for the slow reply here. I can't see anything you've done wrong here, so it might be an issue on the Twilio side. I remend getting in touch with Twilio support and sending them the details, including the Chat Service SID that you're using. – philnash Commented Feb 7, 2017 at 15:14
- Support ... oh no :/ Alright, thx. – guiomie Commented Mar 8, 2017 at 5:14
2 Answers
Reset to default 5before you can get UnconsumedMessagesCount you need manually set last read message (Send a Consumption Report)
something like this (JS)
channel.getMessages(1).then(function (messages) {
var last_message_index = messages.items[0].index;
channel.updateLastConsumedMessageIndex(last_message_index);
});
I am having the same issue with the javascript SDK where it always returns 0.
I ended up doing the following which is working
const count = channel.getMessagesCount();
const unreadCount = channel.lastConsumedMessageIndex === null ? count : count - channel.lastConsumedMessageIndex - 1
I also noticed that using any of the functions to set the messages consumed can take up to a full minute before actually returning that information in the channel.lastConsumedMessageIndex
本文标签: javascriptTwilio Chat APIgetUnconsumedMessagesCount always 0Stack Overflow
版权声明:本文标题:javascript - Twilio Chat API, getUnconsumedMessagesCount always 0 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744219209a2595782.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论