From 9cb0273763b0802719b44026de1140496465fb28 Mon Sep 17 00:00:00 2001 From: Florian <45694132+flo-bit@users.noreply.github.com> Date: Fri, 30 Jan 2026 18:49:31 +0100 Subject: [PATCH] updated blentos --- src/lib/atproto/methods.ts | 31 +++++++++++++++ src/lib/atproto/settings.ts | 2 +- .../SpecialCards/UpdatedBlentos/index.ts | 38 ++++++++++--------- 3 files changed, 52 insertions(+), 19 deletions(-) diff --git a/src/lib/atproto/methods.ts b/src/lib/atproto/methods.ts index a647929..7a646f1 100644 --- a/src/lib/atproto/methods.ts +++ b/src/lib/atproto/methods.ts @@ -101,6 +101,36 @@ export async function getDetailedProfile(data?: { did?: Did; client?: Client }) return response.data; } +export async function getBlentoOrBskyProfile(data: { did: Did; client?: Client }): Promise< + Awaited> & { + hasBlento: boolean; + } +> { + let blentoProfile; + try { + // try getting blento profile first + blentoProfile = await getRecord({ + collection: 'site.standard.publication', + did: data?.did, + rkey: 'blento.self', + client: data?.client + }); + } catch { + console.error('error getting blento profile, falling back to bsky profile'); + } + + const response = await getDetailedProfile(data); + + return { + did: data.did, + handle: response?.handle, + displayName: blentoProfile?.value?.name || response?.displayName || response?.handle, + avatar: (getCDNImageBlobUrl({ did: data?.did, blob: blentoProfile?.value?.icon }) || + response?.avatar) as `${string}:${string}`, + hasBlento: Boolean(blentoProfile.value) + }; +} + /** * Creates an AT Protocol client for a user's PDS. * @param did - The DID of the user @@ -370,6 +400,7 @@ export function getCDNImageBlobUrl({ }; }; }) { + if (!blob || !did) return; did ??= user.did; return `https://cdn.bsky.app/img/feed_thumbnail/plain/${did}/${blob.ref.$link}@webp`; diff --git a/src/lib/atproto/settings.ts b/src/lib/atproto/settings.ts index ead0337..a1c5a38 100644 --- a/src/lib/atproto/settings.ts +++ b/src/lib/atproto/settings.ts @@ -20,7 +20,7 @@ export const permissions = { 'app.blento.settings', 'app.blento.comment', 'app.blento.guestbook.entry', - 'app.bsky.feed.post', + 'app.bsky.feed.post?action=create', 'site.standard.publication', 'site.standard.document', 'xyz.statusphere.status' diff --git a/src/lib/cards/SpecialCards/UpdatedBlentos/index.ts b/src/lib/cards/SpecialCards/UpdatedBlentos/index.ts index 48932f0..3d57c22 100644 --- a/src/lib/cards/SpecialCards/UpdatedBlentos/index.ts +++ b/src/lib/cards/SpecialCards/UpdatedBlentos/index.ts @@ -1,8 +1,9 @@ -import { getDetailedProfile } from '$lib/atproto'; import type { CardDefinition } from '../../types'; import UpdatedBlentosCard from './UpdatedBlentosCard.svelte'; import type { Did } from '@atcute/lexicons'; -import type { AppBskyActorDefs } from '@atcute/bluesky'; +import { getBlentoOrBskyProfile } from '$lib/atproto/methods'; + +type ProfileWithBlentoFlag = Awaited>; export const UpdatedBlentosCardDefitition = { type: 'updatedBlentos', @@ -14,36 +15,37 @@ export const UpdatedBlentosCardDefitition = { ); const recentRecords = await response.json(); const existingUsers = await cache?.get('updatedBlentos'); - const existingUsersArray: AppBskyActorDefs.ProfileViewDetailed[] = existingUsers + const existingUsersArray: ProfileWithBlentoFlag[] = existingUsers ? JSON.parse(existingUsers) : []; - const existingUsersSet = new Set(existingUsersArray.map((v) => v.did)); - - const uniqueDids = new Set(); - for (const record of recentRecords as { did: string }[]) { - if (!existingUsersSet.has(record.did as Did)) uniqueDids.add(record.did as Did); - } + const uniqueDids = new Set(recentRecords.map((v: { did: string }) => v.did as Did)); - const profiles: Promise[] = []; + const profiles: Promise[] = []; for (const did of Array.from(uniqueDids)) { - const profile = getDetailedProfile({ did }); - profiles.push(profile); - if (profiles.length > 30) break; + profiles.push(getBlentoOrBskyProfile({ did })); } for (let i = existingUsersArray.length - 1; i >= 0; i--) { // if handle is handle.invalid, remove from existing users and add to profiles to refresh - if (existingUsersArray[i].handle === 'handle.invalid') { + if ( + (existingUsersArray[i].handle === 'handle.invalid' || + (!existingUsersArray[i].avatar && !existingUsersArray[i].hasBlento)) && + !uniqueDids.has(existingUsersArray[i].did) + ) { const removed = existingUsersArray.splice(i, 1)[0]; - profiles.push(getDetailedProfile({ did: removed.did })); + profiles.push(getBlentoOrBskyProfile({ did: removed.did })); + // if in unique dids, remove from older existing users and keep the newer one + // so updated profiles go first + } else if (uniqueDids.has(existingUsersArray[i].did)) { + existingUsersArray.splice(i, 1); } } - const result = [...(await Promise.all(profiles)), ...existingUsersArray].filter( - (v) => v && v.handle !== 'handle.invalid' - ); + let result = [...(await Promise.all(profiles)), ...existingUsersArray]; + + result = result.filter((v) => v && v.handle !== 'handle.invalid'); if (cache) { await cache?.put('updatedBlentos', JSON.stringify(result)); -- 2.51.2