From b04586ba340861ff952f8bdb7eb8492b96d43205 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Tue, 3 Oct 2023 10:06:40 -0700 Subject: [PATCH] nx: new marking API Signed-off-by: Varun Patil --- src/components/Timeline.vue | 1 + src/native/api.ts | 6 ++++-- src/native/days.ts | 27 +++++++++++++++------------ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/components/Timeline.vue b/src/components/Timeline.vue index 90afea58..7dc53082 100644 --- a/src/components/Timeline.vue +++ b/src/components/Timeline.vue @@ -965,6 +965,7 @@ export default defineComponent({ await Promise.all( Array.from(dayMap.entries()).map(async ([dayId, photos]) => { if (this.heads[dayId]?.day?.haslocal) { + nativex.processFreshServerDay(dayId, photos); nativex.mergeDay(photos, await nativex.getLocalDay(dayId)); } }) diff --git a/src/native/api.ts b/src/native/api.ts index a705fe2e..3f3516c1 100644 --- a/src/native/api.ts +++ b/src/native/api.ts @@ -180,9 +180,11 @@ export type NativeX = { getSyncStatus: () => number; /** - * Set the server ID for a given AUID. + * Set if the given files have remote copies. + * @param auid List of AUIDs to set the server ID for (JSON-encoded) + * @param value Value of remote */ - setServerId: (auid: number, serverId: number) => void; + setHasRemote: (auids: string, value: boolean) => void; }; /** The native interface is a global object that is injected by the native app. */ diff --git a/src/native/days.ts b/src/native/days.ts index af9275d0..6145ff45 100644 --- a/src/native/days.ts +++ b/src/native/days.ts @@ -67,31 +67,34 @@ export function mergeDays(current: IDay[], incoming: IDay[]): IDay[] { * Merge incoming photos into current photos. * @param current Response to update * @param incoming Incoming response - * @returns added photos */ -export function mergeDay(current: IPhoto[], incoming: IPhoto[]): IPhoto[] { +export function mergeDay(current: IPhoto[], incoming: IPhoto[]): void { // Merge local photos into remote photos - const currentAUIDs = new Map(); + const currentAUIDs = new Set(); for (const photo of current) { - currentAUIDs.set(photo.auid!, photo); + currentAUIDs.add(photo.auid!); } // Filter out files that are only available locally - const added: IPhoto[] = []; for (const photo of incoming) { - const serverPhoto = currentAUIDs.get(photo.auid!); - if (serverPhoto) { - nativex.setServerId(photo.auid!, serverPhoto.fileid); + if (!currentAUIDs.has(photo.auid!)) { + current.push(photo); } - - current.push(photo); - added.push(photo); } // Sort by epoch value current.sort((a, b) => (b.epoch ?? 0) - (a.epoch ?? 0)); +} - return added; +/** + * Run internal hooks on fresh day received from server + * Does not update the passed objects in any way + * @param current Photos from day response + */ +export function processFreshServerDay(dayId: number, photos: IPhoto[]): void { + const auids = photos.map((p) => p.auid).filter((a) => !!a) as number[]; + if (!auids.length) return; + nativex.setHasRemote(JSON.stringify(auids), true); } /**