示例#1
0
        public virtual async Task Handle(IChatRemovedEvent <TChatInfo> @event, IChatBusContext chatBusContext)
        {
            var notification = ChatsNotificationBuilder.BuildChatRemovedNotification(@event);

            await Notify(@event.ChatId, notification);

            await NotificationRouteService.RemoveChat(@event.ChatId);
        }
示例#2
0
        public virtual async Task Handle(IRemoveChatCommand command, IChatBusContext chatEventPublisher)
        {
            await ChatsPermissionValidator.ValidateRemove(command.InitiatorUserId, command.ChatId, WorkerName).ConfigureAwait(false);

            var chatInfo = await ChatStore.Delete(command.ChatId, command.InitiatorUserId).ConfigureAwait(false);

            var @event = ChatsEventBuilder.BuildChatRemovedEvent(command.InitiatorUserId, command.ChatId, chatInfo);
            await chatEventPublisher.EventPublisher.Publish(@event).ConfigureAwait(false);
        }
示例#3
0
        public virtual async Task Handle(IReadChatMessagesCommand command, IChatBusContext chatEventPublisher)
        {
            await ChatMessagesPermissionValidator.ValidateRead(command.InitiatorUserId, command.ChatId, command.Index, command.Force, WorkerName).ConfigureAwait(false);

            await ChatMessageStore.Read(command.ChatId, command.InitiatorUserId, command.Index, command.Force).ConfigureAwait(false);

            var @event = ChatMessagesEventBuilder.BuildChatMessagesReadEvent(command.InitiatorUserId, command.ChatId, command.Index, command.Force);
            await chatEventPublisher.EventPublisher.Publish(@event).ConfigureAwait(false);
        }
示例#4
0
        public virtual async Task Handle(IEditChatInfoCommand <TChatInfo> command, IChatBusContext chatEventPublisher)
        {
            await ChatsPermissionValidator.ValidateEditInfo(command.InitiatorUserId, command.ChatId, command.ChatInfo, WorkerName).ConfigureAwait(false);

            var chatInfo = await ChatStore.UpdateInfo(command.ChatId, command.ChatInfo, command.InitiatorUserId).ConfigureAwait(false);

            var @event = ChatsEventBuilder.BuildChatInfoEditedEvent(command.InitiatorUserId, command.ChatId, chatInfo);
            await chatEventPublisher.EventPublisher.Publish(@event).ConfigureAwait(false);
        }
示例#5
0
        public virtual async Task Handle(IChatInfoEditedEvent <TChatInfo> @event, IChatBusContext chatBusContext)
        {
            if (ChatWorkersConfiguration.DisableSystemMessages)
            {
                return;
            }
            var messageInfo = SystemMessagesBuilder.BuildChatInfoEditedMessage(@event);

            await AddMessage(@event, messageInfo, chatBusContext);
        }
示例#6
0
        public virtual async Task Handle(IBlockChatParticipantCommand command, IChatBusContext chatEventPublisher)
        {
            await ChatParticipantsPermissionValidator.ValidateRemove(command.InitiatorUserId, command.ChatId, command.UserId, WorkerName).ConfigureAwait(false);

            var currentParticipant = await ChatParticipantStore.Retrieve(command.ChatId, command.UserId).ConfigureAwait(false);

            var participant = await SetUser(command, ChatParticipantStatus.Blocked).ConfigureAwait(false);

            var @event = ChatParticipantsEventBuilder.BuildChatParticipantBlockedEvent(command.InitiatorUserId, command.ChatId, participant, currentParticipant?.ChatParticipantStatus);
            await chatEventPublisher.EventPublisher.Publish(@event).ConfigureAwait(false);
        }
示例#7
0
        public virtual async Task Handle(IInviteChatParticipantCommand command, IChatBusContext chatEventPublisher)
        {
            await ChatParticipantsPermissionValidator.ValidateInvite(command.InitiatorUserId, command.ChatId, command.UserId, command.ChatParticipantType, command.Style, command.Metadata, WorkerName).ConfigureAwait(false);

            var currentParticipant = await ChatParticipantStore.Retrieve(command.ChatId, command.UserId).ConfigureAwait(false);

            var participant = await SetParticipationCandidate(command, ChatParticipantStatus.Invited).ConfigureAwait(false);

            var @event = ChatParticipantsEventBuilder.BuildChatParticipantInvitedEvent(command.InitiatorUserId, command.ChatId, participant, currentParticipant?.ChatParticipantStatus);
            await chatEventPublisher.EventPublisher.Publish(@event).ConfigureAwait(false);
        }
