Fix chat bulk delete URL resolution
This commit is contained in:
@@ -749,7 +749,24 @@ public sealed class ChatsController(
|
||||
return null;
|
||||
}
|
||||
|
||||
var result = await action(chat.ExternalId, chat.WebUrl);
|
||||
var chatUrl = chat.WebUrl;
|
||||
if (string.IsNullOrWhiteSpace(chatUrl))
|
||||
{
|
||||
chatUrl = await ResolveAndPersistChatUrlAsync(chat, cancellationToken);
|
||||
}
|
||||
|
||||
var result = await action(chat.ExternalId, chatUrl);
|
||||
if (!result.Success && IsChatOpenFailure(result.Error))
|
||||
{
|
||||
var previousUrl = chatUrl;
|
||||
chatUrl = await ResolveAndPersistChatUrlAsync(chat, cancellationToken);
|
||||
if (!string.IsNullOrWhiteSpace(chatUrl) &&
|
||||
!string.Equals(previousUrl, chatUrl, StringComparison.Ordinal))
|
||||
{
|
||||
result = await action(chat.ExternalId, chatUrl);
|
||||
}
|
||||
}
|
||||
|
||||
if (result.Success)
|
||||
{
|
||||
return null;
|
||||
@@ -760,6 +777,37 @@ public sealed class ChatsController(
|
||||
statusCode: StatusCodes.Status409Conflict);
|
||||
}
|
||||
|
||||
private async Task<string?> ResolveAndPersistChatUrlAsync(Chat chat, CancellationToken cancellationToken)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(chat.ExternalId))
|
||||
{
|
||||
return chat.WebUrl;
|
||||
}
|
||||
|
||||
var result = await maxBridge.ResolveChatUrlAsync(chat.ExternalId, cancellationToken);
|
||||
if (!result.Success || string.IsNullOrWhiteSpace(result.ChatUrl))
|
||||
{
|
||||
return chat.WebUrl;
|
||||
}
|
||||
|
||||
var nextWebUrl = result.ChatUrl.Trim();
|
||||
if (string.Equals(chat.WebUrl, nextWebUrl, StringComparison.Ordinal))
|
||||
{
|
||||
return chat.WebUrl;
|
||||
}
|
||||
|
||||
chat.WebUrl = nextWebUrl;
|
||||
chat.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
await db.SaveChangesAsync(cancellationToken);
|
||||
await hubContext.Clients.All.SendAsync("ChatListInvalidated", cancellationToken);
|
||||
return chat.WebUrl;
|
||||
}
|
||||
|
||||
private static bool IsChatOpenFailure(string? error)
|
||||
{
|
||||
return error?.Contains("not found or did not open", StringComparison.OrdinalIgnoreCase) == true;
|
||||
}
|
||||
|
||||
private async Task<List<Chat>> LoadChatsWithAttachmentsAsync(IReadOnlyCollection<Guid> chatIds, CancellationToken cancellationToken)
|
||||
{
|
||||
return await db.Chats
|
||||
|
||||
Reference in New Issue
Block a user