From 7ebc98633ac4f4b0846fab5b60e7615afd01d144 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sun, 14 Jan 2024 12:33:40 +0000 Subject: [PATCH] Desktop: Fixes existing attachments not being shared in some cases with Joplin Server --- packages/lib/models/Folder.sharing.test.ts | 3 +++ packages/lib/models/Folder.ts | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/lib/models/Folder.sharing.test.ts b/packages/lib/models/Folder.sharing.test.ts index 7bf34f4b0..e6b3e3ac0 100644 --- a/packages/lib/models/Folder.sharing.test.ts +++ b/packages/lib/models/Folder.sharing.test.ts @@ -311,11 +311,14 @@ describe('models/Folder.sharing', () => { expect(resource.share_id).toBe(''); } + const previousBlobUpdatedTime = (await Resource.load(resourceId)).blob_updated_time; + await msleep(1); await Folder.updateAllShareIds(resourceService); { const resource: ResourceEntity = await Resource.load(resourceId); expect(resource.share_id).toBe(note1.share_id); + expect(resource.blob_updated_time).toBeGreaterThan(previousBlobUpdatedTime); } await Note.save({ id: note1.id, parent_id: folder2.id }); diff --git a/packages/lib/models/Folder.ts b/packages/lib/models/Folder.ts index b20a99903..74da28bee 100644 --- a/packages/lib/models/Folder.ts +++ b/packages/lib/models/Folder.ts @@ -417,6 +417,7 @@ export default class Folder extends BaseItem { share_id: string; is_shared: number; resource_is_shared: number; + resource_share_id: string; } for (let i = 0; i < 5; i++) { @@ -426,7 +427,12 @@ export default class Folder extends BaseItem { // same time we also process the is_shared property. const rows = (await this.db().selectAll(` - SELECT r.id, n.share_id, n.is_shared, r.is_shared as resource_is_shared + SELECT + r.id, + n.share_id, + n.is_shared, + r.is_shared as resource_is_shared, + r.share_id as resource_share_id FROM note_resources nr LEFT JOIN resources r ON nr.resource_id = r.id LEFT JOIN notes n ON nr.note_id = n.id @@ -513,7 +519,15 @@ export default class Folder extends BaseItem { updated_time: now, }; - if (row.is_shared !== row.resource_is_shared) { + // When a resource becomes published or shared, we set + // `blob_updated_time` to ensure that the resource content + // is uploaded too during the next sync operation. + // + // This is necessary because Joplin Server needs to + // associate `share_id` or `is_shared` with the resource + // content for sharing to work. Otherwise the share + // recipient will only get the resource metadata. + if (row.is_shared !== row.resource_is_shared || row.share_id !== row.resource_share_id) { resource.blob_updated_time = now; }