Ejemplo n.º 1
0
        private async Task PublishChannelModerationChangedEvent(Channel channel, Guid requestedByUserId)
        {
            var @event = new ChannelChangedSystemModerationEvent
            {
                ChannelName       = channel.ChannelName,
                SystemIsModerator = channel.SystemIsModerator,
                RequestedByUserId = requestedByUserId
            };

            await messageDispatcher.Publish(@event).ConfigureAwait(false);
        }
        public async Task Handle(ChannelChangedSystemModerationEvent message, IMessageHandlerContext context)
        {
            var user = await userRepository.GetById(message.RequestedByUserId).ConfigureAwait(false);

            var applicationContext = ApplicatonContext.CreateFromUser(user);

            // TODO This works for now. Should possibly be more specific that use is enabling / disabling this feature.
            if (message.SystemIsModerator)
            {
                await chatlistenerService.JoinPubSub(message.ChannelName, applicationContext).ConfigureAwait(false);

                await context.Publish(new AutoModListenerEnabledForChannelEvent(message.ChannelName)).ConfigureAwait(false);
            }
            else
            {
                await chatlistenerService.LeavePubSub(message.ChannelName, applicationContext).ConfigureAwait(false);

                await context.Publish(new AutoModListenerDisabledForChannelEvent(message.ChannelName)).ConfigureAwait(false);
            }
        }