Exemple #1
0
        /// <summary>
        /// 获取消息时间字符串
        /// </summary>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static string GetMessageTime(EMMessage message)
        {
            if (message == null)
            {
                return(string.Empty);
            }
            DateTime now     = DateTime.Now;
            DateTime msgTime = DCUtilTool.NewDate(message.timestamp());

            if (msgTime.Year == now.Year && msgTime.Month == now.Month && msgTime.Day == now.Day)
            {
                return(msgTime.ToString("HH:mm"));
            }
            if (msgTime.Year == now.Year && msgTime.Month == now.Month && msgTime.Day + 1 == now.Day)
            {
                return("昨天 " + msgTime.ToString("HH:mm"));
            }
            if (msgTime.Year == now.Year && msgTime.Month == now.Month && msgTime.Day + 2 == now.Day)
            {
                return("前天 " + msgTime.ToString("HH:mm"));
            }
            if (msgTime.Year == now.Year)
            {
                return(msgTime.ToString("MM-dd HH:mm"));
            }
            return(msgTime.ToString("yyyy-MM-dd"));
        }
Exemple #2
0
 public void Dispose()
 {
     message   = null;
     firstbody = null;
     failImage.Dispose();
     avatarImage.Dispose();
     image.Dispose();
     thumbnailImage.Dispose();
 }
Exemple #3
0
        /// <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());
        }
Exemple #4
0
        /// <summary>
        /// 好友添加成功
        /// </summary>
        /// <param name="user"></param>
        private void onContactAdded(string user)
        {
            AudioPlayer.shard.playTips();
            EMConversation    conversation = EaseHelper.shard.client.getChatManager().conversationWithType(user, EMConversationType.CHAT, true);
            EMTextMessageBody body         = new EMTextMessageBody("我们成为了好友");
            EMMessage         message      = EMMessage.createSendMessage(SettingMenager.shard.userID, user, body, EMChatType.GROUP);

            conversation.insertMessage(message);
            MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];

            if (main == null)
            {
                return;
            }
            main.refreshFriendFromServer();
        }
        private void downloadImageMainAttchment(EMMessage mMessage, DownloadMessageAttchmentProgress progress, DownloadMessageAttchmentComplite complite)
        {
            EMImageMessageBody body = mMessage.bodies()[0] as EMImageMessageBody;

            body.setDownloadStatus(EMDownloadStatus.DOWNLOADING);
            mMessage.clearBodies();
            mMessage.addBody(body);
            var conversation = EaseHelper.shard.client.getChatManager().conversationWithType(mMessage.conversationId(), DCUtilTool.GetMConversationType(mMessage.chatType()), true);

            conversation.updateMessage(mMessage);
            string dir = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\Changliao" + "\\ChangLiao\\" + SettingMenager.shard.idCard;

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            string path = dir + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".jpg";

            HttpUitls.Instance.DownloadFile(body.remotePath(), path, (p) =>
            {
                if (progress != null)
                {
                    progress(p);
                }
            }, (b) =>
            {
                if (b)
                {
                    var fi = new FileInfo(path);
                    body.setFileLength(fi.Length);
                    body.setLocalPath(path);
                    Image image = Image.FromFile(path);
                    body.setSize(new EMImageMessageBody.Size((double)image.Width, (double)image.Height));
                    body.setDownloadStatus(EMDownloadStatus.SUCCESSED);
                    conversation.updateMessage(mMessage);
                    complite(mMessage);
                }
                else
                {
                    body.setDownloadStatus(EMDownloadStatus.FAILED);
                    conversation.updateMessage(mMessage);
                    complite(mMessage);
                }
            });
        }
        void HandleSendMessageEventHandler(object sender, EventArgs e)
        {
            var contact = ContactTextField.Text?.Trim();
            var msg     = SendMessageTextField.Text?.Trim();

            if (string.IsNullOrEmpty(contact))
            {
                AlertText("Prompt", "Please input a contact");
                return;
            }
            if (string.IsNullOrEmpty(msg))
            {
                AlertText("Prompt", "Please input a message");
                return;
            }

            var chatManager = EMClient.SharedClient().ChatManager;

            var message = new EMMessage(
                contact,
                EMClient.SharedClient().CurrentUsername,
                contact,
                new EMTextMessageBody(msg),
                new NSDictionary())
            {
                ChatType = EMChatType.Chat
            };

            chatManager.SendMessage(message, (progress) => {
                System.Console.WriteLine($"Send message with progress {progress}");
            }, (EMMessage aMessage, EMError error) =>
            {
                if (error != null)
                {
                    AlertText("Prompt", $"Send message failed: {error.ErrorDescription}!");
                }
                else
                {
                    var text      = TextView.Text;
                    TextView.Text = $"{text}\n>>>>>>>>>Send message:{msg}";
                }
            });
        }
 /// <summary>
 /// 下载消息文件
 /// </summary>
 /// <param name="mMessage">消息</param>
 /// <param name="progress">进度回调</param>
 /// <param name="complite">完成回调</param>
 public void downloadFileAttchment(EMMessage mMessage, DownloadMessageAttchmentProgress progress, DownloadMessageAttchmentComplite complite)
 {
     new Thread(new ThreadStart(() =>
     {
         if (mMessage.bodies().Length < 1)
         {
             return;
         }
         if (mMessage.bodies()[0].type == EMMessageBodyType.IMAGE)
         {
             downloadImageMainAttchment(mMessage, progress, complite);
         }
         else if (mMessage.bodies()[0].type == EMMessageBodyType.VIDEO)
         {
             downloadVideoMainAttchment(mMessage, progress, complite);
         }
         else if (mMessage.bodies()[0].type == EMMessageBodyType.FILE)
         {
             downloadFileMainAttchment(mMessage, progress, complite);
         }
     })).Start();
 }