示例#8
0
        public virtual async Task Handle(IRemoveChatMessageCommand command, IChatBusContext chatEventPublisher)
        {
            var currentMessage = await ChatMessageStore.Retrieve(command.ChatId, command.MessageId).ConfigureAwait(false);

            if (!currentMessage.IsSystem)
            {
                await ChatMessagesPermissionValidator.ValidateRemove(command.InitiatorUserId, command.ChatId, command.MessageId, WorkerName).ConfigureAwait(false);
            }
            if (currentMessage.Immutable)
            {
                throw new DotChatRemoveImmutableMessageException(command.MessageId, command.ChatId, command.InitiatorUserId);
            }
            var message = await ChatMessageStore.Delete(command.ChatId, command.MessageId, command.InitiatorUserId).ConfigureAwait(false);

            await ChatMessageStore.Archive(command.ChatId, currentMessage.MessageId, command.MessageId, currentMessage, command.InitiatorUserId).ConfigureAwait(false);

            var @event = ChatMessagesEventBuilder.BuildChatMessageRemovedEvent(command.InitiatorUserId, command.ChatId, message);
            await chatEventPublisher.EventPublisher.Publish(@event).ConfigureAwait(false);
        }
示例#9
0
        public virtual async Task Handle(IChatMessagesReadEvent @event, IChatBusContext chatBusContext)
        {
            var notification = ChatMessagesNotificationBuilder.BuildChatMessagesReadNotification(@event);

            await Notify(@event.ChatId, notification);
        }
示例#10
0
        public virtual async Task Handle(IChatMessageRemovedEvent <TChatInfo, TChatUser, TChatMessage, TChatMessageInfo, TTextMessage, TQuoteMessage, TMessageAttachmentCollection, TMessageAttachment, TChatRefMessageCollection, TChatRefMessage, TContactMessageCollection, TContactMessage> @event, IChatBusContext chatBusContext)
        {
            var notification = ChatMessagesNotificationBuilder.BuildChatMessageRemovedNotification(@event);

            await Notify(@event.ChatId, notification);
        }
示例#11
0
        public virtual async Task Handle(IEditChatMessageCommand <TChatInfo, TChatUser, TChatMessageInfo, TTextMessage, TQuoteMessage, TMessageAttachmentCollection, TMessageAttachment, TChatRefMessageCollection, TChatRefMessage, TContactMessageCollection, TContactMessage> command, IChatBusContext chatEventPublisher)
        {
            var currentMessage = await ChatMessageStore.Retrieve(command.ChatId, command.MessageId).ConfigureAwait(false);

            if (!currentMessage.IsSystem)
            {
                await ChatMessagesPermissionValidator.ValidateEdit(command.InitiatorUserId, command.ChatId, command.MessageId, command.MessageInfo, WorkerName).ConfigureAwait(false);
            }
            if (currentMessage.Immutable)
            {
                throw new DotChatEditImmutableMessageException(command.MessageId, command.ChatId, command.InitiatorUserId);
            }
            var message = await ChatMessageStore.Update(command.ChatId, command.MessageId, command.MessageInfo, command.InitiatorUserId).ConfigureAwait(false);

            await ChatMessageStore.Archive(command.ChatId, currentMessage.MessageId, command.ArchivedMessageId, currentMessage, command.InitiatorUserId).ConfigureAwait(false);

            var @event = ChatMessagesEventBuilder.BuildChatMessageEditedEvent(command.InitiatorUserId, command.ChatId, message);
            await chatEventPublisher.EventPublisher.Publish(@event).ConfigureAwait(false);
        }
示例#12
0
        public virtual async Task Handle(IAddChatMessageCommand <TChatInfo, TChatUser, TChatMessageInfo, TTextMessage, TQuoteMessage, TMessageAttachmentCollection, TMessageAttachment, TChatRefMessageCollection, TChatRefMessage, TContactMessageCollection, TContactMessage> command, IChatBusContext chatEventPublisher)
        {
            if (!command.IsSystem)
            {
                await ChatMessagesPermissionValidator.ValidateAdd(command.InitiatorUserId, command.ChatId, command.MessageInfo, WorkerName).ConfigureAwait(false);
            }
            var message = await ChatMessageStore.Create(command.ChatId, command.InitiatorUserId, command.MessageId, command.MessageInfo, command.Timestamp, command.Index, command.IsSystem, command.InitiatorUserId).ConfigureAwait(false);

            if (!ChatWorkersConfiguration.FastMessageMode)
            {
                var @event = ChatMessagesEventBuilder.BuildChatMessageAddedEvent(command.InitiatorUserId, command.ChatId, message);
                await chatEventPublisher.EventPublisher.Publish(@event).ConfigureAwait(false);
            }
        }
示例#13
0
        public virtual async Task Handle(IChatParticipantsAppendedEvent <TParticipationResultCollection, TParticipationResult, TChatParticipant> @event, IChatBusContext chatBusContext)
        {
            var users = @event.Added.Select(r => r.Participant.UserId);
            await NotificationRouteService.AddUsersToChat(users, @event.ChatId);

            var notification = ChatParticipantsNotificationBuilder.BuildChatParticipantsAppendedNotification(@event);

            await Notify(@event.ChatId, notification);
        }
