/// <summary> /// 废弃 /// </summary> /// <param name="group"></param> /// <param name="member"></param> private void onMemberJoinedGroup(EMGroup group, string member) { MainFrm main = (MainFrm)Application.OpenForms["MainFrm"]; if (main == null) { return; } main.refreshGroupInfo(group.groupId()); }
/// <summary> /// 废弃 /// </summary> /// <param name="group"></param> /// <param name="from"></param> /// <param name="message"></param> private void onReceiveJoinGroupApplication(EMGroup group, string from, string message) { MainFrm main = (MainFrm)Application.OpenForms["MainFrm"]; if (main == null) { return; } main.refreshGroupInfo(group.groupId()); }
/// <summary> /// 离开群组 /// </summary> /// <param name="group"></param> /// <param name="reason"></param> private void onLeaveGroup(EMGroup group, EMGroupLeaveReason reason) { DBHelper.Instance.DeleteGroup(group.groupId()); client.getChatManager().removeConversation(group.groupId(), true); MainFrm main = (MainFrm)Application.OpenForms["MainFrm"]; if (main == null) { return; } main.removeConversation(group.groupId()); }
/// <summary> /// 加入群组 /// </summary> /// <param name="group"></param> /// <param name="inviter"></param> /// <param name="inviteMessage"></param> private void onAutoAcceptInvitationFromGroup(EMGroup group, string inviter, string inviteMessage) { EMConversation conversation = EaseHelper.shard.client.getChatManager().conversationWithType(group.groupId(), EMConversationType.GROUPCHAT, true); EMTextMessageBody body = new EMTextMessageBody("你加入了群聊"); EMMessage message = EMMessage.createSendMessage(SettingMenager.shard.userID, group.groupId(), body, EMChatType.GROUP); conversation.insertMessage(message); MainFrm main = (MainFrm)Application.OpenForms["MainFrm"]; if (main == null) { return; } main.refreshGroupInfo(group.groupId()); }
// Use this for initialization void Start() { rawImage.gameObject.SetActive(false); EMClient.Instance.isAutoAcceptGroupInvitation(false); setMessageRecvListener(); sendTxtMessageBtn.onClick.AddListener(delegate() { EMBaseCallback cb = new EMBaseCallback(); cb.onSuccessCallback = () => { logText.text = "send message success"; }; cb.onProgressCallback = (progress, status) => { }; cb.onErrorCallback = (code, message) => { }; EMClient.Instance.SendTextMessage(txtContent.text, toUser.text, ChatType.Chat, cb); }); screenShot.onClick.AddListener(delegate() { StartCoroutine(GenCapture()); }); sendFileMessageBtn.onClick.AddListener(delegate() { if (filePath.text.Length > 0) { EMBaseCallback cb = new EMBaseCallback(); cb.onSuccessCallback = () => { logText.text = "send file success"; }; cb.onProgressCallback = (progress, status) => { }; cb.onErrorCallback = (code, msg) => { }; EMClient.Instance.SendFileMessage(filePath.text, toUser.text, ChatType.Chat, cb); } }); sendGroupTxtMsgBtn.onClick.AddListener(delegate() { EMBaseCallback cb = new EMBaseCallback(); cb.onSuccessCallback = () => { logText.text = "send group message success"; }; cb.onProgressCallback = (progress, status) => { }; cb.onErrorCallback = (code, message) => { }; if (txtContent.text.Length == 0) { txtContent.placeholder.GetComponent <Text>().text = "input here first"; return; } if (groupName.text.Length == 0) { groupName.placeholder.GetComponent <Text>().text = "input here first"; return; } EMClient.Instance.SendTextMessage(txtContent.text, groupName.text, ChatType.GroupChat, cb); }); sendGroupFileMsgBtn.onClick.AddListener(delegate() { EMBaseCallback cb = new EMBaseCallback(); cb.onSuccessCallback = () => { logText.text = "send group file success"; }; cb.onProgressCallback = (progress, status) => { }; cb.onErrorCallback = (code, message) => { }; if (groupName.text.Length == 0) { groupName.placeholder.GetComponent <Text>().text = "input here first"; return; } EMClient.Instance.SendFileMessage(filePath.text, groupName.text, ChatType.GroupChat, cb); }); createGroupBtn.onClick.AddListener(delegate() { if (groupName.text.Length > 0) { EMGroupCallback cb = new EMGroupCallback(); cb.onSuccessCreateGroupCallback = (group) => { logText.text = "create group success"; }; cb.onErrorCallback = (code, msg) => { logText.text = msg; }; EMClient.Instance.createGroup(groupName.text, "desc:" + groupName.text, new string[0], "reason", 200, (GroupStyle)groupStyle.value, cb); } }); joinGroupBtn.onClick.AddListener(delegate() { EMBaseCallback cb = new EMBaseCallback(); cb.onSuccessCallback = () => { logText.text = "join group success"; }; cb.onProgressCallback = (progress, status) => { }; cb.onErrorCallback = (code, msg) => { logText.text = "join group failure msg=" + msg; }; if (groupName.text.Length > 0) { EMClient.Instance.joinGroup(groupName.text, cb); } else { logText.text = "input group id first"; } }); leaveGroupBtn.onClick.AddListener(delegate() { EMBaseCallback cb = new EMBaseCallback(); cb.onSuccessCallback = () => { logText.text = "leave group success"; }; cb.onProgressCallback = (progress, status) => { }; cb.onErrorCallback = (code, msg) => { logText.text = msg; }; if (groupName.text.Length > 0) { EMClient.Instance.leaveGroup(groupName.text, cb); } else { logText.text = "input group id first"; } }); getGroupsBtn.onClick.AddListener(delegate() { logText.text = ""; groupList.Clear(); EMGroupCallback cb = new EMGroupCallback(); cb.onSuccessGetGroupListCallback = (groups) => { foreach (EMGroup group in groups) { logText.text += "ID=" + group.mGroupId + "," + group.mGroupName + "\n"; groupList.Add(group); groupName.text = group.mGroupId; } logContent.sizeDelta = new Vector2(0, logText.preferredHeight + 5); }; cb.onErrorCallback = (code, msg) => { logText.text = msg; }; EMClient.Instance.getJoinedGroupsFromServer(cb); }); 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"; } }); addToGroupBtn.onClick.AddListener(delegate() { EMBaseCallback cb = new EMBaseCallback(); cb.onSuccessCallback = () => { logText.text = "add user to group success"; }; cb.onProgressCallback = (progress, status) => { }; cb.onErrorCallback = (code, msg) => { logText.text = "failed to addUsersToGroup: " + msg; }; string[] users = { groupUser.text }; EMClient.Instance.addUsersToGroup(groupName.text, users, cb); }); GroupInfoBtn.onClick.AddListener(delegate() { if (groupName.text.Length > 0) { EMGroup group = EMClient.Instance.getGroup(groupName.text); if (group != null) { logText.text = "name=" + group.mGroupName + ",id=" + group.mGroupId; } } else { logText.text = "input group id first"; } }); 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); } }); logoutBtn.onClick.AddListener(delegate() { EMBaseCallback cb = new EMBaseCallback(); cb.onSuccessCallback = () => { SceneManager.LoadScene("LoginScene"); GlobalListener.Instance.listenerInfo = ""; }; cb.onProgressCallback = (progress, status) => { }; cb.onErrorCallback = (code, message) => { }; EMClient.Instance.Logout(true, cb); }); logText.text = GlobalListener.Instance.listenerInfo; sendExtMsgBtn.onClick.AddListener(delegate() { EMBaseCallback cb = new EMBaseCallback(); cb.onSuccessCallback = () => { logText.text = "send message success"; }; cb.onProgressCallback = (progress, status) => { }; cb.onErrorCallback = (code, message) => { }; string jsonstr = "{\"key\":\"extinfotext\"}"; EMClient.Instance.SendTextMessageExt(txtContent.text, toUser.text, ChatType.Chat, cb, jsonstr); }); }