Exemple #8
0
        private void Form_oked(string obj)
        {
            int type = 0;

            if (dSkinRadioButton1.Checked)
            {
                type = 2;
            }
            else if (dSkinRadioButton2.Checked)
            {
                type = 1;
            }
            CreateGroupSendModel model = new CreateGroupSendModel();

            model.group_name     = dSkinTextBox1.Text;
            model.group_portrait = "pc_defalt_group_photo.jpg";
            model.group_type     = type;
            HttpUitls.Instance.get <CreateGroupReciveModel>("group/create", model, (json) =>
            {
                if (json.code == 200)
                {
                    EaseHelper.shard.createdGroupId = json.data;
                    AddGroupUserSendModel addGroup  = new AddGroupUserSendModel();
                    addGroup.group_id       = json.data;
                    addGroup.group_user_ids = obj;
                    HttpUitls.Instance.get <BaseReciveModel>("groupUser/addBatch", addGroup, (js) =>
                    {
                        if (js.code == 200)
                        {
                            GroupInfoSendModel m = new GroupInfoSendModel();
                            m.group_id           = json.data;
                            HttpUitls.Instance.get <GroupInfoReciveModel>("group/detail", m, (jso) =>
                            {
                                if (js.code == 200)
                                {
                                    EMConversation conversation = EaseHelper.shard.client.getChatManager().conversationWithType(json.data, EMConversationType.GROUPCHAT, true);
                                    EMTextMessageBody body      = new EMTextMessageBody("你创建了群聊");
                                    EMMessage message           = EMMessage.createSendMessage(SettingMenager.shard.userID, json.data, body, EMChatType.GROUP);
                                    conversation.insertMessage(message);
                                    DBHelper.Instance.addGroupAndFocus(jso.data);
                                    ThreadPool.QueueUserWorkItem(getGroupMembers, json.data);
                                    MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
                                    if (main != null)
                                    {
                                        main.refreshConversationList();
                                    }
                                    this.BeginInvoke(new EventHandler((s, e) =>
                                    {
                                        this.Close();
                                    }));
                                }
                                else
                                {
                                    if (js.message.Contains("重新登录"))
                                    {
                                        MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
                                        if (main != null)
                                        {
                                            main.gotoLogin();
                                        }
                                    }
                                }
                            }, (s) =>
                            {
                                if (s < 503 && s > 500)
                                {
                                    MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
                                    if (main != null)
                                    {
                                        main.gotoLogin();
                                    }
                                }
                            });
                        }
                        else
                        {
                            if (js.message.Contains("重新登录"))
                            {
                                MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
                                if (main != null)
                                {
                                    main.gotoLogin();
                                }
                            }
                        }
                    }, (code) =>
                    {
                        if (code < 503 && code > 500)
                        {
                            MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
                            if (main != null)
                            {
                                main.gotoLogin();
                            }
                        }
                    });
                }
                else
                {
                    if (json.message.Contains("重新登录"))
                    {
                        MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
                        if (main != null)
                        {
                            main.gotoLogin();
                        }
                    }
                }
            }, (code) =>
            {
                if (code < 503 && code > 500)
                {
                    MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
                    if (main != null)
                    {
                        main.gotoLogin();
                    }
                }
            });
        }
