public async Task <Response> CreateResponseAsync() { try { switch (request.ConversationType) { case ConversationType.Dialog: { var users = await loadDialogsService.GetDialogUsersAsync(request.ConversationId).ConfigureAwait(false); await deleteDialogsService.DeleteDialogAsync(request.ConversationId, clientConnection.UserId.GetValueOrDefault()).ConfigureAwait(false); UsersConversationsCacheService.Instance.UpdateUsersDialogsAsync(users.Select(opt => opt.Id.Value)); } break; case ConversationType.Chat: { List <long> usersId = await loadChatsService.GetChatUsersIdAsync(request.ConversationId).ConfigureAwait(false); await deleteChatsService.DeleteChatAsync(request.ConversationId, clientConnection.UserId.GetValueOrDefault()).ConfigureAwait(false); UsersConversationsCacheService.Instance.UpdateUsersChatsAsync(usersId); BlockSegmentVm segment = await BlockSegmentsService.Instance.CreateDeleteChatSegmentAsync( request.ConversationId, NodeSettings.Configs.Node.Id).ConfigureAwait(false); BlockGenerationHelper.Instance.AddSegment(segment); } break; case ConversationType.Channel: { List <long> usersId = await loadChannelsService.GetChannelUsersIdAsync(request.ConversationId).ConfigureAwait(false); await deleteChannelsService.DeleteChannelAsync(request.ConversationId, clientConnection.UserId.GetValueOrDefault()).ConfigureAwait(false); UsersConversationsCacheService.Instance.UpdateUsersChannelsAsync(usersId); BlockSegmentVm segment = await BlockSegmentsService.Instance.CreateDeleteChannelSegmentAsync( request.ConversationId, NodeSettings.Configs.Node.Id).ConfigureAwait(false); BlockGenerationHelper.Instance.AddSegment(segment); } break; } nodeNoticeService.SendDeleteConversationsNodeNoticeAsync(request.ConversationId, request.ConversationType, clientConnection.UserId.GetValueOrDefault()); return(new ResultResponse(request.RequestId)); } catch (PermissionDeniedException ex) { Logger.WriteLog(ex, request); return(new ResultResponse(request.RequestId, "Conversation not found or user does not have access to conversation.", ErrorCode.DeleteConversationProblem)); } }
public async Task HandleAsync() { switch (notice.ConversationType) { case ConversationType.Dialog: { List <long> dialogsId = await loadDialogsService.GetDialogsIdByUsersIdPairAsync(notice.RequestingUserId, notice.ConversationId).ConfigureAwait(false); await deleteDialogsService.DeleteDialogAsync(dialogsId.FirstOrDefault(), notice.RequestingUserId).ConfigureAwait(false); UsersConversationsCacheService.Instance.UpdateUsersDialogsAsync(notice.RequestingUserId, notice.ConversationId); } break; case ConversationType.Chat: { var usersId = await loadChatsService.GetChatUsersIdAsync(notice.ConversationId).ConfigureAwait(false); await deleteChatsService.DeleteChatAsync(notice.ConversationId, notice.RequestingUserId).ConfigureAwait(false); UsersConversationsCacheService.Instance.UpdateUsersChatsAsync(usersId); BlockSegmentVm segment = await BlockSegmentsService.Instance.CreateDeleteChatSegmentAsync(notice.ConversationId, notice.NodeId).ConfigureAwait(false); BlockGenerationHelper.Instance.AddSegment(segment); } break; case ConversationType.Channel: { var usersId = await loadChannelsService.GetChannelUsersIdAsync(notice.ConversationId).ConfigureAwait(false); await deleteChannelsService.DeleteChannelAsync(notice.ConversationId, notice.RequestingUserId).ConfigureAwait(false); UsersConversationsCacheService.Instance.UpdateUsersChannelsAsync(usersId); BlockSegmentVm segment = await BlockSegmentsService.Instance.CreateDeleteChannelSegmentAsync(notice.ConversationId, notice.NodeId).ConfigureAwait(false); BlockGenerationHelper.Instance.AddSegment(segment); } break; } }
public async Task DeleteChats() { var chat = fillTestDbHelper.Chats.FirstOrDefault(); var creatorChat = chat.ChatUsers.FirstOrDefault(opt => opt.UserRole == UserRole.Creator); await deleteChatsService.DeleteChatAsync(chat.Id, creatorChat.UserId); }