Sync phone contacts and enable chat deletion
This commit is contained in:
@@ -51,8 +51,18 @@ public sealed class ChatsController(
|
||||
Kind = ChatKind.MaxDialog
|
||||
};
|
||||
db.Chats.Add(chat);
|
||||
await db.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
chat.Title = request.Title;
|
||||
chat.AvatarUrl = request.AvatarUrl;
|
||||
chat.DeletedAt = null;
|
||||
chat.PendingMaxAction = null;
|
||||
chat.PendingMaxActionError = null;
|
||||
chat.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
}
|
||||
|
||||
await db.SaveChangesAsync(cancellationToken);
|
||||
|
||||
await hubContext.Clients.All.SendAsync("ChatListInvalidated", cancellationToken);
|
||||
return projection.ToDto(chat);
|
||||
@@ -274,7 +284,7 @@ public sealed class ChatsController(
|
||||
}
|
||||
|
||||
[HttpPost("delete")]
|
||||
public IActionResult DeleteChats(ChatBulkActionRequest request)
|
||||
public async Task<IActionResult> DeleteChats(ChatBulkActionRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var chatIds = request.ChatIds.Distinct().ToArray();
|
||||
if (chatIds.Length == 0)
|
||||
@@ -282,7 +292,43 @@ public sealed class ChatsController(
|
||||
return BadRequest("chatIds are required.");
|
||||
}
|
||||
|
||||
return BadRequest("Chat deletion is disabled because MAX does not remove chats from the web client.");
|
||||
var chats = await LoadChatsWithAttachmentsAsync(chatIds, cancellationToken);
|
||||
if (chats.Count != chatIds.Length || chats.Any(chat => chat.DeletedAt is not null))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
foreach (var chat in chats)
|
||||
{
|
||||
var maxFailure = await TryApplyMaxChatActionAsync(
|
||||
chat,
|
||||
(externalChatId, chatUrl) => maxBridge.DeleteChatAsync(externalChatId, chatUrl, cancellationToken),
|
||||
"delete chat",
|
||||
cancellationToken);
|
||||
if (maxFailure is not null)
|
||||
{
|
||||
return maxFailure;
|
||||
}
|
||||
}
|
||||
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
var files = AttachmentFiles(chats).ToArray();
|
||||
foreach (var chat in chats)
|
||||
{
|
||||
db.Messages.RemoveRange(chat.Messages);
|
||||
chat.LastMessageAt = null;
|
||||
chat.LastMessagePreview = null;
|
||||
chat.UnreadCount = 0;
|
||||
chat.DeletedAt = now;
|
||||
chat.UpdatedAt = now;
|
||||
chat.PendingMaxAction = null;
|
||||
chat.PendingMaxActionError = null;
|
||||
}
|
||||
|
||||
await db.SaveChangesAsync(cancellationToken);
|
||||
DeleteFiles(files);
|
||||
await hubContext.Clients.All.SendAsync("ChatListInvalidated", cancellationToken);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpGet("{chatId:guid}/search")]
|
||||
|
||||
Reference in New Issue
Block a user