Exemple #9
0
        /// <summary>
        /// 显示消息预览文字
        /// </summary>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static string getMessageShowTest(EMMessage message)
        {
            if (message == null)
            {
                return(string.Empty);
            }
            var bodys = message.bodies();

            if (bodys.Length < 1)
            {
                return("");
            }
            EMMessageBody body = bodys[0];
            string        text = "";

            if (body.type == EMMessageBodyType.TEXT)
            {
                EMTextMessageBody textMessageBody = (EMTextMessageBody)body;
                if (textMessageBody.text().EndsWith("_encode"))
                {
                    var arr = textMessageBody.text().Split('_');
                    text += DCEncrypt.Decrypt(arr[0], DCEncrypt.key);
                }
                else
                {
                    text += textMessageBody.text();
                }
            }
            if (body.type == EMMessageBodyType.VOICE)
            {
                text += "[语音]";
            }
            if (body.type == EMMessageBodyType.VIDEO)
            {
                text += "[视频]";
            }
            if (body.type == EMMessageBodyType.IMAGE)
            {
                text += "[图片]";
            }
            if (body.type == EMMessageBodyType.LOCATION)
            {
                text += "[位置]";
            }
            if (body.type == EMMessageBodyType.FILE)
            {
                text += "[文件]";
            }
            if (message.from() == SettingMenager.shard.userID)
            {
                return(text);
            }
            if (message.chatType() == EMChatType.SINGLE)
            {
                var friend = DBHelper.Instance.getFriend(message.from());
                if (friend == null)
                {
                    var stronger = DBHelper.Instance.GetStronger(message.from());
                    if (stronger != null)
                    {
                        text = stronger.nickName + ":" + text;
                    }
                }
                else
                {
                    text = string.IsNullOrEmpty(friend.target_user_nickname) ? friend.friend_self_name : friend.target_user_nickname + ":" + text;
                }
            }
            else
            {
                var groupUser = DBHelper.Instance.GetGroupUser(message.from(), message.conversationId());
                if (groupUser == null)
                {
                    if (DBHelper.Instance.checkFriend(message.from()))
                    {
                        var friend = DBHelper.Instance.getFriend(message.from());
                        if (!string.IsNullOrEmpty(friend.target_user_nickname))
                        {
                            text = friend.target_user_nickname + ":" + text;
                        }
                        else
                        {
                            text = friend.friend_self_name + ":" + text;
                        }
                    }
                    else
                    {
                        var stronger = DBHelper.Instance.GetStronger(message.from());
                        if (stronger != null)
                        {
                            text = stronger.nickName + ":" + text;
                        }
                    }
                }
                else
                {
                    if (DBHelper.Instance.checkFriend(message.from()))
                    {
                        text = groupUser.friend_name + ":" + text;
                    }
                    else if (!string.IsNullOrEmpty(groupUser.group_user_nickname))
                    {
                        text = groupUser.group_user_nickname + ":" + text;
                    }
                    else
                    {
                        text = groupUser.user_name + ":" + text;
                    }
                }
            }
            return(text);
        }
