From 522465829741fbd7b9923bb3bdd01084feb6885c Mon Sep 17 00:00:00 2001 From: thecodrr Date: Thu, 21 Oct 2021 10:16:24 +0500 Subject: [PATCH] feat: send groupId with attachment progress events --- packages/core/api/sync/index.js | 5 ++--- packages/core/collections/attachments.js | 4 ++-- packages/core/common.js | 3 ++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/core/api/sync/index.js b/packages/core/api/sync/index.js index 1d283ec05..cbafe9f70 100644 --- a/packages/core/api/sync/index.js +++ b/packages/core/api/sync/index.js @@ -154,10 +154,9 @@ export default class Sync { try { console.log("Uploading attachments", this._db.attachments.pending); for (var i = 0; i < attachments.length; ++i) { - sendAttachmentsProgressEvent("upload", attachments.length, i); - const attachment = attachments[i]; const { hash } = attachment.metadata; + sendAttachmentsProgressEvent("upload", hash, attachments.length, i); const isUploaded = await this._db.fs.uploadFile(hash, hash); if (!isUploaded) throw new Error("Failed to upload file."); @@ -167,7 +166,7 @@ export default class Sync { } catch (e) { throw new Error("Failed to upload attachments. Error: " + e.message); } finally { - sendAttachmentsProgressEvent("upload", attachments.length); + sendAttachmentsProgressEvent("upload", null, attachments.length); } } } diff --git a/packages/core/collections/attachments.js b/packages/core/collections/attachments.js index 4f3c0cd28..c2990511d 100644 --- a/packages/core/collections/attachments.js +++ b/packages/core/collections/attachments.js @@ -186,7 +186,7 @@ export default class Attachments extends Collection { } async _downloadMedia(hash, { total, current, groupId }) { - sendAttachmentsProgressEvent("download", total, current); + sendAttachmentsProgressEvent("download", groupId, total, current); try { const isDownloaded = await this._db.fs.downloadFile(groupId, hash); if (!isDownloaded) return; @@ -202,7 +202,7 @@ export default class Attachments extends Collection { return src; } finally { if (1 + current === total) - sendAttachmentsProgressEvent("download", total); + sendAttachmentsProgressEvent("download", groupId, total); } } diff --git a/packages/core/common.js b/packages/core/common.js index 29009739f..eb24f75f5 100644 --- a/packages/core/common.js +++ b/packages/core/common.js @@ -10,9 +10,10 @@ export async function sendCheckUserStatusEvent(type) { return results.some((r) => r.type === type && r.result === true); } -export function sendAttachmentsProgressEvent(type, total, current) { +export function sendAttachmentsProgressEvent(type, groupId, total, current) { EV.publish(EVENTS.attachmentsLoading, { type, + groupId, total, current: current === undefined ? total : current, });