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); }
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)); }
/** * Update chat room. */ public bool updateChatRoom(ChatRoomEntity chatRoom) { return(Client.isStatusCodeOK(Client.put("chatrooms/" + chatRoom.roomName, chatRoom, new Dictionary <string, string>()))); }
/** * Creates the chat room. */ public bool createChatRoom(ChatRoomEntity chatRoom) { return(Client.isStatusCodeOK(Client.post("chatrooms", chatRoom, new Dictionary <string, string>()))); }