Exemple #10
0
    // Use this for initialization
    void Start()
    {
        rawImage.gameObject.SetActive(false);

        setMessageRecvListener();

        setGroupListener();


        friendListBtn.onClick.AddListener(delegate {
            friendList.Clear();
            friendListDd.ClearOptions();
            string names           = EMClient.Instance.GetAllContactsFromServer();
            Dropdown.OptionData od = new Dropdown.OptionData();
            od.text = "choose";
            friendList.Add(od);
            if (names.Length > 0)
            {
                string[] namearr = names.Split(new char[] { ',' });
                foreach (string name in namearr)
                {
                    Dropdown.OptionData dod = new Dropdown.OptionData();
                    dod.text = name;
                    friendList.Add(dod);
                }
            }
            friendListDd.AddOptions(friendList);
        });

        sendTxtMessageBtn.onClick.AddListener(delegate() {
            if (friendListDd.value == 0)
            {
                logText.text  = "not choose";
                logText.color = new Color(255, 0, 0);
                return;
            }
            Dropdown.OptionData dod = friendList[friendListDd.value];

            EMBaseCallback cb    = new EMBaseCallback();
            cb.onSuccessCallback = () => {
                logText.text = "send message success";
            };
            cb.onProgressCallback = (progress, status) => {
            };
            cb.onErrorCallback    = (code, message) => {
            };
            EMClient.Instance.SendTextMessage(txtContent.text, dod.text, ChatType.Chat, cb);
        });

        screenShot.onClick.AddListener(delegate() {
            StartCoroutine(GenCapture());
        });

        sendFileMessageBtn.onClick.AddListener(delegate() {
            if (filePath.text.Length > 0)
            {
                Dropdown.OptionData dod = friendList[friendListDd.value];
                EMBaseCallback cb       = new EMBaseCallback();
                cb.onSuccessCallback    = () => {
                    logText.text = "send file success";
                };
                cb.onProgressCallback = (progress, status) => {
                };
                cb.onErrorCallback    = (code, msg) => {
                };
                EMClient.Instance.SendFileMessage(filePath.text, dod.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 suc. groupId=" + group.mGroupId;
                };
                cb.onErrorCallback = (code, msg) => {
                };
                EMClient.Instance.createGroup(groupName.text, "desc:" + groupName.text, new string[0], "reason", 200, GroupStyle.GroupStylePublicOpenJoin, cb);
            }
        });

        leaveGroupBtn.onClick.AddListener(delegate() {
            EMBaseCallback cb    = new EMBaseCallback();
            cb.onSuccessCallback = () => {
                logText.text = "leave group success";
            };
            cb.onProgressCallback = (progress, status) => {
            };
            cb.onErrorCallback    = (code, 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) => {
            };
            EMClient.Instance.getJoinedGroupsFromServer(cb);
        });

        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) => {
            };
            string[] users        = { groupUser.text };
            EMClient.Instance.addUsersToGroup(groupName.text, users, cb);
        });

        inviteToGroupBtn.onClick.AddListener(delegate() {
            EMBaseCallback cb    = new EMBaseCallback();
            cb.onSuccessCallback = () => {
                logText.text = "invite to group success";
            };
            cb.onProgressCallback = (progress, status) => {
            };
            cb.onErrorCallback    = (code, msg) => {
            };
            if (groupName.text.Length > 0)
            {
                string[] users = { groupUser.text };
                EMClient.Instance.inviteUser(groupName.text, users, "welconme", cb);
            }
            else
            {
                logText.text = "input group id first";
            }
        });


        RmUserFromGroupBtn.onClick.AddListener(delegate() {
            EMBaseCallback cb    = new EMBaseCallback();
            cb.onSuccessCallback = () => {
                logText.text = "removeUserFromGroup success";
            };
            cb.onProgressCallback = (progress, status) => {
            };
            cb.onErrorCallback    = (code, msg) => {
            };
            EMClient.Instance.removeUserFromGroup(groupName.text, groupUser.text, cb);
        });

        destroyGroupBtn.onClick.AddListener(delegate() {
            EMBaseCallback cb    = new EMBaseCallback();
            cb.onSuccessCallback = () => {
                logText.text = "destory group success";
            };
            cb.onProgressCallback = (progress, status) => {
            };
            cb.onErrorCallback    = (code, msg) => {
            };
            if (groupName.text.Length > 0)
            {
                EMClient.Instance.destroyGroup(groupName.text, cb);
            }
            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;
            }
            if (msgId.text.Length == 0)
            {
                msgId.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");
            };
            cb.onProgressCallback = (progress, status) => {
            };
            cb.onErrorCallback    = (code, message) => {
            };
            EMClient.Instance.Logout(true, cb);
        });
    }
