Пример #1
0
        private async Task <IEnumerable <MessageDto> > DeleteChatMessagesAsync()
        {
            List <MessageDto> deletedMessages = await deleteMessagesService.DeleteMessagesInfoAsync(
                request.ConversationId,
                ConversationType.Chat,
                request.MessagesIds,
                clientConnection.UserId.GetValueOrDefault()).ConfigureAwait(false);

            conversationsNoticeService.SendMessagesUpdatedNoticeAsync(
                request.ConversationId,
                ConversationType.Chat,
                deletedMessages,
                clientConnection.UserId.GetValueOrDefault(),
                true,
                clientConnection);
            UsersConversationsCacheService.Instance.UpdateUsersChatsAsync(
                await loadChatsService.GetChatUsersIdAsync(request.ConversationId).ConfigureAwait(false));
            return(deletedMessages);
        }
Пример #2
0
        public async Task DeleteMessagesInfo()
        {
            var message         = fillTestDbHelper.Messages.FirstOrDefault();
            var expectedMessage = MessageConverter.GetMessageVm(MessageConverter.GetMessageDto(message), null);
            var actualMessage   = (await deleteMessagesService.DeleteMessagesInfoAsync(
                                       expectedMessage.ConversationId.Value,
                                       expectedMessage.ConversationType,
                                       new List <Guid> {
                expectedMessage.GlobalId.Value
            },
                                       expectedMessage.SenderId.Value)).FirstOrDefault();

            Assert.Equal(expectedMessage.GlobalId, actualMessage.GlobalId);
        }
Пример #3
0
        public async Task HandleAsync()
        {
            switch (notice.ConversationType)
            {
            case ConversationType.Dialog:
            {
                var dialogs = await loadDialogsService.GetUsersDialogsAsync(
                    notice.Messages.FirstOrDefault().SenderId.GetValueOrDefault(),
                    notice.Messages.FirstOrDefault().ReceiverId.GetValueOrDefault()).ConfigureAwait(false);

                if (!dialogs.Any())
                {
                    await deleteMessagesService.DeleteForwardedDialogMessagesAsync(notice.Messages).ConfigureAwait(false);

                    return;
                }
                List <MessageDto> messages = await deleteMessagesService.DeleteMessagesInfoAsync(
                    dialogs.FirstOrDefault(dialog => dialog.FirstUserId == notice.RequestorId).Id,
                    ConversationType.Dialog,
                    notice.Messages.Select(opt => opt.GlobalId.GetValueOrDefault()),
                    notice.RequestorId).ConfigureAwait(false);

                conversationsNoticeService.SendMessagesUpdatedNoticeAsync(
                    dialogs.FirstOrDefault(dialog => dialog.FirstUserId == notice.RequestorId).Id,
                    ConversationType.Dialog,
                    messages,
                    notice.RequestorId,
                    true,
                    null);
                UsersConversationsCacheService.Instance.UpdateUsersDialogsAsync(
                    notice.Messages.FirstOrDefault().SenderId.GetValueOrDefault(),
                    notice.Messages.FirstOrDefault().ReceiverId.GetValueOrDefault());
            }
            break;

            case ConversationType.Chat:
            {
                List <MessageDto> messages = await deleteMessagesService.DeleteMessagesInfoAsync(
                    notice.ConversationId.GetValueOrDefault(),
                    ConversationType.Chat,
                    notice.Messages.Select(opt => opt.GlobalId.GetValueOrDefault()),
                    notice.RequestorId).ConfigureAwait(false);

                conversationsNoticeService.SendMessagesUpdatedNoticeAsync(
                    notice.ConversationId.GetValueOrDefault(),
                    ConversationType.Chat,
                    messages,
                    notice.RequestorId,
                    true,
                    null);
                UsersConversationsCacheService.Instance.UpdateUsersChatsAsync(
                    await loadChatsService.GetChatUsersIdAsync(notice.ConversationId.GetValueOrDefault()).ConfigureAwait(false));
            }
            break;

            case ConversationType.Channel:
            {
                List <MessageDto> messages = await deleteMessagesService.DeleteMessagesInfoAsync(
                    notice.ConversationId.GetValueOrDefault(),
                    ConversationType.Channel,
                    notice.Messages.Select(opt => opt.GlobalId.GetValueOrDefault()),
                    notice.RequestorId).ConfigureAwait(false);

                conversationsNoticeService.SendMessagesUpdatedNoticeAsync(
                    notice.ConversationId.GetValueOrDefault(),
                    ConversationType.Channel,
                    messages,
                    notice.RequestorId,
                    true,
                    null);
                UsersConversationsCacheService.Instance.UpdateUsersChannelsAsync(
                    await loadChannelsService.GetChannelUsersIdAsync(notice.ConversationId.GetValueOrDefault()).ConfigureAwait(false));
            }
            break;
            }
        }