在 Quickblox Chat sdk 中聊天/1:1 聊天

Posted

技术标签:

【中文标题】在 Quickblox Chat sdk 中聊天/1:1 聊天【英文标题】:Chat/1:1 Chat in Quickblox Chat sdk 【发布时间】:2015-02-04 12:18:05 【问题描述】:

如何在两个用户之间的 quickblox 私人聊天中获得离线和在线用户。 如果两个用户 Jone 和 kally 如果 kally 离线,那么如何在此处获取离线用户 Kally 我的代码的状态。请检查并帮助我。

         try 
            QBChatMessage chatMessage = new QBChatMessage();
            chatMessage.setBody(inputbox.getText().toString()); 
            chatMessage.setProperty("save_to_history", "1"); 
            long time = System.currentTimeMillis()/1000;
            chatMessage.setProperty("date_sent", time + "");
            privateChat.sendMessage(chatMessage);
            showMessage(chatMessage);
            inputbox.setText("");
         catch (XMPPException e) 
            Log.e("XMPPException",e.toString());
         catch (SmackException.NotConnectedException e) 
            Log.e("Not Connected Exception",e.toString());
        catch (NullPointerException e) 
            Log.e("NullPointerException", e.toString());
        catch (Exception e) 
            Log.e("Exception", e.toString());
        

       QBPrivateChatManagerListener privateChatManagerListener = new              QBPrivateChatManagerListener() 
    @Override
    public void chatCreated(final QBPrivateChat privateChat, final boolean createdLocally) 
        if(!createdLocally)
            privateChat.addMessageListener(privateChatMessageListener);
        
    
;

QBMessageListener<QBPrivateChat> privateChatMessageListener = new QBMessageListener<QBPrivateChat>() 
    @Override
    public void processMessage(QBPrivateChat privateChat, final QBChatMessage chatMessage) 
        Log.w(Tag, "new incoming message: chatMessage" + chatMessage);
        showMessage(chatMessage);
        playBeepSound(mContext);
    

    @Override
    public void processError(QBPrivateChat privateChat, QBChatException error, QBChatMessage originMessage)
        Log.w(Tag, "new incoming message: originMessage" + originMessage);
    

    @Override
    public void processMessageDelivered(QBPrivateChat privateChat, String messageID)
        Log.w(Tag, "new incoming message:messageID " + messageID);
    

    @Override
    public void processMessageRead(QBPrivateChat privateChat, String messageID)
        Log.w(Tag, "new incoming message:messageID messageID" + messageID);
    
;
private void createNewDialog()
    privateChatManager = QBChatService.getInstance().getPrivateChatManager();
    privateChatManager.createDialog(opponentId, new QBEntityCallbackImpl<QBDialog>() 
        @Override
        public void onSuccess(QBDialog dialog, Bundle args) 
            //Log.e("QBdialog", ""+dialog);
            //Log.e("id", dialog.getDialogId());
            setUpListener();
            isQBDialog = true;
        

        @Override
        public void onError(List<String> errors) 
            Log.e("errors", ""+errors);
            isQBDialog = false;

        
    );


private void setUpListener()
privateChatManager.addPrivateChatManagerListener(privateChatManagerListener);
    privateChat = privateChatManager.getChat(opponentId);
    if (privateChat == null) 
        privateChat = privateChatManager.createChat(opponentId, privateChatMessageListener);
        privateChat.addIsTypingListener(privateChatIsTypingListener);

    else
        privateChat.addMessageListener(privateChatMessageListener);
        privateChat.addIsTypingListener(privateChatIsTypingListener);
    

我正在关注聊天链接 http://quickblox.com/developers/android_XMPP_Chat_Sample

【问题讨论】:

【参考方案1】:

我还尝试为一对一聊天实现 quickblox 聊天,但由于文档不够充分,我陷入了困境。然后我发现socket.io更方便一对一聊天。点击链接:http://socket.io/blog/native-socket-io-and-android/。您还必须找到免费的 node.js 托管公司。我可以向你推荐 heroku.com

【讨论】:

【参考方案2】:

您可以添加监听器来跟踪用户状态 - RosterListener。

例如:

https://github.com/QuickBlox/q-municate-android/blob/master/Q-municate_core/src/main/java/com/quickblox/q_municate_core/qb/helpers/QBFriendListHelper.java

Q-municate 实时跟踪用户状态(私人和群聊)。

【讨论】:

以上是关于在 Quickblox Chat sdk 中聊天/1:1 聊天的主要内容,如果未能解决你的问题,请参考以下文章

Xamarin C# SDK 中的 Quickblox 聊天设置 save_to_history 为 true

使用 QuickBlox JS SDK 列出房间在线用户数

无法解决:com.quickblox:quickblox-android-sdk-chat:2.6.1

QBRoomChatManager 类在以后的 Quickblox 库中不存在 - quickblox-sdk-release-2

Quickblox Android sdk 2.0 Beta 缺少一些类

Quickblox 在一对一聊天中改变对手