Exemple #11
0
 public MessageModel(EMMessage mMessage)
 {
     this.message = mMessage;
     if (message.bodies().Length < 1)
     {
         return;
     }
     bodyType  = message.bodies()[0].type;
     chatType  = message.chatType();
     messageId = message.msgId();
     firstbody = message.bodies()[0];
     isRead    = message.isRead();
     if (message.msgDirection() == EMMessageDirection.SEND)
     {
         isSender = true;
     }
     else
     {
         isSender = false;
     }
     nickName = message.from();
     if (bodyType == EMMessageBodyType.TEXT)
     {
         if (message.getAttribute("jpzim_is_big_expression", out isGifFace))
         {
             if (isGifFace)
             {
                 message.getAttribute("jpzim_big_expression_path", out gitFaceURL);
                 message.getAttribute("faceH", out faceH);
                 message.getAttribute("faceW", out faceW);
                 if (!string.IsNullOrEmpty(gitFaceURL))
                 {
                     DCWebImageMaanager.shard.downloadImageAsync(gitFaceURL, (image, b) =>
                     {
                         this.image = image;
                         if (faceH < 1 || faceW < 1)
                         {
                             faceW = image.Width;
                             faceH = image.Height;
                         }
                     });
                 }
                 text   = "[动画表情]";
                 isRead = message.isRead();
                 setupUserInfo();
                 return;
             }
         }
         string typ;
         if (message.getAttribute("type", out typ))
         {
             if (typ.Equals("person"))
             {
                 isIDCard = true;
                 isRead   = message.isRead();
                 message.getAttribute("id", out IDCardID);
                 return;
             }
         }
         EMTextMessageBody body = (EMTextMessageBody)message.bodies()[0];
         text   = body.text();
         isRead = message.isRead();
         if (text.EndsWith("_encode"))
         {
             var arr = text.Split('_');
             text = DCEncrypt.Decrypt(arr[0], DCEncrypt.key);
             if (string.IsNullOrEmpty(text))
             {
                 text = body.text();
             }
         }
     }
     else if (bodyType == EMMessageBodyType.IMAGE)
     {
         EMImageMessageBody body = (EMImageMessageBody)message.bodies()[0];
         var file = body.localPath();
         if (!string.IsNullOrEmpty(body.localPath()) && File.Exists(body.localPath()))
         {
             image = new Bitmap(body.localPath());
         }
         fileLocalPath          = body.localPath();
         thumbnailFileLocalPath = body.thumbnailLocalPath();
         fileURLPath            = body.remotePath();
         thumbnailFileURLPath   = body.thumbnailRemotePath();
         fileSize           = body.fileLength();
         imageSize          = new Size(Convert.ToInt32(body.size().mWidth), Convert.ToInt32(body.size().mHeight));
         thumbnailImageSize = new Size(Convert.ToInt32(body.thumbnailSize().mWidth), Convert.ToInt32(body.thumbnailSize().mWidth));
     }
     else if (bodyType == EMMessageBodyType.VOICE)
     {
         EMVoiceMessageBody body = (EMVoiceMessageBody)message.bodies()[0];
         fileLocalPath = body.localPath();
         fileURLPath   = body.remotePath();
         fileSize      = body.fileLength();
         mediaDuration = body.duration();
     }
     else if (bodyType == EMMessageBodyType.VIDEO)
     {
         EMVideoMessageBody body = (EMVideoMessageBody)message.bodies()[0];
         fileLocalPath          = body.localPath();
         thumbnailFileLocalPath = body.thumbnailLocalPath();
         fileURLPath            = body.remotePath();
         thumbnailFileURLPath   = body.thumbnailRemotePath();
         fileSize = body.fileLength();
         if (string.IsNullOrEmpty(thumbnailFileLocalPath) && File.Exists(body.thumbnailLocalPath()))
         {
             thumbnailImage = Image.FromFile(thumbnailFileLocalPath);
         }
         thumbnailImageSize = new Size(Convert.ToInt32(body.size().mWidth), Convert.ToInt32(body.size().mHeight));
     }
     else
     {
         if (bodyType == EMMessageBodyType.COMMAND)
         {
             return;
         }
         if (bodyType == EMMessageBodyType.LOCATION)
         {
             EMLocationMessageBody body1 = firstbody as EMLocationMessageBody;
             latitude  = body1.latitude();
             longitude = body1.longitude();
             address   = body1.address();
             return;
         }
         EMFileMessageBody body = (EMFileMessageBody)message.bodies()[0];
         fileLocalPath = body.localPath();
         fileURLPath   = body.remotePath();
         fileSize      = body.fileLength();
         displayName   = body.displayName();
         fileSizeDes   = getFileSize();
     }
     isRead = message.isRead();
     setupUserInfo();
 }
 /// <summary>
 /// 下载消息文件
 /// </summary>
 /// <param name="mMessage">消息</param>
 /// <param name="complite">完成回调</param>
 public void downloadFileAttchment(EMMessage mMessage, DownloadMessageAttchmentComplite complite)
 {
     downloadFileAttchment(mMessage, null, complite);
 }
        private void downloadFileMainAttchment(EMMessage mMessage, DownloadMessageAttchmentProgress progress, DownloadMessageAttchmentComplite complite)
        {
            EMFileMessageBody body = mMessage.bodies()[0] as EMFileMessageBody;

            body.setDownloadStatus(EMDownloadStatus.DOWNLOADING);
            mMessage.clearBodies();
            mMessage.addBody(body);
            var conversation = EaseHelper.shard.client.getChatManager().conversationWithType(mMessage.conversationId(), DCUtilTool.GetMConversationType(mMessage.chatType()), true);

            conversation.updateMessage(mMessage);
            string dir = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\Changliao" + "\\ChangLiao\\" + SettingMenager.shard.idCard;

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            string path = dir + "\\" + body.displayName();
            var    p    = path;
            int    i    = 0;

            while (File.Exists(p))
            {
                i += 1;
                var arr = path.Split('.');
                if (arr.Length > 2)
                {
                    p = "";
                    for (int j = 0; j < arr.Length - 1; j++)
                    {
                        p += arr[j];
                    }
                    p = p + "(" + i + ")." + arr[arr.Length - 1];
                }
                else if (arr.Length == 2)
                {
                    p = arr[0] + "(" + i + ")." + arr[1];
                }
                else
                {
                    p = path + "(" + i + ")";
                }
            }
            HttpUitls.Instance.DownloadFile(body.remotePath(), p, (p1) =>
            {
                if (progress != null)
                {
                    progress(p1);
                }
            }, (b) =>
            {
                if (b)
                {
                    var fi = new FileInfo(path);
                    body.setFileLength(fi.Length);
                    body.setLocalPath(path);
                    body.setDownloadStatus(EMDownloadStatus.SUCCESSED);
                    conversation.updateMessage(mMessage);
                    complite(mMessage);
                }
                else
                {
                    body.setDownloadStatus(EMDownloadStatus.FAILED);
                    conversation.updateMessage(mMessage);
                    complite(mMessage);
                }
            });
        }
