public bool LOBBY2CLIEN_Chat_RESP_handler(Observers.Interfaces.INotification note) { ChatResp resp = note.Body as ChatResp; if (resp.chatType == (int)ChatType.World) { ChatInfo info = new ChatInfo(); info.chatType = ChatType.World; info.content = resp.content; info.talkerName = resp.sendRoleName; // info.isMe = GameProxy.instance.PlayerInfo.name.Equals(resp.sendRoleName); info.isMe = GameProxy.instance.AccountName.Equals(resp.sendRoleName); ChatProxy.instance.AddChatInfo(info); ChatProxy.instance.UpdateChatByProtocol(info.isMe); } else if (resp.chatType == (int)ChatType.System) { string s = resp.content; if (resp.noticeNo != 0) { SystemNoticeProxy.instance.AddSystemNotice(resp.noticeNo, resp.noticParams); } else { SystemNoticeProxy.instance.AddSystemNotice(s); } } return(true); }
//主要是這個方法 public async Task SendBothMsg(string userid, string recieveid, string input) { //獲取用戶資料 var userdata = new MemberData(); userdata = MemberList.Memlist.Where(i => i.memberid == Convert.ToInt32(userid)).FirstOrDefault(); var recieverdata = new MemberData(); recieverdata = MemberList.Memlist.Where(i => i.memberid == Convert.ToInt32(recieveid)).FirstOrDefault(); var sendToChatData = new ChatResp { memberid = userdata.memberid, username = userdata.nickname, gender = userdata.gender }; //要傳到message組件的訊息 //也要分傳給接收者還是自己的 //自己接收的性別 要是接收 者的 不然大頭貼會嘿嘿嘿 var LastMsgSpeaker = new ChatMsgLastData { memberid = userdata.memberid, gender = recieverdata.gender, username = userdata.nickname, text = input, //是對哪個用戶的msg chatname = recieverdata.nickname, //傳這個是要讓點訊息時可以到該聊天室 chatid = recieverdata.memberid.ToString(), }; var LastMsgReciever = new ChatMsgLastData { memberid = userdata.memberid, gender = userdata.gender, username = userdata.nickname, text = input, //是對哪個用戶的msg chatname = userdata.nickname, //傳這個是要讓點訊息時可以到該聊天室 chatid = userdata.memberid.ToString(), unreadcount = 1 }; //取得要傳送的id 列表 //member 的 connectionid list var useridList = ConnectList[userid]; //reciever 的 connectionid list var recieveidList = new List <string>(); if (ConnectList.ContainsKey(recieveid)) { //reciever 的 connectionid list recieveidList = ConnectList[recieveid]; } var resultList = useridList.Concat(recieveidList).ToList(); //傳到聊天室的訊息 await Clients.Clients(resultList).SendAsync("RecieveBothMsg", sendToChatData, input); //傳訊息到message 組件 (最後訊息) await Clients.Clients(useridList).SendAsync("SendLastMsg", LastMsgSpeaker); await Clients.Clients(recieveidList).SendAsync("SendLastMsg", LastMsgReciever);//result.forReciever //修改未讀總數 //改變footer 未讀總數 //讓接收者知道是誰傳的 await Clients.Clients(recieveidList).SendAsync("ChangeTotal", userid, 1); }