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 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(); } } }
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(); }
public void MessageChannel(RedisChannel cnl, RedisValue val) { ConnectionMultiplexer redisCli = redis.GetRedisConn(); var broadcastMsgType = GetBroadcastMsgType(val.ToString()); switch (broadcastMsgType) { case BroadcastMsgType.Chat: { var msg = JsonConvert.DeserializeObject <RedisMessage>(val.ToString()); var param = Class1.Gzip(System.Text.Encoding.Default.GetBytes(msg.Content)); bool ret = Class1.sql.ExecuteNonQueryWithBinary($"INSERT INTO `message`(id, user_id_send, user_id_recv, group_id, content, create_time, content_type, msg_type) VALUES({msg.Id}, " + $"{msg.UserIdSend}, {msg.UserIdRecv}, {msg.GroupId}, @param, {msg.CreateTime}, {msg.ContentType}, {msg.MsgType})", param); if (!ret) { MessageBox.Show("DB错误,INSERT INTO message失败", "信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } byte[] imageData = null; if (msg.ContentType == (int)Class1.ContentType.Image) { imageData = Class1.FetchImage(msg.Content); } switch (msg.MsgType) { case (int)Class1.MsgType.PrivateChat: { if (Class1.formChatPool.ContainsKey(msg.UserIdSend)) { var frm_chat = Class1.formChatPool[msg.UserIdSend]; switch (msg.ContentType) { case (int)Class1.ContentType.Text: { Class1.appendRtfToMsgBox(frm_chat, $"{Class1.UserId2User[msg.UserIdSend].NickName}({msg.UserIdSend})", Class1.StampToDateTime(msg.CreateTime), msg.Content); break; } case (int)Class1.ContentType.Object: { var objId = long.Parse(msg.Content); Class1.InsertObjectIfNotExists(objId, msg.ObjectETag, msg.ObjectName); Class1.appendFileToMsgBox(frm_chat, $"{Class1.UserId2User[msg.UserIdSend].NickName}({msg.UserIdSend})", Class1.StampToDateTime(msg.CreateTime), "[文件]" + msg.ObjectName, long.Parse(msg.Content)); break; } case (int)Class1.ContentType.Vibration: { Class1.appendSysMsgToMsgBox(frm_chat, "你" + (msg.UserIdSend == Class1.UserId ? "发送" : "收到") + "了一个窗口抖动。\r\n", Class1.StampToDateTime(msg.CreateTime)); Class1.Vibration(frm_chat); break; } case (int)Class1.ContentType.Image: { Class1.appendImageToMsgBox(frm_chat, $"{Class1.UserId2User[msg.UserIdSend].NickName}({msg.UserIdSend})", Class1.StampToDateTime(msg.CreateTime), imageData); break; } default: throw new Exception("unknown content_type " + msg.ContentType); } //消息已读 var updateFriendLastReadMsgIdReq = new http._User_Relation.UpdateFriendLastReadMsgIdReq() { UserId = Class1.UserId, LastReadMsgId = new Dictionary <long, long>() }; updateFriendLastReadMsgIdReq.LastReadMsgId.Add(msg.UserIdSend, msg.Id); http._User_Relation.UpdateFriendLastReadMsgId(updateFriendLastReadMsgIdReq); } else { switch (msg.ContentType) { case (int)Class1.ContentType.Text: { Class1.appendPersonalMsgToUnReadBox(msg.Id, msg.UserIdSend, Class1.rtfToText(msg.Content)); break; } case (int)Class1.ContentType.Object: { var objId = long.Parse(msg.Content); Class1.InsertObjectIfNotExists(objId, msg.ObjectETag, msg.ObjectName); Class1.appendPersonalMsgToUnReadBox(msg.Id, msg.UserIdSend, "[文件]" + msg.ObjectName); break; } case (int)Class1.ContentType.Vibration: { Class1.appendPersonalMsgToUnReadBox(msg.Id, msg.UserIdSend, "你收到了一个窗口抖动"); break; } case (int)Class1.ContentType.Image: { Class1.appendPersonalMsgToUnReadBox(msg.Id, msg.UserIdSend, "[图片]"); break; } default: throw new Exception("unknown content_type " + msg.ContentType); } } break; } case (int)Class1.MsgType.GroupChat: { if (Class1.formGroupPool.ContainsKey(msg.GroupId)) { var frmGroup = Class1.formGroupPool[msg.GroupId]; switch (msg.ContentType) { case (int)Class1.ContentType.Text: { cls_group.appendRtfToMsgBox(frmGroup, msg.UserIdSend.ToString(), Class1.StampToDateTime(msg.CreateTime), msg.Content); break; } case (int)Class1.ContentType.Object: { cls_group.appendFileToMsgBox(frmGroup, msg.UserIdSend.ToString(), Class1.StampToDateTime(msg.CreateTime), "[文件]" + msg.ObjectName, long.Parse(msg.Content)); break; } case (int)Class1.ContentType.Image: { cls_group.appendImageToMsgBox(frmGroup, msg.UserIdSend.ToString(), Class1.StampToDateTime(msg.CreateTime), imageData); break; } default: throw new Exception("unknown content_type content_type = " + msg.ContentType); } //消息已读 var req = new http._Group_User.UpdateGroupLastReadMsgIdReq() { UserId = Class1.UserId, LastReadMsgId = new Dictionary <long, long>() { { msg.GroupId, msg.Id } } }; http._Group_User.UpdateGroupLastReadMsgId(req); } else { switch (msg.ContentType) { case (int)Class1.ContentType.Text: { Class1.appendGroupMsgToUnReadBox(msg.Id, msg.UserIdSend, msg.GroupId, Class1.rtfToText(msg.Content)); break; } case (int)Class1.ContentType.Object: { var objId = long.Parse(msg.Content); Class1.InsertObjectIfNotExists(objId, msg.ObjectETag, msg.ObjectName); Class1.appendGroupMsgToUnReadBox(msg.Id, msg.UserIdSend, msg.GroupId, "[文件]" + msg.ObjectName); break; } case (int)Class1.ContentType.Image: { Class1.appendGroupMsgToUnReadBox(msg.Id, msg.UserIdSend, msg.GroupId, "[图片]"); break; } default: throw new Exception("unknown content_type content_type = " + msg.ContentType); } } break; } default: throw new Exception("unknown msg_type"); } break; } case BroadcastMsgType.AddFriend: { var msg = JsonConvert.DeserializeObject <RedisAddFriend>(val.ToString()); bool ret = Class1.sql.ExecuteNonQuery($"INSERT INTO `user_relation_request`(id, user_id_send, user_id_recv, create_time, status, parent_id) VALUES({msg.Id}, " + $"{msg.UserIdSend}, {msg.UserIdRecv}, {msg.CreateTime}, 0, -1)"); if (!ret) { MessageBox.Show("DB错误,INSERT INTO user_relation_request失败888", "信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Class1.appendSystemMsgToUnReadBox(msg.Id, msg.UserIdSend, "来自" + $"{Class1.GetUserInfo(msg.UserIdSend).NickName}({msg.UserIdSend})" + "的好友请求", Class1.UnReadMsgType.AddFriend, new Dictionary <string, object>()); break; } case BroadcastMsgType.ReplyAddFriend: { var msg = JsonConvert.DeserializeObject <RedisReplyAddFriend>(val.ToString()); bool ret = Class1.sql.ExecuteNonQuery($"INSERT INTO `user_relation_request`(id, user_id_send, user_id_recv, create_time, status, parent_id) VALUES({msg.Id}, " + $"{msg.UserIdSend}, {msg.UserIdRecv}, {msg.CreateTime}, 0, {msg.ParentId})"); if (!ret) { MessageBox.Show("DB错误,INSERT INTO user_relation_request失败", "信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } ret = Class1.sql.ExecuteNonQuery($"UPDATE `user_relation_request` SET status = {msg.Status} WHERE id = {msg.ParentId}"); if (!ret) { MessageBox.Show("DB错误,UPDATE user_relation_request失败", "信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Class1.appendSystemMsgToUnReadBox(msg.Id, msg.UserIdSend, $"{Class1.GetUserInfo(msg.UserIdSend).NickName}({msg.UserIdSend})" + (msg.Status == (long)Class1.AddFriendStatus.Accepted ? "通过" : "拒绝") + "了好友请求", Class1.UnReadMsgType.ReplyAddFriend, new Dictionary <string, object>()); break; } case BroadcastMsgType.AddGroup: { var msg = JsonConvert.DeserializeObject <RedisAddGroup>(val.ToString()); bool ret = Class1.sql.ExecuteNonQuery($"INSERT INTO `group_user_request`(id, user_id_send, user_id_recv, group_id, create_time, status, parent_id, type) VALUES({msg.Id}, " + $"{msg.UserIdSend}, {0}, {msg.GroupId}, {msg.CreateTime}, 0, -1, {(int)Class1.GroupUserRequestType.AddGroup})"); if (!ret) { MessageBox.Show("DB错误,INSERT INTO group_user_request失败", "信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Class1.appendSystemMsgToUnReadBox(msg.Id, msg.UserIdSend, $"{Class1.GetUserInfo(msg.UserIdSend).NickName}({msg.UserIdSend})" + "请求加入群聊" + $"{Class1.GetGroupInfo(msg.GroupId).Name}({msg.GroupId})", Class1.UnReadMsgType.AddGroup, new Dictionary <string, object>() { { "group_id", msg.GroupId } }); break; } case BroadcastMsgType.ReplyAddGroup: { var msg = JsonConvert.DeserializeObject <RedisReplyAddGroup>(val.ToString()); bool ret = Class1.sql.ExecuteNonQuery($"INSERT INTO `group_user_request`(id, user_id_send, user_id_recv, group_id, create_time, status, parent_id, type) VALUES({msg.Id}, " + $"{msg.UserIdSend}, {msg.UserIdRecv}, {msg.GroupId}, {msg.CreateTime}, 0, {msg.ParentId}, {(int)Class1.GroupUserRequestType.AddGroup})"); if (!ret) { MessageBox.Show("DB错误,INSERT INTO group_user_request失败", "信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } ret = Class1.sql.ExecuteNonQuery($"UPDATE `group_user_request` SET status = {msg.Status} WHERE id = {msg.ParentId}"); if (!ret) { MessageBox.Show("DB错误,UPDATE group_user_request失败", "信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Class1.appendSystemMsgToUnReadBox(msg.Id, msg.UserIdSend, $"{Class1.GetUserInfo(msg.UserIdSend).NickName}({msg.UserIdSend})" + (msg.Status == (long)Class1.AddFriendStatus.Accepted ? "通过" : "拒绝") + "了加群请求", Class1.UnReadMsgType.ReplyAddGroup, new Dictionary <string, object>()); break; } case BroadcastMsgType.InviteAddGroup: { break; } case BroadcastMsgType.ReplyInviteAddGroup: { break; } default: throw new Exception("unknown BroadcastMsgType " + broadcastMsgType); } icon.ChangeIconState(); }