Beispiel #1
0
        public async Task <ApiResponse> Chat_Sent(ChatVM _vm)
        {
            ApiResponse apiResponse = new ApiResponse();
            ChatRepo    _obj        = new ChatRepo();

            try
            {
                _vm._flag = 0;
                var result = await _obj.ChatMessageSend(_vm);

                if (result > 0)
                {
                    return new ApiResponse {
                               IsValidUser = true, Message = "success", MessageType = result, DataList = result
                    }
                }
                ;
                else
                {
                    return new ApiResponse {
                               IsValidUser = true, Message = "someting went wrong..!!", MessageType = result, DataList = result
                    }
                };
            }
            catch (Exception ex)
            {
                apiResponse = TaskUTL.GenerateExceptionResponse(ex, "hub", true);
                return(apiResponse);
            }
        }
Beispiel #2
0
        public async Task <ApiResponse> ChatSignOut(ChatVM _vm)
        {
            ApiResponse apiResponse = new ApiResponse();
            ChatRepo    _obj        = new ChatRepo();

            try
            {
                _vm._flag = 0;
                var result = await _obj.ChatSignOut(_vm);

                if (result > 0)
                {
                    return new ApiResponse {
                               IsValidUser = true, Message = "success", MessageType = result, DataList = null
                    }
                }
                ;
                else
                {
                    return new ApiResponse {
                               IsValidUser = true, Message = "Already Chat Off", MessageType = result, DataList = null
                    }
                };
            }
            catch (Exception ex)
            {
                apiResponse = TaskUTL.GenerateExceptionResponse(ex, _pageName, true);
                return(apiResponse);
            }
        }
Beispiel #3
0
        public async Task <ChatReceiveResponse> ChatReceivedByTime(ChatVM _vm)
        {
            ChatReceiveResponse apiResponse = new ChatReceiveResponse();
            ChatRepo            _obj        = new ChatRepo();

            try
            {
                _vm._flag = 0;
                var result = await _obj.ChatReceivedByTime(_vm);

                if (result._flag > 0)
                {
                    return new ChatReceiveResponse {
                               ChatStatus = 1, DataList = result._dataList
                    }
                }
                ;
                else
                {
                    return new ChatReceiveResponse {
                               ChatStatus = 0, DataList = result._dataList
                    }
                };
            }
            catch (Exception ex)
            {
                apiResponse = new ChatReceiveResponse {
                    error = ex.Message.ToString()
                };                                                                        //TaskUTL.GenerateExceptionResponse(ex, _pageName, true);
                return(apiResponse);
            }
        }
Beispiel #4
0
        public void GetLastMessagesForUser_WithOffset_RetrievesExpectedUsersWithMessages_InAllCases(int userId, int offset,
                                                                                                    List <UserShortVersionWithMessage> expected)
        {
            //arrange
            using (DummyDbContext ctx = new DummyDbContext())
            {
                IChatRepoTest chatRepo = new ChatRepo();

                //act
                List <UserShortVersionWithMessage> actual = chatRepo.GetLastMessagesForUserWithDbContext(ctx, userId, offset);

                //assert
                Assert.Equal(expected.Count, actual.Count);
                for (int i = 0; i < actual.Count; i++)
                {
                    Assert.Equal(expected[i].UserId, actual[i].UserId);
                    Assert.Equal(expected[i].UserFullName, actual[i].UserFullName);
                    Assert.Equal(expected[i].Message.Id, actual[i].Message.Id);
                }
            }
        }
Beispiel #5
0
        public async Task AddFriend(string token)
        {
            RandomRoom room = RoomManager.Instance.GetRoom(Context.ConnectionId);

            if (room != null)
            {
                foreach (WaitUser usr in room.Members)
                {
                    if (usr.UserID <= 0)
                    {
                        await Clients.Group(room.ID).BroadcastMessage($"Người dùng {Context.ConnectionId} đề xuất kết bạn thất bại vì ít nhất 1 trong 2 người chưa đăng nhập!");

                        return;
                    }
                    if (usr.ConnectionID == Context.ConnectionId)
                    {
                        usr.FriendRequest = true;
                    }
                }

                await Clients.Group(room.ID).BroadcastMessage($"Người dùng {Context.ConnectionId} đã đề xuất kết bạn!");

                // Call API create chat room
                if (room.Members.Length >= 2 && room.Members[0].FriendRequest && room.Members[1].FriendRequest)
                {
                    IChatRepo chatRepo = new ChatRepo();
                    await chatRepo.CreateChatRoom(
                        room.Members[0].UserID,
                        room.Members[1].UserID,
                        room.Members[0].UserName,
                        room.Members[1].UserName,
                        token);
                }
            }

            Debug();
        }
Beispiel #6
0
 /// <summary>
 /// Controller for the Chat table
 /// </summary>
 /// <param name="chatRepo"></param>
 /// <param name="playerRepo"></param>
 public ChatController(ChatRepo chatRepo, PlayerRepo playerRepo) : base(playerRepo)
 {
     _chatRepo = chatRepo;
 }