Exemple #1
0
        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);
                    }
                }
            }));
        }
Exemple #2
0
        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);
                        }
                    }
                });
            }));
        }
Exemple #3
0
        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);
            }));
        }