Exemple #14
0
    // 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);
        });
    }
Exemple #15
0
 private void cancelManagerToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (rightIndex == -1)
     {
         return;
     }
     if (menbers != null)
     {
         var member = menbers[rightIndex];
         DeleteManagerSendModel m = new DeleteManagerSendModel();
         m.group_id      = member.user.groupID;
         m.oldManager_id = member.user.userID;
         HttpUitls.Instance.get <BaseReciveModel>("groupUser/addManager", m, (json) =>
         {
             if (json.code == 200)
             {
                 this.menbers[rightIndex].user.is_manager = 1;
                 ThreadPool.QueueUserWorkItem((o) =>
                 {
                     refreshGroupMember();
                 });
                 loadData();
                 EMCmdMessageBody body = new EMCmdMessageBody("");
                 EMMessage message     = EMMessage.createSendMessage(SettingMenager.shard.userID, member.user.userID, body, EMChatType.SINGLE);
                 message.setAttribute("type", "qun");
                 message.setAttribute("id", member.user.groupID);
                 message.setAttribute("qun_auth", "qun_auth");
                 message.setAttribute("auth", "2");
                 EaseHelper.shard.client.getChatManager().sendMessage(message);
             }
             else
             {
                 if (json.message.Contains("重新登录"))
                 {
                     MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
                     if (main != null)
                     {
                         main.gotoLogin();
                     }
                 }
                 else
                 {
                     this.BeginInvoke(new EventHandler((ss, ee) =>
                     {
                         MessageBox.Show(json.message);
                     }));
                 }
             }
         }, (code) =>
         {
             if (code > 500 && code < 503)
             {
                 MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
                 if (main != null)
                 {
                     main.gotoLogin();
                 }
             }
         });
     }
     skinContextMenuStrip1.Items.Clear();
 }
