public Task ChatRoomSendMessage(string message, string chatRoomName) { return(Task.Run(() => { var chatRoom = chatRoomService.GetChatRoom(chatRoomName); if (chatRoom.HasParticipant(Context.User)) { ChatMessage chatMessage = new ChatMessage { User = Context.User, Message = message, WhenCreated = DateTime.UtcNow }; chatRoom.AddChatMessage(chatMessage); var apiObject = new ChatRoomSendMessage { ChatMessage = chatMessage.ApiGetChatMessage(), ChatRoomName = chatRoomName }; foreach (var participant in chatRoom.GetParticipants()) { var connection = userConnectionsService.ChatConnectionService.GetConnection(participant); Clients.Client(connection).ChatRoomSendMessage(apiObject); } } })); }
public Task GameLobbySendMessage(string message, long gameLobbyID) { return(Task.Run(() => { var gameLobby = gameLobbyService.GetGameLobby(gameLobbyID); if (gameLobby == null) { return; } gameLobby.UseLobbyLock(() => { if (gameLobby.HasUser(Context.User)) { ChatMessage chatMessage = new ChatMessage { User = Context.User, Message = message, WhenCreated = DateTime.UtcNow }; var apiObject = new GameLobbySendMessage { MessageType = GameLobbyMessageType.User, ChatMessage = chatMessage.ApiGetChatMessage() }; foreach (var participant in gameLobby.GetUsers()) { var connection = userConnectionsService.GameConnectionService.GetConnection(participant); Clients.Client(connection).GameLobbySendMessage(apiObject); } } }); })); }
public Task ChatUserSendMessage(string message, int recipientUserID) { return(Task.Run(() => { ChatMessage chatMessage = new ChatMessage { User = Context.User, Message = message, WhenCreated = DateTime.UtcNow }; var apiObject = new ChatUserSendMessage { ChatMessage = chatMessage.ApiGetChatMessage() }; var connection = userConnectionsService.ChatConnectionService.GetConnection(recipientUserID); Clients.Client(connection).ChatUserSendMessage(apiObject); connection = userConnectionsService.ChatConnectionService.GetConnection(Context.User); Clients.Client(connection).ChatUserSendMessage(apiObject); })); }