nx: new marking API

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/807/merge
Varun Patil 2023-10-03 10:06:40 -07:00
parent 5f6897b5c9
commit b04586ba34
3 changed files with 20 additions and 14 deletions

View File

@ -965,6 +965,7 @@ export default defineComponent({
await Promise.all( await Promise.all(
Array.from(dayMap.entries()).map(async ([dayId, photos]) => { Array.from(dayMap.entries()).map(async ([dayId, photos]) => {
if (this.heads[dayId]?.day?.haslocal) { if (this.heads[dayId]?.day?.haslocal) {
nativex.processFreshServerDay(dayId, photos);
nativex.mergeDay(photos, await nativex.getLocalDay(dayId)); nativex.mergeDay(photos, await nativex.getLocalDay(dayId));
} }
}) })

View File

@ -180,9 +180,11 @@ export type NativeX = {
getSyncStatus: () => number; 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. */ /** The native interface is a global object that is injected by the native app. */

View File

@ -67,31 +67,34 @@ export function mergeDays(current: IDay[], incoming: IDay[]): IDay[] {
* Merge incoming photos into current photos. * Merge incoming photos into current photos.
* @param current Response to update * @param current Response to update
* @param incoming Incoming response * @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 // Merge local photos into remote photos
const currentAUIDs = new Map<number, IPhoto>(); const currentAUIDs = new Set<number>();
for (const photo of current) { for (const photo of current) {
currentAUIDs.set(photo.auid!, photo); currentAUIDs.add(photo.auid!);
} }
// Filter out files that are only available locally // Filter out files that are only available locally
const added: IPhoto[] = [];
for (const photo of incoming) { for (const photo of incoming) {
const serverPhoto = currentAUIDs.get(photo.auid!); if (!currentAUIDs.has(photo.auid!)) {
if (serverPhoto) { current.push(photo);
nativex.setServerId(photo.auid!, serverPhoto.fileid);
} }
current.push(photo);
added.push(photo);
} }
// Sort by epoch value // Sort by epoch value
current.sort((a, b) => (b.epoch ?? 0) - (a.epoch ?? 0)); 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);
} }
/** /**