// POST api/<controller> public void PostChat(ChatItem chatItem) { chatItem.Id = Guid.NewGuid(); chatItem.DateTime = DateTime.Now; _manager.AddChat(chatItem); //broadcast the chat to all the clients _chatHub.SendMessage(chatItem); }
private bool AddChat() { AddChatViewModel acvm = new AddChatViewModel(); AddChatWindow acw = new AddChatWindow(acvm); if (acw.ShowDialog() == true) { if (chatManager.AddChat(acvm.ChatName, acvm.Password)) { ChatTab chatTab = new ChatTab(acvm.ChatName); ChatTabs.Add(chatTab); return(true); } } return(false); }
private void OnMessage(IMClientPeer peer, OperationRequest request) { const SubCode subCode = SubCode.Chat_Message; if (!TryInitResponse(subCode, peer, request, out var parameters, ParameterKeys.CHAT_MESSAGE_REQUEST, out ChatMessageRequestModel model)) { return; } Chat chat = new Chat { SendUsername = peer.LoginUser?.Username, ReceiveUsername = model.ReceiveUsername, MessageType = (int)model.MessageType, Message = model.Message, Time = TimeUtil.GetCurrentUtcTime().GetTotalMilliseconds() }; switch (model.MessageType) { case Chat.MessageCode.Word: //记录到DB中 ChatManager.AddChat(chat); OnWord(peer, parameters, chat); break; case Chat.MessageCode.Emoji: //记录到DB中 ChatManager.AddChat(chat); OnEmoji(peer, parameters, chat); break; case Chat.MessageCode.File: //记录到DB中 ChatManager.AddChat(chat); OnFile(peer, parameters, chat); break; default: mLogger.ErrorFormat("消息错误!客户端:{0},用户名:{1},mSubCode:{2},ChatMessageCode{3}", peer, peer.LoginUser, subCode, model.MessageType); peer.SendResponse(ReturnCode.ChatMessageCodeException, ESocketParameterTool.NewParameters.AddOperationCode(OperationCode)); break; } }
public void AddChat(IChat chat) { ChatManager.AddChat(chat); }