コード例 #1
0
        public async Task DeleteForwardedMessages()
        {
            var messages         = fillTestDbHelper.Messages.Take(5).ToList();
            var expectedMessages = MessageConverter.GetMessagesVm(MessageConverter.GetMessagesDto(messages), null);
            var actualMessages   = await deleteMessagesService.DeleteForwardedDialogMessagesAsync(expectedMessages);

            Assert.Equal(expectedMessages.Select(opt => opt.GlobalId.Value), actualMessages.Select(opt => opt.GlobalId));
        }
コード例 #2
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;
            }
        }