fix: Bug - Sending files and attachment issues

Hydrate playable media after disk receive, relay file-announce to sibling
devices via account_sync, bind DM attachments to pre-allocated message ids,
and improve gallery retry/cancel UX with bounded parallel auto-downloads.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-14 13:05:23 +02:00
co-authored by Cursor
parent bb0ac930ad
commit fa45052432
30 changed files with 785 additions and 71 deletions
@@ -16,6 +16,7 @@ import {
isDirectMessageAttachmentRoomId,
shouldAutoRequestWhenWatched
} from '../../domain/logic/attachment.logic';
import { ATTACHMENT_AUTO_DOWNLOAD_CONCURRENCY, runTasksWithBoundedConcurrency } from '../../domain/logic/attachment-autodownload-concurrency.rules';
import type { Attachment, AttachmentMeta } from '../../domain/models/attachment.model';
import type {
FileAnnouncePayload,
@@ -153,6 +154,10 @@ export class AttachmentManagerService {
return this.transfer.requestImageFromAnyPeer(messageId, attachment);
}
hasPendingRequest(messageId: string, attachmentId: string): boolean {
return this.transfer.hasPendingRequest(messageId, attachmentId);
}
async tryRestoreAttachmentFromLocal(attachment: Attachment): Promise<boolean> {
const restored = await this.persistence.tryRestoreAttachmentFromLocal(attachment);
@@ -316,33 +321,40 @@ export class AttachmentManagerService {
await this.restoreLocalAttachmentsForRoom(roomId);
if (isDirectMessageAttachmentRoomId(roomId)) {
await this.requestAutoDownloadsForRuntimeRoom(roomId);
return;
}
let messageIds: string[];
if (this.database.isReady()) {
if (isDirectMessageAttachmentRoomId(roomId)) {
messageIds = await this.collectMessageIdsForAttachmentsInRoom(roomId);
} else if (this.database.isReady()) {
const messages = await this.database.getMessages(roomId, 500, 0);
for (const message of messages) {
this.runtimeStore.rememberMessageRoom(message.id, message.roomId);
await this.requestAutoDownloadsForMessage(message.id);
}
return;
messageIds = messages.map((message) => message.id);
} else {
messageIds = await this.collectMessageIdsForAttachmentsInRoom(roomId);
}
await this.requestAutoDownloadsForRuntimeRoom(roomId);
await runTasksWithBoundedConcurrency(
messageIds.map((messageId) => () => this.requestAutoDownloadsForMessage(messageId)),
ATTACHMENT_AUTO_DOWNLOAD_CONCURRENCY
);
}
private async requestAutoDownloadsForRuntimeRoom(roomId: string): Promise<void> {
private async collectMessageIdsForAttachmentsInRoom(roomId: string): Promise<string[]> {
const messageIds: string[] = [];
for (const [messageId] of this.runtimeStore.getAttachmentEntries()) {
const attachmentRoomId = await this.persistence.resolveMessageRoomId(messageId);
if (attachmentRoomId === roomId) {
await this.requestAutoDownloadsForMessage(messageId);
messageIds.push(messageId);
}
}
return messageIds;
}
private async requestAutoDownloadsForMessage(messageId: string, attachmentId?: string): Promise<void> {