예제 #1
0
        public async Task <ChatRoomDto> GetOrCreatePrivateRoomWith(string userId)
        {
            string currentUserId = identityService.CurrentUserId;

            if (currentUserId == userId)
            {
                throw new ArgumentException("Same user error");
            }

            if (!(await this.userRepo.FindByIdAsync(userId) is UserEntity user))
            {
                throw new ArgumentException("User does not exists");
            }

            var privateRoom = await roomRepo.GetPrivateRoomAsync(currentUserId, userId);

            if (privateRoom == null)
            {
                ChatRoomEntity newChatRoom = new ChatRoomEntity
                {
                    IsPrivate   = true,
                    OwnerUserId = currentUserId.ToLower(),
                    UserRooms   = new List <UsersChatRoomsEntity> {
                        new UsersChatRoomsEntity {
                            UserId = currentUserId
                        }, new UsersChatRoomsEntity {
                            UserId = userId
                        }
                    }
                };
                string id = await roomRepo.CreateAsync(newChatRoom);

                privateRoom = await roomRepo.FindByIdAsync(id);
            }

            ChatRoomDto model = mapper.Map <ChatRoomEntity, ChatRoomDto>(privateRoom);

            await notificator.Notificate(new NewChatNotification(model, model.Participants.Select(x => x.Id)));

            return(model);
        }
예제 #2
0
        public async Task <IActionResult> Invite(string chatRoomId)
        {
            string currentUserId = identity.CurrentUserId;
            var    users         = await this.userRepo.GetNonParticipantsForRoomAsync(chatRoomId, currentUserId, null, 10);

            ChatRoomEntity chatRoom = await this.roomRepo.FindByIdAsync(chatRoomId);

            if (users != null && chatRoom != null)
            {
                var roomVm = mapper.Map <ChatRoomEntity, ChatRoomViewModel>(chatRoom);
                var model  = new InviteUsersViewModel
                {
                    RoomName = roomVm.GetRoomName(identity.CurrentUserId),
                    RoomId   = chatRoomId,
                    Users    = users.Select(x => mapper.Map <UserEntity, UserViewModel>(x)).ToList()
                };

                return(PartialView("_inviteUsers", model));
            }

            return(StatusCode(404));
        }
예제 #3
0
 /**
  * Update chat room.
  */
 public bool updateChatRoom(ChatRoomEntity chatRoom)
 {
     return(Client.isStatusCodeOK(Client.put("chatrooms/" + chatRoom.roomName, chatRoom,
                                             new Dictionary <string, string>())));
 }
예제 #4
0
 /**
  * Creates the chat room.
  */
 public bool createChatRoom(ChatRoomEntity chatRoom)
 {
     return(Client.isStatusCodeOK(Client.post("chatrooms", chatRoom, new Dictionary <string, string>())));
 }