示例#14
0
 protected virtual async Task AddMessage <TEvent>(TEvent @event, TChatMessageInfo messageInfo, IChatBusContext chatBusContext)
     where TEvent : IEvent, IChatRelated
 {
     if (ChatWorkersConfiguration.DisableSystemMessages)
     {
         return;
     }
     await AddMessage(@event.InitiatorUserId, @event.ChatId, messageInfo, chatBusContext);
 }
示例#15
0
        public virtual async Task Handle(IChatInfoEditedEvent <TChatInfo> @event, IChatBusContext chatBusContext)
        {
            var notification = ChatsNotificationBuilder.BuildChatInfoEditedNotification(@event);

            await Notify(@event.ChatId, notification);
        }
示例#16
0
        public virtual async Task Handle(IChatParticipantBlockedEvent <TChatParticipant> @event, IChatBusContext chatBusContext)
        {
            var notification = ChatParticipantsNotificationBuilder.BuildChatParticipantBlockedNotification(@event);

            await Notify(@event.ChatId, notification);

            await NotificationRouteService.RemoveUserFromChat(@event.Participant.UserId, @event.ChatId);
        }
示例#17
0
        public virtual async Task Handle(IChatParticipantsAppendedEvent <TParticipationResultCollection, TParticipationResult, TChatParticipant> @event, IChatBusContext chatBusContext)
        {
            if (ChatWorkersConfiguration.DisableSystemMessages)
            {
                return;
            }
            var messagesInfo = SystemMessagesBuilder.BuildBulkParticipantsAppendedMessages(@event);

            foreach (var messageInfo in messagesInfo)
            {
                await AddMessage(@event, messageInfo, chatBusContext);
            }
        }
示例#18
0
        public virtual async Task Handle(IAppendChatParticipantsCommand <TParticipationCandidateCollection, TParticipationCandidate> command, IChatBusContext chatEventPublisher)
        {
            await ChatParticipantsPermissionValidator.ValidateAppend(command.InitiatorUserId, command.ChatId, command.ToAdd, command.ToInvite, WorkerName).ConfigureAwait(false);

            var currentParticipants = await ChatParticipantStore.RetrieveList(command.ChatId, command.ToAdd.Concat(command.ToInvite).Select(r => r.UserId));

            var append = command.ToAdd.Concat(command.ToInvite);
            var users  = await ReadUserStore.Retrieve(append.Select(r => r.UserId));

            users = users.Join(append, r => r.UserId, r => r.UserId, (u, c) => new { User = u, Candidate = c })
                    .Select(r => ReadUserStore.Customize(r.User, r.Candidate.Style, r.Candidate.Metadata))
                    .ToList();

            async Task <IReadOnlyCollection <TParticipationResult> > SetStatusGroup(IReadOnlyCollection <TParticipationCandidate> candidates, ChatParticipantStatus status)
            {
                IEnumerable <TChatParticipant> chatParticipants = Enumerable.Empty <TChatParticipant>();

                foreach (var group in candidates.GroupBy(r => r.ChatParticipantType))
                {
                    var participants = await ChatParticipantStore.Set(command.ChatId,
                                                                      users.Join(@group, r => r.UserId, r => r.UserId, (u, p) => u),
                                                                      @group.Key, status, command.InitiatorUserId).ConfigureAwait(false);

                    chatParticipants = chatParticipants.Concat(participants);
                }
                return(chatParticipants
                       .GroupJoin(currentParticipants, r => r.UserId, r => r.UserId,
                                  (p, cp) => new { p, cp }).SelectMany(r => r.cp.DefaultIfEmpty(), (tmp, cp) => ChatParticipantsEventBuilder.BuildParticipationResult(tmp.p, cp?.ChatParticipantStatus))
                       .ToList());
            }

            var added = await SetStatusGroup(command.ToAdd, ChatParticipantStatus.Active);

            var invited = await SetStatusGroup(command.ToInvite, ChatParticipantStatus.Invited);

            var @event = ChatParticipantsEventBuilder.BuildChatParticipantsAppendedEvent(command.InitiatorUserId, command.ChatId, added, invited);
            await chatEventPublisher.EventPublisher.Publish(@event).ConfigureAwait(false);
        }
示例#19
0
 protected virtual async Task AddMessage(Guid initiatorUserId, Guid chatId, TChatMessageInfo messageInfo, IChatBusContext chatBusContext)
 {
     if (messageInfo != null)
     {
         var addMessageCommand = ChatMessagesCommandBuilder.BuildIndexChatMessageCommand(initiatorUserId, chatId, null, true, messageInfo);
         await chatBusContext.CommandSender.Send(addMessageCommand);
     }
 }
