public async Task <IActionResult> CloseChannelAsync(Guid channelId)
        {
            var userId = GetCurrentUserId();
            await _channelService.CloseChannelAsync(new ChannelRequest(userId, channelId));

            return(Ok());
        }
Beispiel #2
0
        public async Task CloseChannelAsync(ChannelRequest request)
        {
            try
            {
                var channel = await _channelService.GetChannelByIdAsync(request);

                var member = await _memberService.GetMemberSummaryBySaasUserIdAsync(request.SaasUserId);

                if (channel.CreatorId != member.Id && member.Role != UserRole.Admin)
                {
                    throw new Exception(String.Format(LanguageResources.RoomOwnerRequired, channel.Name));
                }
                if (channel.IsClosed)
                {
                    throw new Exception(String.Format(LanguageResources.RoomAlreadyClosed, channel.Name));
                }

                await _channelService.CloseChannelAsync(request);

                var channelSummary = await _channelService.GetChannelSummaryAsync(request);

                await _channelNotificationHub.OnCloseChannel(member, channelSummary);

                await _channelNotificationHub.OnUpdateChannel(member, channelSummary);
            }
            catch (ServiceException 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 CloseChannelAsync(ChannelRequest request)
        {
            await _channelService.CloseChannelAsync(request.SaasUserId, request.ChannelId);

            var channelSummary = await _channelService.GetChannelSummaryAsync(request.SaasUserId, request.ChannelId);

            await _channelNotificationService.OnCloseChannel(channelSummary);

            var channelMembers = await _memberService.GetChannelMembersAsync(request.ChannelId);

            foreach (var member in channelMembers)
            {
                // unsubscribe user from channel
                await _pushNotificationService.UnsubscribeUserFromTagAsync(member.SaasUserId, PushNotificationsTagTemplates.GetChatChannelTag(request.ChannelId.ToString()));
            }

            // TODO [az]: do we need this notification?
            await _channelNotificationService.OnUpdateChannel(channelSummary);
        }
        public async Task CloseChannelAsyncTest()
        {
            // Arrange
            var request = new CreateChannelRequest(SaasUserId, "name", ChannelType.Public)
            {
                Description    = "test",
                WelcomeMessage = "test"
            };

            var channel = await _channelService.CreateChannelAsync(request);

            // Act
            await _channelService.CloseChannelAsync(SaasUserId, channel.Id);

            var newChannel = await _channelService.GetChannelByIdAsync(channel.Id);

            // Assert
            Assert.NotNull(newChannel);
            Assert.True(newChannel.IsClosed);
        }