public void ShowReceivedMessage(Messages message) { if (message is RoomParticipantsMessage) { HandleRoomParticipantsMessage((RoomParticipantsMessage)message); } if (message is CreateRoomResponseMessage) { AddRoomToRoomsListBox((CreateRoomResponseMessage)message); } if (message is ServerUdpAnswerMessages) { AddServerInfoToServersListBox((ServerUdpAnswerMessages)message); } else if (message is ParticipantsListMessages) { RefreshParticipantsListBox((ParticipantsListMessages)message); } else if (message is RoomMessage) { HandleRoomMessage((RoomMessage)message); } else if (message is CommonChatMessages) { CommonChatMessages commonChatMessage = (CommonChatMessages)message; HandleChatMessage(commonChatMessage); } }
private void HandleChatMessage(CommonChatMessages commonChatMessage) { if (commonChatMessage is IndividualChatMessages) { IndividualChatMessages individualChatMessage = (IndividualChatMessages)commonChatMessage; if (client.id == individualChatMessage.ReceiverId) { ReceiverHandleIndividualChatMessage(individualChatMessage); } else if (client.id == individualChatMessage.SenderId) { SenderHandleIndividualChatMessage(individualChatMessage); } } else if (commonChatMessage is CommonChatMessages) { AddNewCommonChatMessage(commonChatMessage); } }
private void AddNewCommonChatMessage(CommonChatMessages commonChatMessage) { Action action = delegate { if (selectedDialog == 0) { string chatContent = "[" + commonChatMessage.DateTime.ToString() + " " + commonChatMessage.SenderIp.ToString() + ":" + commonChatMessage.SenderPort + "]: \"" + client.participants[commonChatMessage.SenderId].Name + "\": " + commonChatMessage.Content + "\r\n"; ChatListBox.Items.Add(chatContent); } }; if (InvokeRequired) { Invoke(action); } else { action(); } }
public void HandleReceivedMessage(Messages message) { if (message is InviteRoomMessage) { InviteRoomMessage inviteRoomMessage = (InviteRoomMessage)message; HandleInviteRoomMessage(inviteRoomMessage); } if (message is ExitRoomMessage) { ExitRoomMessage exitRoomMessage = (ExitRoomMessage)message; HandleExitRoomMessage(exitRoomMessage); } if (message is ClientUdpRequestMessages) { ClientUdpRequestMessages clientUdpRequestMessage = (ClientUdpRequestMessages)message; HandleClientUdpRequestMessage(clientUdpRequestMessage); } if (message is CreateRoomRequestMessage) { CreateRoomRequestMessage createRoomRequestMessage = (CreateRoomRequestMessage)message; HandleCreateRommRequestMessage(createRoomRequestMessage); } if (message is RoomMessage) { RoomMessage roomMessage = (RoomMessage)message; HandleRoomMessage(roomMessage); } else if (message is IndividualChatMessages) { IndividualChatMessages individualChatMessage = (IndividualChatMessages)message; HandleIndividualChatMessage(individualChatMessage); } else if (message is CommonChatMessages) { CommonChatMessages commonChatMessage = (CommonChatMessages)message; WriteLine("\"" + GetName(commonChatMessage.SenderId) + "\": " + commonChatMessage.Content); HandleCommonChatMessage(commonChatMessage); } }
private void HandleChatMessage(CommonChatMessages commonChatMessage) { if (commonChatMessage is IndividualChatMessages) { IndividualChatMessages individualChatMessage = (IndividualChatMessages)commonChatMessage; foreach (NewChatParticipant chatParticipant in participants) { if (chatParticipant.Id == individualChatMessage.SenderId) { chatParticipant.MessageHistory.Add(individualChatMessage); chatParticipant.NotReadedMessageCountIncrement(individualChatMessage); if (individualChatMessage is FileIndividualMessage) { var fileIndividualMessage = (FileIndividualMessage)individualChatMessage; foreach (var file in fileIndividualMessage.Files) { chatParticipant.Files.Add(file.Key, file.Value); } } break; } } } else { participants[0].NotReadedMessageCountIncrement(commonChatMessage); if (commonChatMessage is FileCommonMessage) { var fileCommonMessage = (FileCommonMessage)commonChatMessage; foreach (var file in fileCommonMessage.Files) { participants[0].Files.Add(file.Key, file.Value); } } } }
private void HandleCommonChatMessage(CommonChatMessages commonChatMessage) { messageHistory.Add(commonChatMessage); SendMessageToAllClients(commonChatMessage); SendMessageToAllClients(GetMessagesHistoryMessage()); }