Exemple #16
0
        private void 取消全员禁言ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GroupInfoSendModel m = new GroupInfoSendModel();

            m.group_id = model.groupId;
            HttpUitls.Instance.get <BaseReciveModel>("group/cancelAllBanned", m, (json) =>
            {
                if (json.code == 200)
                {
                    model.is_all_banned = 2;
                    loadInfo();
                    EMCmdMessageBody body = new EMCmdMessageBody("");
                    EMMessage message     = EMMessage.createSendMessage(SettingMenager.shard.userID, model.groupId, body, EMChatType.GROUP);
                    message.setAttribute("type", "qun");
                    message.setAttribute("id", model.groupId);
                    message.setAttribute("grouptype", "2");
                    EaseHelper.shard.client.getChatManager().sendMessage(message);
                    HttpUitls.Instance.get <GroupInfoReciveModel>("group/detail", m, (jso) =>
                    {
                        if (jso.code == 200)
                        {
                            DBHelper.Instance.addGroupAndFocus(jso.data);
                            model = DBHelper.Instance.GetGroup(model.groupId);
                            loadInfo();
                            ThreadPool.QueueUserWorkItem((o) =>
                            {
                                refreshGroupMember();
                            });
                            MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
                            if (main != null)
                            {
                                main.refreshConversationList();
                                main.loadGroup();
                            }
                        }
                        else
                        {
                            if (jso.message.Contains("重新登录"))
                            {
                                MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
                                if (main != null)
                                {
                                    main.gotoLogin();
                                }
                            }
                        }
                    }, (s) =>
                    {
                        if (s < 503 && s > 500)
                        {
                            MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
                            if (main != null)
                            {
                                main.gotoLogin();
                            }
                        }
                    });
                }
                else
                {
                    if (json.message.Contains("重新登录"))
                    {
                        MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
                        if (main != null)
                        {
                            main.gotoLogin();
                        }
                    }
                    else
                    {
                        this.BeginInvoke(new EventHandler((s, ee) =>
                        {
                            MessageBox.Show(json.message);
                        }));
                    }
                }
            }, (code) =>
            {
                if (code < 503 && code > 500)
                {
                    MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
                    if (main != null)
                    {
                        main.gotoLogin();
                    }
                }
            });
        }
