public void sendMsg() { if (inputBox.ForeColor != Color.Gray || inputBox.Text != "") { textMessage message = new textMessage(); message.content = inputBox.Text; message.target = (int)targetUserID; message.sendUser = publicClass.mainUser.id; message.sendTime = DateTime.Now; AddMessage(message); if (publicClass.myChat.ContainsKey(message.target)) { publicClass.myChat[message.target].addMessage(message); } else { singleChatSession chatSession = new singleChatSession(message.target); chatSession.addMessage(message); publicClass.myChat.Add(message.target, chatSession); } string sendMessage = JsonConvert.SerializeObject(new command() { data = message, type = 1, subType = "singleChatTextMessage", res = "" }); //序列化 publicClass.cSocket.sendSysMsg(sendMessage, 0); } }
//单聊图片文件信息解析 public static void decodeSingleIFMessageDraw(command cComand) { JArray data = (JArray)cComand.data;//转化为Jobject int uID = data[1].ToObject <int>(); int targetID = data[2].ToObject <int>(); string fileName = data[3].ToString(); imageFileMessage message = new imageFileMessage(); message.fileName = fileName; try { string endfix = fileName.Substring(fileName.IndexOf('.') + 1); if (endfix == "jpg" | endfix == "jpeg" | endfix == "png" | endfix == "gif") { message.fileType = "img";//图片类型 } } catch { message.fileType = "file";//文件类型 } message.sendUser = uID; message.sendTime = DateTime.Now; if (!myChat.ContainsKey(message.sendUser)) { singleChatSession chatSession = new singleChatSession(message.sendUser); chatSession.addMessage(message); myChat.Add(message.sendUser, chatSession); if (s1 == null) { m1.Invoke(new Action(() => { m1.userHeadTwinkle((uint)message.sendUser, 0); })); } else if (s1.targetUserID != (uint)message.sendUser) { m1.Invoke(new Action(() => { m1.userHeadTwinkle((uint)message.sendUser, 0); })); } else if (s1.targetUserID == (uint)message.sendUser) { if (s1.IsDisposed) { m1.Invoke(new Action(() => { m1.userHeadTwinkle((uint)message.sendUser, 0); })); } else { s1.Invoke(new Action(() => { s1.AddMessage(message); })); } } } else { myChat[message.sendUser].addMessage(message); if (s1 == null) { m1.Invoke(new Action(() => { m1.userHeadTwinkle((uint)message.sendUser, 0); })); } else if (s1.targetUserID != (uint)message.sendUser) { m1.Invoke(new Action(() => { m1.userHeadTwinkle((uint)message.sendUser, 0); })); } else if (s1.targetUserID == (uint)message.sendUser) { if (s1.IsDisposed) { m1.Invoke(new Action(() => { m1.userHeadTwinkle((uint)message.sendUser, 0); })); } else { s1.Invoke(new Action(() => { s1.AddMessage(message); })); } } } }
//单聊文本信息解析 public static void decodeSingleTextMessageDraw(command cComand) { JObject data = (JObject)cComand.data; //转化为Jobject textMessage message = data.ToObject <textMessage>(); //获取消息类 if (!myChat.ContainsKey(message.sendUser)) { singleChatSession chatSession = new singleChatSession(message.sendUser); chatSession.addMessage(message); myChat.Add(message.sendUser, chatSession); if (s1 == null) { m1.Invoke(new Action(() => { m1.userHeadTwinkle((uint)message.sendUser, 0); })); } else if (s1.targetUserID != (uint)message.sendUser) { m1.Invoke(new Action(() => { m1.userHeadTwinkle((uint)message.sendUser, 0); })); } else if (s1.targetUserID == (uint)message.sendUser) { if (s1.IsDisposed) { m1.Invoke(new Action(() => { m1.userHeadTwinkle((uint)message.sendUser, 0); })); } else { s1.Invoke(new Action(() => { s1.AddMessage(message); })); } } } else { myChat[message.sendUser].addMessage(message); if (s1 == null) { m1.Invoke(new Action(() => { m1.userHeadTwinkle((uint)message.sendUser, 0); })); } else if (s1.targetUserID != (uint)message.sendUser) { m1.Invoke(new Action(() => { m1.userHeadTwinkle((uint)message.sendUser, 0); })); } else if (s1.targetUserID == (uint)message.sendUser) { if (s1.IsDisposed) { m1.Invoke(new Action(() => { m1.userHeadTwinkle((uint)message.sendUser, 0); })); } else { s1.Invoke(new Action(() => { s1.AddMessage(message); })); } } } }