public async Task JoinToChannelAsync(JoinToChannelRequest request) { if (request.ChannelId == Guid.Empty) { throw new Exception(LanguageResources.Join_RoomRequired); } // Locate the room, does NOT have to be open try { var member = await _memberService.GetMemberSummaryBySaasUserIdAsync(request.SaasUserId); var isMemberExistInChannel = await _channelService.CheckIfMemberExistInChannelAsync(new InviteMemberRequest(request.SaasUserId, request.ChannelId, member.Id)); if (!isMemberExistInChannel) { await _channelService.JoinToChannelAsync(request); var channel = await _channelService.GetChannelSummaryAsync(new ChannelRequest(request.SaasUserId, request.ChannelId)); await _channelNotificationHub.OnJoinChannel(member, channel); } } catch (NotFoundException ex) { _logger.Event(PropertyNames.EventId).With.Message("Exception: Channel does not exist. ChannelId: {channelId}", request.ChannelId).Exception(ex).AsError(); throw new Exception(String.Format(LanguageResources.RoomNotFound, request.ChannelId)); } }
public async Task JoinToChannelAsync(JoinToChannelRequest request) { await CheckAccessTokenAndExecute(new TaskReference(async() => { request.SaasUserId = Context.GetSaasUserId(); await _channelSocketService.JoinToChannelAsync(request); }), request.RequestId); }
public async Task JoinToChannelAsync(JoinToChannelRequest request) { var channel = await UnitOfWork.ChannelRepository.GetChannelByIdAsync(request.ChannelId); Ensure.That(channel) .WithException(x => new NotFoundException(new ErrorDto(ErrorCode.NotFound, "Channel does not exist."))) .IsNotNull(); var member = await UnitOfWork.MemberRepository.GetMemberBySaasUserIdAsync(request.SaasUserId); Ensure.That(member) .WithException(x => new ServiceException(new ErrorDto(ErrorCode.NotFound, "Member does not exist."))) .IsNotNull(); var members = await _channelMemberService.GetChannelMembersAsync(new ChannelRequest(request.SaasUserId, request.ChannelId)); if (members.Any(x => x.MemberId == member.Id)) { throw new ConflictException(new ErrorDto(ErrorCode.ConflictError, "You have been already joined to the channel.")); } // Throw if the channel is private but the user isn't allowed if (channel.Type == ChannelType.Private && channel.CreatorId != member.Id) { throw new ConflictException(new ErrorDto(ErrorCode.ConflictError, "This channel is not available for you.")); } var channelMember = new ChannelMembers { ChannelId = channel.Id, MemberId = member.Id, LastReadMessageId = null }; using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { await UnitOfWork.ChannelMemberRepository.AddChannelMemberAsync(channelMember); await UnitOfWork.ChannelRepository.IncrementChannelMembersCount(channel.Id); transactionScope.Complete(); } }