【问题标题】:getting null while calling for messages on current channel in Twilio chat android在 Twilio 聊天 android 中调用当前频道上的消息时为空
【发布时间】:2016-11-24 06:14:11
【问题描述】:

最近我更新了我的应用程序以支持最近的version twilio chat 0.11.1。之后,当我调用 currentChannel.getMessages() 时,它返回 null。 我正在这样做

        Channels channelsObject = basicClient.getIpMessagingClient
        channelsObject.getChannel(channelId, new CallbackListener<Channel>() {
                    @Override
                    public void onSuccess(final Channel channel) {
                        currentChannel = channel;
                        setupRecyclerView();
                    }
                });
        private void setupRecyclerView() {
              currentChannel.addListener(ChatFragment.this);
              currentChannel.synchronize(new com.twilio.chat.CallbackListener<Channel>() {
              @Override
              public void onError(ErrorInfo errorInfo) {
                Application.get().logErrorInfo("Channel sync failed", errorInfo);
              }

              @Override
              public void onSuccess(Channel result) {
                logger.d("Channel sync success for " + result.getFriendlyName());
            }
        });
        Messages messagesObject = currentChannel.getMessages();

我收到类似

的警告
 | WARNING  | ChatUtils(native) | ListenerWrapper default onSuccess() not found
| WARNING  | Channel(native) | No messages available, maybe you forgot to synchronize the channel?

【问题讨论】:

    标签: android chat twilio


    【解决方案1】:

    没有可用的消息,也许您忘记同步频道?

    这正是正在发生的事情。只有当您收到CallbackListener.onSuccess() 回调时,才会同步频道。它是异步执行的,您的 getMessages() 调用会在回调触发之前执行。

          currentChannel.synchronize(new com.twilio.chat.CallbackListener<Channel>() {
              @Override
              public void onError(ErrorInfo errorInfo) {
                Application.get().logErrorInfo("Channel sync failed", errorInfo);
              }
    
              @Override
              public void onSuccess(Channel result) {
                logger.d("Channel sync success for " + result.getFriendlyName() + " now can get messages and members objects");
                Messages messagesObject = result.getMessages();
                // should be non-null now
              }
          });
    

    【讨论】:

    • 谢谢我明白了。但是第一次同步需要一些时间(3 或 4 秒)。这是预期的吗?
    • 这是需要在 SDK 中优化的东西 - 你在空通道上得到 3-4 秒吗?
    • 是的。空通道也需要 3-4 秒。
    • 能否请您从慢速同步运行中保存整个 adb 日志(不要忘记在运行之前发出 ChatClient.setLogLevel(Android.Log.DEBUG); 以获取完整日志)并将其发布到 gist.github.com 之类的地方?我想看看。
    • JFYI 在 SDK 版本 1.0.0 或更高版本中不再有显式的 synchronize() 调用,但通道仍然是隐式同步的,您应该检查同步状态 - 如果您需要,它至少应该是 METADATA如果要接收消息和成员集合,则要提取频道名称、sid 或属性,以及 ALL
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 1970-01-01
    • 2020-04-21
    相关资源
    最近更新 更多