fix: Restore chat attachments after reload

Wait for persisted attachment metadata before serving or advertising files so reconnecting peers can load images and downloads reliably.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-14 10:29:37 +02:00
co-authored by Cursor
parent d3d22846e7
commit 41ebaf2407
5 changed files with 131 additions and 5 deletions
@@ -61,8 +61,11 @@ export class AttachmentManagerService {
void this.persistence.initFromDatabase().then(async () => {
if (this.watchedRoomId) {
await this.restoreLocalAttachmentsForRoom(this.watchedRoomId);
await this.announceHostedAttachments();
}
// Announce regardless of the current route - a reloaded uploader
// sitting on the dashboard still hosts its persisted files.
await this.announceHostedAttachments();
});
}
});
@@ -88,12 +91,19 @@ export class AttachmentManagerService {
this.webrtc.onPeerConnected.subscribe(() => {
if (this.watchedRoomId) {
void this.restoreLocalAttachmentsForRoom(this.watchedRoomId).then(async () => {
const watchedRoomId = this.watchedRoomId;
void this.restoreLocalAttachmentsForRoom(watchedRoomId).then(async () => {
await this.announceHostedAttachments();
});
void this.requestAutoDownloadsForRoom(this.watchedRoomId);
void this.requestAutoDownloadsForRoom(watchedRoomId);
return;
}
// No room open (e.g. reloaded onto the dashboard) - still announce
// persisted files so peers relearn this device hosts them.
void this.announceHostedAttachments();
});
}