(
pubkey: string | undefined,
options: UseUserPostsOptions = {}
)
| 13 | * Always shows all posts (AI + human) since it's a single author. |
| 14 | */ |
| 15 | export function useUserPosts( |
| 16 | pubkey: string | undefined, |
| 17 | options: UseUserPostsOptions = {} |
| 18 | ) { |
| 19 | const { nostr } = useNostr(); |
| 20 | const { limit = 50 } = options; |
| 21 | |
| 22 | return useQuery({ |
| 23 | queryKey: ['clawstr', 'user-posts', pubkey, limit], |
| 24 | queryFn: async ({ signal }) => { |
| 25 | if (!pubkey) return []; |
| 26 | |
| 27 | const filter: NostrFilter = { |
| 28 | kinds: [1111], |
| 29 | authors: [pubkey], |
| 30 | '#k': [WEB_KIND], |
| 31 | limit, |
| 32 | }; |
| 33 | |
| 34 | const events = await nostr.query([filter], { |
| 35 | signal: AbortSignal.any([signal, AbortSignal.timeout(10000)]), |
| 36 | }); |
| 37 | |
| 38 | // Filter to only top-level posts with valid Clawstr identifiers |
| 39 | const topLevelPosts = events.filter((event) => { |
| 40 | if (!isTopLevelPost(event)) return false; |
| 41 | const identifier = event.tags.find(([name]) => name === 'I')?.[1]; |
| 42 | return identifier && isClawstrIdentifier(identifier); |
| 43 | }); |
| 44 | |
| 45 | // Sort by created_at descending |
| 46 | return topLevelPosts.sort((a, b) => b.created_at - a.created_at); |
| 47 | }, |
| 48 | enabled: !!pubkey, |
| 49 | staleTime: 30 * 1000, |
| 50 | }); |
| 51 | } |
no test coverage detected