Exemple #17
0
 /// <summary>
 /// 接收Cmd消息
 /// </summary>
 /// <param name="messages"></param>
 private void onReciveCmdMessage(EMMessage[] messages)
 {
     foreach (EMMessage message in messages)
     {
         string own = "";
         if (message.getAttribute("own", out own))
         {
             var data = JsonConvert.DeserializeObject <List <DeleteMessageDataModel> >(own);
             foreach (var item in data)
             {
                 EMConversation conversation = client.getChatManager().conversationWithType(item.userid, EMConversationType.CHAT, false);
                 if (conversation != null)
                 {
                     conversation.removeMessage(item.messageId);
                 }
                 MainFrm m = (MainFrm)Application.OpenForms["MainFrm"];
                 if (m == null)
                 {
                     continue;
                 }
                 m.deleteMesssage(item.userid, item.messageId);
             }
             MainFrm main = (MainFrm)Application.OpenForms["MainFrm"];
             if (main == null)
             {
                 return;
             }
             main.refreshConversationList();
         }
         string type;
         if (message.getAttribute("type", out type))
         {
             if (type == "personMSG")
             {
                 string userid = "";
                 string nsid   = "";
                 message.getAttribute("userid", out userid);
                 message.getAttribute("msgid", out nsid);
                 EMConversation conversation = client.getChatManager().conversationWithType(message.conversationId(), EMConversationType.CHAT, false);
                 if (conversation != null)
                 {
                     EMMessage mMessage = conversation.loadMessage(nsid);
                     if (mMessage != null)
                     {
                         conversation.removeMessage(mMessage);
                     }
                 }
                 MainFrm m = (MainFrm)Application.OpenForms["MainFrm"];
                 if (m == null)
                 {
                     continue;
                 }
                 m.deleteMesssage(userid, nsid);
                 m.refreshConversationList();
             }
             if (type == "deleteMSG")
             {
                 string userid = "";
                 string nsid   = "";
                 message.getAttribute("userid", out userid);
                 message.getAttribute("msgid", out nsid);
                 EMConversation conversation = client.getChatManager().conversationWithType(message.conversationId(), EMConversationType.GROUPCHAT, false);
                 if (conversation != null)
                 {
                     EMMessage mMessage = conversation.loadMessage(nsid);
                     if (mMessage != null)
                     {
                         conversation.removeMessage(mMessage);
                     }
                 }
                 MainFrm m = (MainFrm)Application.OpenForms["MainFrm"];
                 if (m == null)
                 {
                     continue;
                 }
                 m.deleteMesssage(userid, nsid);
                 m.refreshConversationList();
             }
             if (type == "qunAdmin" || type == "qun" || type == "qun_shield")
             {
                 MainFrm m = (MainFrm)Application.OpenForms["MainFrm"];
                 if (m == null)
                 {
                     continue;
                 }
                 string id = "";
                 message.getAttribute("id", out id);
                 m.refreshGroupInfo(id);
             }
         }
     }
 }