Twilio Chat API,getUnconsumedMessagesCount始终为0 [英] Twilio Chat API, getUnconsumedMessagesCount always 0

查看:215
本文介绍了Twilio Chat API,getUnconsumedMessagesCount始终为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取特定频道中特定成员的未读消息数。为此,我希望使用 channel.getUnconsumedMessagesCount() /docs/Channel.html#getUnconsumedMessagesCount__anchor\"rel =noreferrer>文档

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);
  });

未读计数总是返回0.要测试,我会执行以下操作:

The unread count always return 0. To test, I do the following:


  1. 用户2在另一个Chrome选项卡中向myChannel提交消息

  2. 用户2 myChannel获取更新来自(1)的消息通过
    .on('messageAdded',[...])

  3. 刷新用户1 chrome标签,获取
    值为0的getUnconsumedMessagesCount

  4. 如果我为user1调用myChannel.getMessages(),我会看到来自user2的消息

  1. user 2 submitting a message to myChannel in another chrome tab
  2. user 2 myChannel get's updated with the message from (1) via .on('messageAdded', [...])
  3. refresh user 1 chrome tab, and get getUnconsumedMessagesCount with value of 0
  4. If I call myChannel.getMessages() for user1, I see the message from user2

最初我调用了.getUnconsumedMessagesCount()没有首先做join(),我认为这可能是问题,但即使加入仍然没有。

Initially I called .getUnconsumedMessagesCount() without doing join() first, I thought this could be the issue, but even with join still nothing.

推荐答案

我对javascript SDK遇到同样的问题,它总是返回0。

I am having the same issue with the javascript SDK where it always returns 0.

我最终做了以下工作

const count = channel.getMessagesCount();
const unreadCount = channel.lastConsumedMessageIndex === null ? count : count - channel.lastConsumedMessageIndex - 1

我还注意到使用任何函数来设置消耗的消息可能需要一整分钟才能在channel.lastConsumedMessageIndex

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

这篇关于Twilio Chat API,getUnconsumedMessagesCount始终为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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