目录

会话管理

获取用户所有会话

getConversationsBtn.onClick.AddListener (delegate() {
    logText.text = "conversation list:\n";
    List<EMConversation> conversations = EMClient.Instance.GetAllConversations();
    foreach(EMConversation conv in conversations){
        logText.text += conv.mConversationId;
        if(conv.mLastMsg != null)
            logText.text += ",lastmsgId=" + conv.mLastMsg.mMsgId;
        logText.text += "\n";
    }
});

获取会话最新消息

getLastMsgBtn.onClick.AddListener (delegate() {
    if(fromUser.text.Length == 0) {
        fromUser.placeholder.GetComponent<Text>().text = "input here first";
        return;
    }
    EMMessage message = EMClient.Instance.GetLatestMessage(fromUser.text);
    if(message != null) {
        msgId.text = message.mMsgId;
        logText.text = message.mMsgId;
    }
});

获取会话指定消息

getMessageBtn.onClick.AddListener (delegate() {
    if(fromUser.text.Length == 0) {
        fromUser.placeholder.GetComponent<Text>().text = "input here first";
        return;
    }
    logText.text = "";
    List<EMMessage> list = EMClient.Instance.GetConversationMessage(fromUser.text,msgId.text,20);
    foreach(EMMessage msg in list){
        logText.text += "msg id:"+msg.mMsgId+",from:"+msg.mFrom;
        if(msg.mType == MessageType.TXT)
            logText.text += ",txt:"+msg.mTxt;
        if(msg.mType == MessageType.FILE)
            logText.text += ",path:"+msg.mRemotePath;
        logText.text += "\n";
        logContent.sizeDelta = new Vector2 (0, logText.preferredHeight+5);
    }
});

上一章节:群组管理

下一页:设置管理