private void SendMsg(string touser, string msg) { var minfo = new MsgShowInfo { Content = msg, FromUser = CurrentUser.UserName, ToUser = touser, HeadImg = pictureBox1.Image, MsgType = 1, NickName = CurrentUser.NickName, isMe = true, }; var result = wxsdk.SendMsg(minfo.ToUser, msg); if (result.BaseResponse.Ret == 0) { var ctrls = panUserList.Controls.Find(touser, false); if (ctrls.Length > 0) { var cntItem = ctrls[0] as ContactItem; cntItem?.msgList.Add(minfo); if (touser == CurrentContact?.Name) { msgListShow1.Add(minfo); } } } }
public void Add(MsgShowInfo msgInfo) { msgList.Add(msgInfo); MsgItem item = new MsgItem(msgInfo); item.Dock = DockStyle.Top; Controls.Add(item); item.BringToFront(); item.UpdateShow(); }
//消息同步 private void WxSync(WebwxSyncInfo info) { if (info.AddMsgCount > 0) { foreach (var c in panUserList.Controls) { ContactItem citem = c as ContactItem; var msgs = info.AddMsgList.Where(x => x.FromUserName == citem.Name || x.ToUserName == citem.Name).ToList(); foreach (var msg in msgs) { MsgShowInfo msginfo = new MsgShowInfo { Content = msg.Content, FromUser = msg.FromUserName, ToUser = msg.ToUserName, isMe = msg.FromUserName == CurrentUser.UserName, MsgType = msg.MsgType, }; if (msginfo.isMe) { msginfo.HeadImg = pictureBox1.Image; } else if (msg.FromUserName == citem.Name) { msginfo.HeadImg = citem.Avatar; } citem.msgList.Add(msginfo); if (CurrentContact?.Name == citem.Name) { msgListShow1.Add(msginfo); if (autoReply.Checked) { SendMsg(citem.Name, "这是自动回复的消息:" + DateTime.Now.ToString()); } } break; } } } }
public MsgItem(MsgShowInfo minfo) { InitializeComponent(); msgInfo = minfo; }