Thread viewer for Bluesky

tweaked some use of optional types

+18 -22
+3 -7
src/api/authenticated_api.ts
··· 1 - import { BlueskyAPI } from "./bluesky_api"; 1 + import { BlueskyAPI, type TimelineFetchOptions } from "./bluesky_api"; 2 2 import { AuthError, type FetchAllOnPageLoad } from './minisky.js'; 3 3 import { Post } from '../models/posts.js'; 4 4 import { atURI, feedPostTime } from '../utils.js'; ··· 80 80 return { cursor: response.cursor, posts: postGroups.flat() }; 81 81 } 82 82 83 - async loadHomeTimeline( 84 - days: number, 85 - options: { onPageLoad?: FetchAllOnPageLoad; keepLastPage?: boolean } = {} 86 - ): Promise<json[]> { 83 + async loadHomeTimeline(days: number, options: TimelineFetchOptions = {}): Promise<json[]> { 87 84 let now = new Date(); 88 85 let timeLimit = now.getTime() - days * 86400 * 1000; 89 86 ··· 91 88 params: { limit: 100 }, 92 89 field: 'feed', 93 90 breakWhen: (x: json) => feedPostTime(x) < timeLimit, 94 - onPageLoad: options.onPageLoad, 95 - keepLastPage: options.keepLastPage 91 + ...options 96 92 }); 97 93 } 98 94
+13 -13
src/api/bluesky_api.ts
··· 43 43 | 'posts_with_media' // posts and replies, but only with images (no reposts) 44 44 | 'posts_with_video'; // posts and replies, but only with videos (no reposts) 45 45 46 + export type TimelineFetchOptions = { 47 + onPageLoad?: FetchAllOnPageLoad; 48 + keepLastPage?: boolean; 49 + } 50 + 46 51 /** 47 52 * API client for connecting to the Bluesky XRPC API (authenticated or not). 48 53 */ ··· 133 138 return json.quoteCount; 134 139 } 135 140 136 - async getQuotes(url: string, cursor: string | undefined = undefined): Promise<json> { 141 + async getQuotes(url: string, cursor?: string): Promise<json> { 137 142 let postURI: string; 138 143 139 144 if (url.startsWith('at://')) { ··· 153 158 return await this.getRequest('blue.feeds.post.getQuotes', params); 154 159 } 155 160 156 - async getHashtagFeed(hashtag: string, cursor: string | undefined = undefined): Promise<json> { 161 + async getHashtagFeed(hashtag: string, cursor?: string): Promise<json> { 157 162 let params: Record<string, any> = { q: '#' + hashtag, limit: 50, sort: 'latest' }; 158 163 159 164 if (cursor) { ··· 186 191 async loadUserTimeline( 187 192 did: string, 188 193 days: number, 189 - options: { filter: AuthorFeedFilter, onPageLoad?: FetchAllOnPageLoad, keepLastPage?: boolean } 194 + options: { filter: AuthorFeedFilter } & TimelineFetchOptions 190 195 ): Promise<json[]> { 191 196 let now = new Date(); 192 197 let timeLimit = now.getTime() - days * 86400 * 1000; 198 + let { filter, ...fetchOptions } = options; 193 199 194 200 return await this.fetchAll('app.bsky.feed.getAuthorFeed', { 195 201 params: { 196 202 actor: did, 197 - filter: options.filter, 203 + filter: filter, 198 204 limit: 100 199 205 }, 200 206 field: 'feed', 201 207 breakWhen: (x: json) => feedPostTime(x) < timeLimit, 202 - onPageLoad: options.onPageLoad, 203 - keepLastPage: options.keepLastPage 208 + ...fetchOptions 204 209 }); 205 210 } 206 211 207 - async loadListTimeline( 208 - list: string, 209 - days: number, 210 - options: { onPageLoad?: FetchAllOnPageLoad, keepLastPage?: boolean } = {} 211 - ): Promise<json[]> { 212 + async loadListTimeline(list: string, days: number, options: TimelineFetchOptions = {}): Promise<json[]> { 212 213 let now = new Date(); 213 214 let timeLimit = now.getTime() - days * 86400 * 1000; 214 215 ··· 219 220 }, 220 221 field: 'feed', 221 222 breakWhen: (x: json) => feedPostTime(x) < timeLimit, 222 - onPageLoad: options.onPageLoad, 223 - keepLastPage: options.keepLastPage 223 + ...options 224 224 }); 225 225 } 226 226
+2 -2
src/api/minisky.ts
··· 53 53 field: string; 54 54 params?: json; 55 55 breakWhen?: (obj: json) => boolean; 56 - keepLastPage?: boolean | undefined; 57 - onPageLoad?: FetchAllOnPageLoad | undefined; 56 + keepLastPage?: boolean; 57 + onPageLoad?: FetchAllOnPageLoad; 58 58 }; 59 59 60 60 export class Minisky {