Disable chat deletion
This commit is contained in:
@@ -367,33 +367,11 @@ public sealed class AdminController(
|
||||
}
|
||||
|
||||
[HttpDelete("api/chats/{id:guid}")]
|
||||
public async Task<IActionResult> DeleteChat(Guid id, [FromQuery] string? pairingCode, CancellationToken cancellationToken)
|
||||
public IActionResult DeleteChat(Guid id, [FromQuery] string? pairingCode)
|
||||
{
|
||||
if (!IsPairingCodeValid(pairingCode)) return Unauthorized();
|
||||
|
||||
var chat = await db.Chats
|
||||
.Include(x => x.Messages)
|
||||
.ThenInclude(x => x.Attachments)
|
||||
.FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
|
||||
if (chat is null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var files = chat.Messages
|
||||
.SelectMany(x => x.Attachments)
|
||||
.Select(x => storage.GetPath(x.StorageFileName))
|
||||
.Where(System.IO.File.Exists)
|
||||
.ToArray();
|
||||
|
||||
db.Chats.Remove(chat);
|
||||
await db.SaveChangesAsync(cancellationToken);
|
||||
foreach (var file in files)
|
||||
{
|
||||
System.IO.File.Delete(file);
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
return BadRequest("Chat deletion is disabled because MAX does not remove chats from the web client.");
|
||||
}
|
||||
|
||||
private async Task<AdminStatusDto> BuildStatusAsync(CancellationToken cancellationToken)
|
||||
|
||||
@@ -274,7 +274,7 @@ public sealed class ChatsController(
|
||||
}
|
||||
|
||||
[HttpPost("delete")]
|
||||
public async Task<IActionResult> DeleteChats(ChatBulkActionRequest request, CancellationToken cancellationToken)
|
||||
public IActionResult DeleteChats(ChatBulkActionRequest request)
|
||||
{
|
||||
var chatIds = request.ChatIds.Distinct().ToArray();
|
||||
if (chatIds.Length == 0)
|
||||
@@ -282,30 +282,7 @@ public sealed class ChatsController(
|
||||
return BadRequest("chatIds are required.");
|
||||
}
|
||||
|
||||
var chats = await LoadChatsWithAttachmentsAsync(chatIds, cancellationToken);
|
||||
if (chats.Count != chatIds.Length)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
var files = AttachmentFiles(chats).ToArray();
|
||||
foreach (var chat in chats)
|
||||
{
|
||||
db.Messages.RemoveRange(chat.Messages);
|
||||
chat.DeletedAt ??= now;
|
||||
chat.HistoryClearedAt = now;
|
||||
chat.LastMessageAt = null;
|
||||
chat.LastMessagePreview = null;
|
||||
chat.UnreadCount = 0;
|
||||
chat.UpdatedAt = now;
|
||||
QueuePendingMaxAction(chat, ChatPendingMaxAction.DeleteChat, now);
|
||||
}
|
||||
|
||||
await db.SaveChangesAsync(cancellationToken);
|
||||
DeleteFiles(files);
|
||||
await hubContext.Clients.All.SendAsync("ChatListInvalidated", cancellationToken);
|
||||
return NoContent();
|
||||
return BadRequest("Chat deletion is disabled because MAX does not remove chats from the web client.");
|
||||
}
|
||||
|
||||
[HttpGet("{chatId:guid}/search")]
|
||||
|
||||
@@ -68,7 +68,9 @@ public sealed class MockMaxBridgeClient : IMaxBridgeClient
|
||||
|
||||
public Task<MaxActionResult> DeleteChatAsync(string externalChatId, string? chatUrl, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.FromResult(new MaxActionResult(true, null));
|
||||
return Task.FromResult(new MaxActionResult(
|
||||
false,
|
||||
"Chat deletion is disabled because MAX does not remove chats from the web client."));
|
||||
}
|
||||
|
||||
public Task<MaxSendResult> SendTextAsync(string externalChatId, string? chatUrl, string text, CancellationToken cancellationToken)
|
||||
|
||||
@@ -69,14 +69,11 @@ public sealed class WorkerMaxBridgeClient(
|
||||
?? new MaxActionResult(false, "Worker returned an empty clear history result.");
|
||||
}
|
||||
|
||||
public async Task<MaxActionResult> DeleteChatAsync(string externalChatId, string? chatUrl, CancellationToken cancellationToken)
|
||||
public Task<MaxActionResult> DeleteChatAsync(string externalChatId, string? chatUrl, CancellationToken cancellationToken)
|
||||
{
|
||||
return await SendAsync<MaxActionResult>(
|
||||
HttpMethod.Post,
|
||||
"/chat/delete",
|
||||
new { externalChatId, chatUrl },
|
||||
cancellationToken)
|
||||
?? new MaxActionResult(false, "Worker returned an empty delete chat result.");
|
||||
return Task.FromResult(new MaxActionResult(
|
||||
false,
|
||||
"Chat deletion is disabled because MAX does not remove chats from the web client."));
|
||||
}
|
||||
|
||||
public async Task<MaxSendResult> SendTextAsync(string externalChatId, string? chatUrl, string text, CancellationToken cancellationToken)
|
||||
|
||||
@@ -125,10 +125,9 @@ public sealed class MaxOutboxService(
|
||||
chat,
|
||||
(externalChatId, chatUrl) => maxBridge.ClearChatHistoryAsync(externalChatId, chatUrl, cancellationToken),
|
||||
cancellationToken),
|
||||
ChatPendingMaxAction.DeleteChat => await ApplyMaxChatActionAsync(
|
||||
chat,
|
||||
(externalChatId, chatUrl) => maxBridge.DeleteChatAsync(externalChatId, chatUrl, cancellationToken),
|
||||
cancellationToken),
|
||||
ChatPendingMaxAction.DeleteChat => new MaxActionResult(
|
||||
false,
|
||||
"Chat deletion is disabled because MAX does not remove chats from the web client."),
|
||||
_ => new MaxActionResult(false, $"Unsupported chat action: {pendingAction.Value}.")
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user