-1
src/components/ProfileView.svelte
-1
src/components/ProfileView.svelte
+23
-11
src/lib/state.svelte.ts
+23
-11
src/lib/state.svelte.ts
···
406
};
407
408
export const allPosts = new SvelteMap<Did, SvelteMap<ResourceUri, PostWithUri>>();
409
// did -> post uris that are replies to that did
410
export const replyIndex = new SvelteMap<Did, SvelteSet<ResourceUri>>();
411
···
446
}
447
}
448
}
449
};
450
451
export const timelines = new SvelteMap<Did, SvelteSet<ResourceUri>>();
···
550
const uri: ResourceUri = toCanonicalUri({ did, ...commit });
551
if (commit.collection === 'app.bsky.feed.post') {
552
if (commit.operation === 'create') {
553
const posts = [
554
{
555
-
record: commit.record as AppBskyFeedPost.Main,
556
uri,
557
cid: commit.cid
558
}
559
];
560
-
await setRecordCache(uri, commit.record);
561
const client = clients.get(did) ?? viewClient;
562
const hydrated = await hydratePosts(client, did, posts, hydrateCacheFn);
563
if (!hydrated.ok) {
···
566
}
567
addPosts(hydrated.value.values());
568
addTimeline(did, hydrated.value.keys());
569
} else if (commit.operation === 'delete') {
570
-
const post = allPosts.get(did)?.get(uri);
571
-
if (post) {
572
-
allPosts.get(did)?.delete(uri);
573
-
// remove from timeline
574
-
timelines.get(did)?.delete(uri);
575
-
// remove reply from index
576
-
const subjectDid = extractDidFromUri(post.record.reply?.parent.uri ?? '');
577
-
if (subjectDid) replyIndex.get(subjectDid)?.delete(uri);
578
-
}
579
}
580
}
581
};
···
406
};
407
408
export const allPosts = new SvelteMap<Did, SvelteMap<ResourceUri, PostWithUri>>();
409
+
export type DeletedPostInfo = { reply?: PostWithUri['record']['reply'] };
410
+
export const deletedPosts = new SvelteMap<ResourceUri, DeletedPostInfo>();
411
// did -> post uris that are replies to that did
412
export const replyIndex = new SvelteMap<Did, SvelteSet<ResourceUri>>();
413
···
448
}
449
}
450
}
451
+
};
452
+
453
+
export const deletePost = (uri: ResourceUri) => {
454
+
const did = extractDidFromUri(uri)!;
455
+
const post = allPosts.get(did)?.get(uri);
456
+
if (!post) return;
457
+
allPosts.get(did)?.delete(uri);
458
+
// remove reply from index
459
+
const subjectDid = extractDidFromUri(post.record.reply?.parent.uri ?? '');
460
+
if (subjectDid) replyIndex.get(subjectDid)?.delete(uri);
461
+
deletedPosts.set(uri, { reply: post.record.reply });
462
};
463
464
export const timelines = new SvelteMap<Did, SvelteSet<ResourceUri>>();
···
563
const uri: ResourceUri = toCanonicalUri({ did, ...commit });
564
if (commit.collection === 'app.bsky.feed.post') {
565
if (commit.operation === 'create') {
566
+
const record = commit.record as AppBskyFeedPost.Main;
567
const posts = [
568
{
569
+
record,
570
uri,
571
cid: commit.cid
572
}
573
];
574
+
await setRecordCache(uri, record);
575
const client = clients.get(did) ?? viewClient;
576
const hydrated = await hydratePosts(client, did, posts, hydrateCacheFn);
577
if (!hydrated.ok) {
···
580
}
581
addPosts(hydrated.value.values());
582
addTimeline(did, hydrated.value.keys());
583
+
if (record.reply) {
584
+
const parentDid = extractDidFromUri(record.reply.parent.uri)!;
585
+
addTimeline(parentDid, [uri]);
586
+
// const rootDid = extractDidFromUri(record.reply.root.uri)!;
587
+
// addTimeline(rootDid, [uri]);
588
+
}
589
} else if (commit.operation === 'delete') {
590
+
deletePost(uri);
591
}
592
}
593
};