parent
5f6897b5c9
commit
b04586ba34
|
@ -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));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -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. */
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue