Thread viewer for Bluesky

changed how mention notifications are loaded

Changed files
+11 -16
+11 -16
api.js
··· 278 278 return await this.getRequest('app.bsky.feed.searchPosts', params); 279 279 } 280 280 281 - /** @param {string} [cursor], @returns {Promise<json>} */ 282 - 283 - async loadNotifications(cursor) { 284 - let params = { limit: 100 }; 285 - 286 - if (cursor) { 287 - params.cursor = cursor; 288 - } 281 + /** @param {json} [params], @returns {Promise<json>} */ 289 282 290 - return await this.getRequest('app.bsky.notification.listNotifications', params); 283 + async loadNotifications(params) { 284 + return await this.getRequest('app.bsky.notification.listNotifications', params || {}); 291 285 } 292 286 293 287 /** ··· 296 290 */ 297 291 298 292 async loadMentions(cursor) { 299 - let response = await this.loadNotifications(cursor); 300 - let mentions = response.notifications.filter(x => ['reply', 'mention'].includes(x.reason)); 301 - let uris = mentions.map(x => x['uri']); 302 - let posts = []; 293 + let response = await this.loadNotifications({ cursor: cursor ?? '', limit: 100, reasons: ['reply', 'mention'] }); 294 + let uris = response.notifications.map(x => x.uri); 295 + let batches = []; 303 296 304 297 for (let i = 0; i < uris.length; i += 25) { 305 - let batch = await this.loadPosts(uris.slice(i, i + 25)); 306 - posts = posts.concat(batch); 298 + let batch = this.loadPosts(uris.slice(i, i + 25)); 299 + batches.push(batch); 307 300 } 308 301 309 - return { cursor: response.cursor, posts }; 302 + let postGroups = await Promise.all(batches); 303 + 304 + return { cursor: response.cursor, posts: postGroups.flat() }; 310 305 } 311 306 312 307 /**