public async Task AddUserToGroup(GroupUserRequest request) { try { var result = await _chatService.AddUserToGroup(Context.UserIdentifier, request.Group, request.User); ChatResponse response = new ChatResponse(); if (result.Success) { response.Type = ChatResponseType.UpdateGroupView; response.Data = result.Data; await SendResponseToGroup(request.Group, response); await GroupUserConnection(request.Group, request.User, true); } else { response.Type = ChatResponseType.SystemErrorMessage; response.Data = result.Message; await SendResponseToCaller(response); } } catch (Exception) { } }
public async Task <IActionResult> JoinGroup( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "group/{groupId}/join")] User user, string groupId, [SignalR(HubName = Constants.ChatHubName)] IAsyncCollector <SignalRGroupAction> groupActions) { if (!Guid.TryParse(groupId, out Guid groupIdGuid)) { _logger.LogError($"Could not parse {groupId} as a valid GUID."); return(new BadRequestResult()); } var success = await _chatService.AddUserToGroup(user, groupIdGuid); IActionResult earlyReturn = success switch { ServiceResult.Success => null, ServiceResult.InvalidArguments => new BadRequestResult(), ServiceResult.NotFound => new NotFoundResult(), _ => new InternalServerErrorResult() }; if (earlyReturn != null) { return(earlyReturn); } await groupActions.AddAsync( new SignalRGroupAction { UserId = user.Id.ToIdString(), Action = GroupAction.Add, GroupName = groupIdGuid.ToIdString() }); return(new OkResult()); }