private void clb_member_DoubleClickSubItem(object sender, ChatListEventArgs e, MouseEventArgs es) { var userId = (long)e.SelectSubItem.ID; if (userId == Class1.UserId) { return; } frm_chat frm_chat; if (Class1.formChatPool.ContainsKey(userId)) { frm_chat = Class1.formChatPool[userId]; frm_chat.Activate(); } else { frm_chat = new frm_chat(userId); Class1.formChatPool.Add(userId, frm_chat); frm_chat.Show(); } if (Class1.unReadPrivateMsgItemPool.ContainsKey(userId)) { var updateFriendLastReadMsgIdReq = new http._User_Relation.UpdateFriendLastReadMsgIdReq() { UserId = Class1.UserId, LastReadMsgId = new Dictionary <long, long>() }; var subItem = Class1.unReadPrivateMsgItemPool[userId]; var ids = ((List <long>)(((Dictionary <string, object>)subItem.Tag)["ids"])); foreach (var id in ids) { if (updateFriendLastReadMsgIdReq.LastReadMsgId.ContainsKey(userId)) { updateFriendLastReadMsgIdReq.LastReadMsgId[userId] = Math.Max(updateFriendLastReadMsgIdReq.LastReadMsgId[userId], id); } else { updateFriendLastReadMsgIdReq.LastReadMsgId.Add(userId, id); } } http._User_Relation.UpdateFriendLastReadMsgId(updateFriendLastReadMsgIdReq); Class1.frmMsgBox.clb_unread_msg.Items[0].SubItems.Remove(subItem); Class1.unReadPrivateMsgItemPool.Remove(userId); icon.ChangeIconState(); } }
private void clb_unread_msg_ClickSubItem(object sender, CCWin.SkinControl.ChatListClickEventArgs e, MouseEventArgs es) { if (es.Button != MouseButtons.Left) { return; } var dict = (Dictionary <string, object>)e.SelectSubItem.Tag; var type = (long)dict["type"]; switch (type) { case (long)Class1.UnReadMsgType.Message: { var msgType = (int)dict["msg_type"]; switch (msgType) { case (int)Class1.MsgType.PrivateChat: { var ids = (List <long>)dict["ids"]; var userIdSend = (long)dict["user_id_send"]; frm_chat frm_chat; if (Class1.formChatPool.ContainsKey(userIdSend)) { frm_chat = Class1.formChatPool[userIdSend]; frm_chat.Activate(); } else { frm_chat = new frm_chat(userIdSend); Class1.formChatPool.Add(userIdSend, frm_chat); frm_chat.Show(); } var updateFriendLastReadMsgIdReq = new http._User_Relation.UpdateFriendLastReadMsgIdReq() { UserId = Class1.UserId, LastReadMsgId = new Dictionary <long, long>() }; foreach (var id in ids) { if (updateFriendLastReadMsgIdReq.LastReadMsgId.ContainsKey(userIdSend)) { updateFriendLastReadMsgIdReq.LastReadMsgId[userIdSend] = Math.Max(updateFriendLastReadMsgIdReq.LastReadMsgId[userIdSend], id); } else { updateFriendLastReadMsgIdReq.LastReadMsgId.Add(userIdSend, id); } } http._User_Relation.UpdateFriendLastReadMsgId(updateFriendLastReadMsgIdReq); var subItem = Class1.unReadPrivateMsgItemPool[userIdSend]; clb_unread_msg.Items[0].SubItems.Remove(subItem); Class1.unReadPrivateMsgItemPool.Remove(userIdSend); break; } case (int)Class1.MsgType.GroupChat: { var maxId = (long)dict["max_id"]; var groupId = (long)dict["group_id"]; frm_group frmGroup; if (Class1.formGroupPool.ContainsKey(groupId)) { frmGroup = Class1.formGroupPool[groupId]; frmGroup.Activate(); } else { frmGroup = new frm_group(Class1.GetGroupInfo(groupId)); Class1.formGroupPool.Add(groupId, frmGroup); frmGroup.Show(); } var req = new http._Group_User.UpdateGroupLastReadMsgIdReq() { UserId = Class1.UserId, LastReadMsgId = new Dictionary <long, long>() { { groupId, maxId } } }; http._Group_User.UpdateGroupLastReadMsgId(req); var subItem = Class1.unReadGroupMsgItemPool[groupId]; clb_unread_msg.Items[2].SubItems.Remove(subItem); Class1.unReadGroupMsgItemPool.Remove(groupId); break; } default: throw new Exception("unknown msg_type"); } break; } case (long)Class1.UnReadMsgType.AddFriend: { var userIdSend = (long)dict["user_id_send"]; if (!Class1.IsOnline) { MessageBox.Show("你目前处于离线状态,暂时无法使用此功能", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } var id = (long)dict["id"]; var ret = MessageBox.Show($"{Class1.GetUserInfo(userIdSend).NickName}({userIdSend})" + "请求添加为好友,是否接受?", "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information); int status; if (ret == DialogResult.Yes) { status = (int)Class1.AddFriendStatus.Accepted; } else if (ret == DialogResult.No) { status = (int)Class1.AddFriendStatus.Rejected; } else { return; } var req = new http._User_Relation.ReplyAddFriendReq() { Id = id, Status = status }; var resp = http._User_Relation.ReplyAddFriend(req); var replyId = resp.Id; var createTime = resp.CreateTime; bool ok = Class1.sql.ExecuteNonQuery($"UPDATE `user_relation_request` SET `status` = {status} WHERE `id` = {id}"); if (!ok) { MessageBox.Show("DB错误,UPDATE user_relation_request", "信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } ok = Class1.sql.ExecuteNonQuery($"INSERT INTO `user_relation_request`(id, user_id_send, user_id_recv, create_time, status, parent_id) VALUES({replyId}, " + $"{Class1.UserId}, {userIdSend}, {createTime}, 0, {id})"); if (!ok) { MessageBox.Show("DB错误,INSERT INTO user_relation_request", "信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } clb_unread_msg.Items[1].SubItems.Remove(e.SelectSubItem); break; } case (long)Class1.UnReadMsgType.ReplyAddFriend: { var id = (long)dict["id"]; Class1.UpdateMessageStatus(new Dictionary <long, int> { { id, 1 } }, new Dictionary <long, int>()); clb_unread_msg.Items[1].SubItems.Remove(e.SelectSubItem); break; } case (long)Class1.UnReadMsgType.AddGroup: { var userIdSend = (long)dict["user_id_send"]; if (!Class1.IsOnline) { MessageBox.Show("你目前处于离线状态,暂时无法使用此功能", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } var id = (long)dict["id"]; var groupId = (long)dict["group_id"]; var ret = MessageBox.Show($"{Class1.GetUserInfo(userIdSend).NickName}({userIdSend})" + "请求加入群聊" + $"{Class1.GetGroupInfo(groupId).Name}({groupId})" + ",是否接受?", "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information); int status; if (ret == DialogResult.Yes) { status = (int)Class1.AddFriendStatus.Accepted; } else if (ret == DialogResult.No) { status = (int)Class1.AddFriendStatus.Rejected; } else { return; } var req = new http._Group_User.ReplyAddGroupReq() { Id = id, Status = status }; var resp = http._Group_User.ReplyAddGroup(req); var replyId = resp.Id; var createTime = resp.CreateTime; bool ok = Class1.sql.ExecuteNonQuery($"UPDATE `group_user_request` SET `status` = {status} WHERE `id` = {id}"); if (!ok) { MessageBox.Show("DB错误,UPDATE group_user_request", "信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } ok = Class1.sql.ExecuteNonQuery($"INSERT INTO `group_user_request`(id, user_id_send, user_id_recv, group_id, create_time, status, parent_id, type) VALUES({replyId}, " + $"{Class1.UserId}, {userIdSend}, {groupId}, {createTime}, 0, {id}, {(int)Class1.GroupUserRequestType.AddGroup})"); if (!ok) { MessageBox.Show("DB错误,INSERT INTO group_user_request", "信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } clb_unread_msg.Items[1].SubItems.Remove(e.SelectSubItem); break; } case (long)Class1.UnReadMsgType.ReplyAddGroup: { var id = (long)dict["id"]; Class1.UpdateMessageStatus(new Dictionary <long, int>(), new Dictionary <long, int> { { id, 1 } }); clb_unread_msg.Items[1].SubItems.Remove(e.SelectSubItem); break; } case (long)Class1.UnReadMsgType.InviteAddGroup: { break; } case (long)Class1.UnReadMsgType.ReplyInviteAddGroup: { break; } default: throw new Exception("unknown UnReadMsgType"); } icon.ChangeIconState(); }
private void ChatListBox_DoubleClickSubItem(object sender, ChatListEventArgs e, MouseEventArgs es) { if (es.Button != MouseButtons.Left) { return; } var itemId = (long)e.SelectSubItem.ID; if (Class1.chatListSubItemPool.ContainsKey(itemId) && Class1.chatListSubItemPool[itemId] == e.SelectSubItem) { var userId = itemId; frm_chat frm_chat; if (Class1.formChatPool.ContainsKey(userId)) { frm_chat = Class1.formChatPool[userId]; frm_chat.Activate(); } else { frm_chat = new frm_chat(userId); Class1.formChatPool.Add(userId, frm_chat); frm_chat.Show(); } if (Class1.unReadPrivateMsgItemPool.ContainsKey(userId)) { var updateFriendLastReadMsgIdReq = new http._User_Relation.UpdateFriendLastReadMsgIdReq() { UserId = Class1.UserId, LastReadMsgId = new Dictionary <long, long>() }; var subItem = Class1.unReadPrivateMsgItemPool[userId]; var ids = ((List <long>)(((Dictionary <string, object>)subItem.Tag)["ids"])); foreach (var id in ids) { if (updateFriendLastReadMsgIdReq.LastReadMsgId.ContainsKey(userId)) { updateFriendLastReadMsgIdReq.LastReadMsgId[userId] = Math.Max(updateFriendLastReadMsgIdReq.LastReadMsgId[userId], id); } else { updateFriendLastReadMsgIdReq.LastReadMsgId.Add(userId, id); } } http._User_Relation.UpdateFriendLastReadMsgId(updateFriendLastReadMsgIdReq); Class1.frmMsgBox.clb_unread_msg.Items[0].SubItems.Remove(subItem); Class1.unReadPrivateMsgItemPool.Remove(userId); icon.ChangeIconState(); } } else if (Class1.groupItemPool.ContainsKey(itemId) && Class1.groupItemPool[itemId] == e.SelectSubItem) { var groupId = itemId; frm_group frmGroup; if (Class1.formGroupPool.ContainsKey(groupId)) { frmGroup = Class1.formGroupPool[groupId]; frmGroup.Activate(); } else { frmGroup = new frm_group(Class1.GetGroupInfo(groupId)); Class1.formGroupPool.Add(groupId, frmGroup); frmGroup.Show(); } if (Class1.unReadGroupMsgItemPool.ContainsKey(groupId)) { var subItem = Class1.unReadGroupMsgItemPool[groupId]; var maxId = (long)((Dictionary <string, object>)subItem.Tag)["max_id"]; var req = new http._Group_User.UpdateGroupLastReadMsgIdReq() { UserId = Class1.UserId, LastReadMsgId = new Dictionary <long, long>() { { groupId, maxId } } }; http._Group_User.UpdateGroupLastReadMsgId(req); Class1.frmMsgBox.clb_unread_msg.Items[2].SubItems.Remove(subItem); Class1.unReadGroupMsgItemPool.Remove(groupId); icon.ChangeIconState(); } } }