示例#20
0
        public virtual async Task Handle(IAddChatCommand <TChatInfo, TParticipationCandidateCollection, TParticipationCandidate> command, IChatBusContext chatEventPublisher)
        {
            await ChatsPermissionValidator.ValidateAdd(command.InitiatorUserId, command.ChatId, command.ChatInfo, WorkerName).ConfigureAwait(false);

            var chat = await ChatStore.Create(command.ChatId, command.ChatInfo, command.ToAdd, command.ToInvite, command.InitiatorUserId).ConfigureAwait(false);

            var @event = ChatsEventBuilder.BuildChatAddedEvent(command.InitiatorUserId, chat);
            await chatEventPublisher.EventPublisher.Publish(@event).ConfigureAwait(false);
        }
示例#21
0
        public virtual async Task Handle(IChatParticipantTypeChangedEvent <TChatParticipant> @event, IChatBusContext chatBusContext)
        {
            var notification = ChatParticipantsNotificationBuilder.BuildChatParticipantTypeChangedNotification(@event);

            await Notify(@event.ChatId, notification);
        }
示例#22
0
        public virtual async Task Handle(IChatAddedEvent <TChat, TChatInfo, TChatParticipantCollection, TChatParticipant, TChatUser, TChatMessageInfo, TTextMessage, TQuoteMessage, TMessageAttachmentCollection, TMessageAttachment, TChatRefMessageCollection, TChatRefMessage, TContactMessageCollection, TContactMessage> @event, IChatBusContext chatBusContext)
        {
            var userIds = @event.Chat.Participants.Where(r => r.ChatParticipantStatus == ChatParticipantStatus.Active).Select(r => r.UserId);
            await NotificationRouteService.AddUsersToChat(userIds, @event.Chat.ChatId);

            var notification = ChatsNotificationBuilder.BuildChatAddedNotification(@event);

            await Notify(@event.Chat.ChatId, notification);
        }
示例#23
0
        public virtual async Task Handle(IChatAddedEvent <TChat, TChatInfo, TChatParticipantCollection, TChatParticipant, TChatUser, TChatMessageInfo, TTextMessage, TQuoteMessage, TMessageAttachmentCollection, TMessageAttachment, TChatRefMessageCollection, TChatRefMessage, TContactMessageCollection, TContactMessage> @event, IChatBusContext chatBusContext)
        {
            if (ChatWorkersConfiguration.DisableSystemMessages)
            {
                return;
            }
            var messagesInfo = SystemMessagesBuilder.BuildChatAddedMessage(@event);

            foreach (var messageInfo in messagesInfo)
            {
                await AddMessage(@event.InitiatorUserId, @event.Chat.ChatId, messageInfo, chatBusContext);
            }
        }
示例#24
0
 public virtual async Task Handle(IChatMessageAddedEvent <TChatInfo, TChatUser, TChatMessage, TChatMessageInfo, TTextMessage, TQuoteMessage, TMessageAttachmentCollection, TMessageAttachment, TChatRefMessageCollection, TChatRefMessage, TContactMessageCollection, TContactMessage> @event, IChatBusContext chatBusContext)
 {
     await ChatStore.SetTop(@event.ChatId, @event.Message);
 }
示例#25
0
        public virtual async Task Handle(IIndexChatMessageCommand <TChatInfo, TChatUser, TChatMessageInfo, TTextMessage, TQuoteMessage, TMessageAttachmentCollection, TMessageAttachment, TChatRefMessageCollection, TChatRefMessage, TContactMessageCollection, TContactMessage> command, IChatBusContext chatEventPublisher)
        {
            if (!command.IsSystem)
            {
                await ChatMessagesPermissionValidator.ValidateAdd(command.InitiatorUserId, command.ChatId, command.MessageInfo, WorkerName).ConfigureAwait(false);
            }
            var timestamp = await ChatMessageTimestampGenerator.Generate();

            var index = await _messageIndexGenerator.Generate(command.ChatId).ConfigureAwait(false);

            var addCommand = ChatMessagesCommandBuilder.BuildAddChatMessageCommand(command.InitiatorUserId, command.ChatId, command.MessageId, timestamp, index, command.IsSystem, command.MessageInfo);
            await chatEventPublisher.CommandSender.Send(addCommand).ConfigureAwait(false);

            if (ChatWorkersConfiguration.FastMessageMode)
            {
                var @event = ChatMessagesEventBuilder.BuildChatMessageAddedEvent(command.InitiatorUserId, command.ChatId, command.MessageId, timestamp, index, command.IsSystem, command.MessageInfo);
                await chatEventPublisher.EventPublisher.Publish(@event).ConfigureAwait(false);
            }
        }