public void HandleReceivedMessages(ChatHelpingLibrary.Message message) { if (message is ChatMessage) { ChatMessage chatMessage = (ChatMessage)message; if (chatMessage.ReceiverId == 0) { if (selectedDialogId != 0) { Action action = delegate { NewMessagelabel.Text = "Вам пришло новое сообщение в Общий чат"; NewMessageChatId = 0; }; if (InvokeRequired) { Invoke(action); } else { action(); } } ClientInfo findClientInfoList = clientsInfoList.Find(f => f.Id == chatMessage.ReceiverId); int index = clientsInfoList.IndexOf(findClientInfoList); clientsInfoList[index].MessageHistory.Add(chatMessage); if (chatMessage.ReceiverId == selectedDialogId) { RedrawOther(chatMessage.SenderName, chatMessage.Content, chatMessage.DateTime); if (chatMessage.IsAnyFiles) { foreach (FileInMessage fileInMessage in chatMessage.FilesInMessageList) { RedrawFileInDialogPanel(chatMessage.SenderName + "отправил файл", fileInMessage.fileName, chatMessage.DateTime, fileInMessage.fileID); } } } } else { if (chatMessage.SenderId != selectedDialogId) { Action action = delegate { NewMessagelabel.Text = "Вам пришло новое сообщение от " + chatMessage.SenderName; NewMessageChatId = chatMessage.SenderId; }; if (InvokeRequired) { Invoke(action); } else { action(); } } ClientInfo findClientInfoList = clientsInfoList.Find(f => f.Id == chatMessage.SenderId); int index = clientsInfoList.IndexOf(findClientInfoList); clientsInfoList[index].MessageHistory.Add(chatMessage); if (chatMessage.SenderId == selectedDialogId) { RedrawOther(chatMessage.SenderName, chatMessage.Content, chatMessage.DateTime); if (chatMessage.IsAnyFiles) { foreach (FileInMessage fileInMessage in chatMessage.FilesInMessageList) { RedrawFileInDialogPanel(chatMessage.SenderName + "отправил файл", fileInMessage.fileName, chatMessage.DateTime, fileInMessage.fileID); } } } } } if (message is ClientsListMessage) { ClientsListMessage clientsListMessage = (ClientsListMessage)message; clientsInfoList = clientsListMessage.clientInfoList; currentClient.MyId = clientsListMessage.YourId; RefreshOnlineListBox(); } if (message is ActionWithClientMessage) { ActionWithClientMessage actionWithClientMessage = (ActionWithClientMessage)message; if (actionWithClientMessage.ActionType == 1) { ClientInfo clientInfo = new ClientInfo(); clientInfo.Id = actionWithClientMessage.ClientId; clientInfo.Name = actionWithClientMessage.ClientName; clientsInfoList.Add(clientInfo); } else if (actionWithClientMessage.ActionType == 0) { var removeValue = clientsInfoList.First(x => x.Id == actionWithClientMessage.ClientId); clientsInfoList.Remove(removeValue); } RefreshOnlineListBox(); } }
public void СlientSignInOutMessage(string ClientName, int Id, int actionId) { ActionWithClientMessage actionWithClientMessage = new ActionWithClientMessage(DateTime.Now, servIp, port, ClientName, Id, actionId); BroadcastMessage(actionWithClientMessage); }
public void HandleReceivedMessages(ChatHelpingLibrary.Message message) { if (message is ChatMessage) { ChatMessage chatMessage = (ChatMessage)message; if (chatMessage.ReceiverId == 0) { if (selectedDialogId != 0) { NewMessagelabel.Text = "Вам пришло новое сообщение в Общий чат"; NewMessageChatId = 0; } ClientInfo findClientInfoList = clientsInfoList.Find(f => f.Id == chatMessage.ReceiverId); int index = clientsInfoList.IndexOf(findClientInfoList); clientsInfoList[index].MessageHistory.Add(chatMessage); if (chatMessage.ReceiverId == selectedDialogId) { RedrawOther(chatMessage.senderName, chatMessage.Content, chatMessage.dateTime); } } else { if (chatMessage.SenderId != selectedDialogId) { NewMessagelabel.Text = "Вам пришло новое сообщение от " + chatMessage.senderName; NewMessageChatId = chatMessage.SenderId; } ClientInfo findClientInfoList = clientsInfoList.Find(f => f.Id == chatMessage.SenderId); int index = clientsInfoList.IndexOf(findClientInfoList); clientsInfoList[index].MessageHistory.Add(chatMessage); if (chatMessage.SenderId == selectedDialogId) { RedrawOther(chatMessage.senderName, chatMessage.Content, chatMessage.dateTime); } } } if (message is ClientsListMessage) { ClientsListMessage clientsListMessage = (ClientsListMessage)message; clientsInfoList = clientsListMessage.clientInfoList; currentClient.MyId = clientsListMessage.YourId; RefreshOnlineListBox(); } if (message is ActionWithClientMessage) { ActionWithClientMessage actionWithClientMessage = (ActionWithClientMessage)message; if (actionWithClientMessage.ActionType == 1) { ClientInfo clientInfo = new ClientInfo(); clientInfo.Id = actionWithClientMessage.ClientId; clientInfo.Name = actionWithClientMessage.ClientName; clientsInfoList.Add(clientInfo); } else if (actionWithClientMessage.ActionType == 0) { var removeValue = clientsInfoList.First(x => x.Id == actionWithClientMessage.ClientId); clientsInfoList.Remove(removeValue); } RefreshOnlineListBox(); } }