This commit is contained in:
Manav Rathi
2024-08-14 13:51:43 +05:30
parent ee5acf6a2e
commit fd1f3c6710

View File

@@ -168,7 +168,7 @@ export const userEntityDiff = async (
*
* See also, [Note: User entity keys].
*/
const entityKey = async (type: EntityType) => {
const getOrCreateEntityKeyB64 = async (type: EntityType) => {
const encryptionKeyB64 = await usersEncryptionKeyB64();
const worker = await sharedCryptoWorker();
@@ -304,9 +304,11 @@ const saveLatestUpdatedAt = (type: EntityType, value: number) =>
*
* This diff is then applied to the data we have persisted locally.
*/
export const syncPersons = async (entityKeyB64: string) => {
export const syncPersons = async () => {
const type: EntityType = "person";
const entityKeyB64 = await getOrCreateEntityKeyB64(type);
const parse = ({ id, data }: UserEntity): Person => {
const rp = RemotePerson.parse(
JSON.parse(new TextDecoder().decode(data)),
@@ -327,10 +329,12 @@ export const syncPersons = async (entityKeyB64: string) => {
const entities = await userEntityDiff(type, sinceTime, entityKeyB64);
if (entities.length == 0) break;
await applyPersonDiff(entities.map((e) => (e.data ? parse(e) : e.id)));
await applyPersonDiff(
entities.map((entity) => (entity.data ? parse(entity) : entity.id)),
);
sinceTime = entities.reduce(
(max, e) => Math.max(max, e.updatedAt),
(max, entity) => Math.max(max, entity.updatedAt),
sinceTime,
);
await saveLatestUpdatedAt(type, sinceTime);