personal web client for Bluesky
typescript solidjs bluesky atcute
at trunk 3.0 kB view raw
1import type { AppBskyActorDefs, AppBskyFeedDefs } from '@atcute/bluesky'; 2import type { Did } from '@atcute/lexicons'; 3import type { InfiniteData } from '@mary/solid-query'; 4 5import type { CacheMatcher } from '../cache/utils'; 6import type { TimelinePage } from '../queries/timeline'; 7import { embedViewRecordToPostView, getEmbeddedPost } from '../utils/post'; 8 9export const findAllPosts = (uri: string, includeQuote = false): CacheMatcher<AppBskyFeedDefs.PostView> => { 10 return { 11 filter: { 12 queryKey: ['timeline'], 13 }, 14 *iterate(data: InfiniteData<TimelinePage>) { 15 for (const page of data.pages) { 16 for (const item of page.items) { 17 const post = item.post; 18 const reply = item.reply; 19 20 if (post.uri === uri) { 21 yield post; 22 } 23 24 if (includeQuote) { 25 const embeddedPost = getEmbeddedPost(post.embed); 26 if (embeddedPost && embeddedPost.uri === uri) { 27 yield embedViewRecordToPostView(embeddedPost); 28 } 29 } 30 31 if (reply !== undefined) { 32 const parent = reply.parent; 33 const root = reply.root; 34 35 if (parent !== undefined) { 36 if (parent.uri === uri) { 37 yield parent; 38 } 39 40 if (includeQuote) { 41 const embeddedPost = getEmbeddedPost(parent.embed); 42 if (embeddedPost && embeddedPost.uri === uri) { 43 yield embedViewRecordToPostView(embeddedPost); 44 } 45 } 46 } 47 48 if (root !== undefined) { 49 if (root.uri === uri) { 50 yield root; 51 } 52 53 if (includeQuote) { 54 const embeddedPost = getEmbeddedPost(root.embed); 55 if (embeddedPost && embeddedPost.uri === uri) { 56 yield embedViewRecordToPostView(embeddedPost); 57 } 58 } 59 } 60 } 61 } 62 } 63 }, 64 }; 65}; 66 67export const findAllProfiles = (did: Did): CacheMatcher<AppBskyActorDefs.ProfileViewBasic> => { 68 return { 69 filter: { 70 queryKey: ['timeline'], 71 }, 72 *iterate(data: InfiniteData<TimelinePage>) { 73 for (const page of data.pages) { 74 for (const item of page.items) { 75 const post = item.post; 76 const reply = item.reply; 77 78 { 79 if (post.author.did === did) { 80 yield post.author; 81 } 82 83 const embeddedPost = getEmbeddedPost(post.embed); 84 if (embeddedPost && embeddedPost.author.did === did) { 85 yield embeddedPost.author; 86 } 87 } 88 89 if (reply !== undefined) { 90 const parent = reply.parent; 91 const root = reply.root; 92 93 if (parent !== undefined) { 94 if (parent.author.did === did) { 95 yield parent.author; 96 } 97 98 const embeddedPost = getEmbeddedPost(parent.embed); 99 if (embeddedPost && embeddedPost.author.did === did) { 100 yield embeddedPost.author; 101 } 102 } 103 104 if (root !== undefined) { 105 if (root.author.did === did) { 106 yield root.author; 107 } 108 109 const embeddedPost = getEmbeddedPost(root.embed); 110 if (embeddedPost && embeddedPost.author.did === did) { 111 yield embeddedPost.author; 112 } 113 } 114 } 115 } 116 } 117 }, 118 }; 119};