Esempio n. 1
0
 public async Task <IActionResult> AddUserToChat(string userUUID, string chatUUID, CancellationToken ct = default)
 {
     if (!AuthenticationUtilities.IsAllowedChat(User))
     {
         return(BadRequest("User has been banned from Chat"));
     }
     return(Ok(await _chatService.AddUserToChatAsync(userUUID, chatUUID, ct)));
 }
Esempio n. 2
0
 public async Task <IActionResult> GetMessagesForChat(string chatUUID, long startfrom, int limit = 20, CancellationToken ct = default)
 {
     if (!AuthenticationUtilities.IsAllowedChat(User))
     {
         return(BadRequest("User has been banned from Chat"));
     }
     return(Ok(await _chatService.GetMessagesForChatAsync(chatUUID, startfrom, limit, ct)));
 }
Esempio n. 3
0
 public async Task <IActionResult> GetMessageById(string messageUUID, CancellationToken ct = default)
 {
     if (!AuthenticationUtilities.IsAllowedChat(User))
     {
         return(BadRequest("User has been banned from Chat"));
     }
     return(Ok(await _chatService.GetMessageByIdAsync(messageUUID, ct)));
 }
Esempio n. 4
0
        public async Task <IActionResult> ReportUser([FromBody] ChatMessageReport report, CancellationToken ct = default)
        {
            if (!AuthenticationUtilities.IsAllowedChat(User))
            {
                return(BadRequest("User has been banned from Chat"));
            }
            await _chatService.ReportMessageAsync(report, ct);

            return(Ok());
        }
Esempio n. 5
0
        public async Task <IActionResult> BotMessage([FromBody] ChatBotRequest request, CancellationToken ct = default)
        {
            if (!AuthenticationUtilities.IsAllowedChat(User))
            {
                return(BadRequest("User has been banned from Chat"));
            }
            string uuid = AuthenticationUtilities.GetUUIDFromIdentity(User);

            return(Ok(await _chatBot.GetResponseForCommand(request.input, uuid, request.version)));
        }
Esempio n. 6
0
        public async Task <IActionResult> MarkChatAsRead(string chatUUID, CancellationToken ct = default)
        {
            if (!AuthenticationUtilities.IsAllowedChat(User))
            {
                return(BadRequest("User has been banned from Chat"));
            }
            await _chatService.MarkChatAsReadAsync(AuthenticationUtilities.GetUUIDFromIdentity(User), chatUUID, ct);

            return(Ok());
        }
Esempio n. 7
0
 public async Task <IActionResult> EditChat([FromBody] ChatEditDetails details, CancellationToken ct = default)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest("Invalid chat details"));
     }
     if (!AuthenticationUtilities.IsAllowedChat(User))
     {
         return(BadRequest("User has been banned from Chat"));
     }
     return(Ok(await _chatService.EditChatAsync(details, ct)));
 }
Esempio n. 8
0
 public async Task <IActionResult> CreateChat([FromBody] Chat chat, CancellationToken ct = default)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest("Invalid chat object"));
     }
     if (!AuthenticationUtilities.IsAllowedChat(User))
     {
         return(BadRequest("User has been banned from Chat"));
     }
     return(Ok(await _chatService.CreateNewChatAsync(chat, ct)));
 }
Esempio n. 9
0
 public async Task <IActionResult> UploadChatAttachment(string chatUUID, CancellationToken ct = default)
 {
     if (HttpContext.Request.Form.Files.Count > 0)
     {
         return(Ok(await _chatService.UploadChatAttachmentAsync(HttpContext.Request.Form.Files[0], chatUUID, ct)));
     }
     if (!AuthenticationUtilities.IsAllowedChat(User))
     {
         return(BadRequest("User has been banned from Chat"));
     }
     return(BadRequest("No files specified"));
 }
Esempio n. 10
0
 public async Task <IActionResult> AddMessageToChat(string chatUUID, [FromBody] ChatMessage message, CancellationToken ct = default)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest("Invalid message details"));
     }
     if (!AuthenticationUtilities.IsAllowedChat(User))
     {
         return(BadRequest("User has been banned from Chat"));
     }
     return(Ok(await _chatService.AddMessageToChatAsync(message, chatUUID, ct)));
 }
Esempio n. 11
0
        public async Task <IActionResult> AddUserToChatByUsername(string username, string chatUUID, CancellationToken ct = default)
        {
            if (!AuthenticationUtilities.IsAllowedChat(User))
            {
                return(BadRequest("User has been banned from Chat"));
            }
            Chat chat = await _chatService.GetChatByIdAsync(chatUUID, ct);

            if (chat.ChatMembers.Where(cm => cm.UserUUID == AuthenticationUtilities.GetUUIDFromIdentity(User)).Any())
            {
                string uuid = await _userService.GetUUIDFromUsername(username, ct);

                if (string.IsNullOrWhiteSpace(uuid))
                {
                    return(BadRequest("User does not exist"));
                }
                return(Ok(await _chatService.AddUserToChatAsync(uuid, chatUUID, ct)));
            }
            else
            {
                return(BadRequest("You cannot add to a chat you are not in"));
            }
        }