-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
406
};
407
407
408
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>();
409
411
// did -> post uris that are replies to that did
410
412
export const replyIndex = new SvelteMap<Did, SvelteSet<ResourceUri>>();
411
413
···
446
448
}
447
449
}
448
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 });
449
462
};
450
463
451
464
export const timelines = new SvelteMap<Did, SvelteSet<ResourceUri>>();
···
550
563
const uri: ResourceUri = toCanonicalUri({ did, ...commit });
551
564
if (commit.collection === 'app.bsky.feed.post') {
552
565
if (commit.operation === 'create') {
566
+
const record = commit.record as AppBskyFeedPost.Main;
553
567
const posts = [
554
568
{
555
-
record: commit.record as AppBskyFeedPost.Main,
569
+
record,
556
570
uri,
557
571
cid: commit.cid
558
572
}
559
573
];
560
-
await setRecordCache(uri, commit.record);
574
+
await setRecordCache(uri, record);
561
575
const client = clients.get(did) ?? viewClient;
562
576
const hydrated = await hydratePosts(client, did, posts, hydrateCacheFn);
563
577
if (!hydrated.ok) {
···
566
580
}
567
581
addPosts(hydrated.value.values());
568
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
+
}
569
589
} 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
-
}
590
+
deletePost(uri);
579
591
}
580
592
}
581
593
};