tangled
alpha
login
or
join now
flo-bit.dev
/
blento
21
fork
atom
your personal website on atproto - mirror
blento.app
21
fork
atom
overview
issues
pulls
pipelines
updated blentos
Florian
1 month ago
9cb02737
78a9cec6
+52
-19
3 changed files
expand all
collapse all
unified
split
src
lib
atproto
methods.ts
settings.ts
cards
SpecialCards
UpdatedBlentos
index.ts
+31
src/lib/atproto/methods.ts
···
101
101
return response.data;
102
102
}
103
103
104
104
+
export async function getBlentoOrBskyProfile(data: { did: Did; client?: Client }): Promise<
105
105
+
Awaited<ReturnType<typeof getDetailedProfile>> & {
106
106
+
hasBlento: boolean;
107
107
+
}
108
108
+
> {
109
109
+
let blentoProfile;
110
110
+
try {
111
111
+
// try getting blento profile first
112
112
+
blentoProfile = await getRecord({
113
113
+
collection: 'site.standard.publication',
114
114
+
did: data?.did,
115
115
+
rkey: 'blento.self',
116
116
+
client: data?.client
117
117
+
});
118
118
+
} catch {
119
119
+
console.error('error getting blento profile, falling back to bsky profile');
120
120
+
}
121
121
+
122
122
+
const response = await getDetailedProfile(data);
123
123
+
124
124
+
return {
125
125
+
did: data.did,
126
126
+
handle: response?.handle,
127
127
+
displayName: blentoProfile?.value?.name || response?.displayName || response?.handle,
128
128
+
avatar: (getCDNImageBlobUrl({ did: data?.did, blob: blentoProfile?.value?.icon }) ||
129
129
+
response?.avatar) as `${string}:${string}`,
130
130
+
hasBlento: Boolean(blentoProfile.value)
131
131
+
};
132
132
+
}
133
133
+
104
134
/**
105
135
* Creates an AT Protocol client for a user's PDS.
106
136
* @param did - The DID of the user
···
370
400
};
371
401
};
372
402
}) {
403
403
+
if (!blob || !did) return;
373
404
did ??= user.did;
374
405
375
406
return `https://cdn.bsky.app/img/feed_thumbnail/plain/${did}/${blob.ref.$link}@webp`;
+1
-1
src/lib/atproto/settings.ts
···
20
20
'app.blento.settings',
21
21
'app.blento.comment',
22
22
'app.blento.guestbook.entry',
23
23
-
'app.bsky.feed.post',
23
23
+
'app.bsky.feed.post?action=create',
24
24
'site.standard.publication',
25
25
'site.standard.document',
26
26
'xyz.statusphere.status'
+20
-18
src/lib/cards/SpecialCards/UpdatedBlentos/index.ts
···
1
1
-
import { getDetailedProfile } from '$lib/atproto';
2
1
import type { CardDefinition } from '../../types';
3
2
import UpdatedBlentosCard from './UpdatedBlentosCard.svelte';
4
3
import type { Did } from '@atcute/lexicons';
5
5
-
import type { AppBskyActorDefs } from '@atcute/bluesky';
4
4
+
import { getBlentoOrBskyProfile } from '$lib/atproto/methods';
5
5
+
6
6
+
type ProfileWithBlentoFlag = Awaited<ReturnType<typeof getBlentoOrBskyProfile>>;
6
7
7
8
export const UpdatedBlentosCardDefitition = {
8
9
type: 'updatedBlentos',
···
14
15
);
15
16
const recentRecords = await response.json();
16
17
const existingUsers = await cache?.get('updatedBlentos');
17
17
-
const existingUsersArray: AppBskyActorDefs.ProfileViewDetailed[] = existingUsers
18
18
+
const existingUsersArray: ProfileWithBlentoFlag[] = existingUsers
18
19
? JSON.parse(existingUsers)
19
20
: [];
20
21
21
21
-
const existingUsersSet = new Set(existingUsersArray.map((v) => v.did));
22
22
+
const uniqueDids = new Set<Did>(recentRecords.map((v: { did: string }) => v.did as Did));
22
23
23
23
-
const uniqueDids = new Set<Did>();
24
24
-
for (const record of recentRecords as { did: string }[]) {
25
25
-
if (!existingUsersSet.has(record.did as Did)) uniqueDids.add(record.did as Did);
26
26
-
}
27
27
-
28
28
-
const profiles: Promise<AppBskyActorDefs.ProfileViewDetailed | undefined>[] = [];
24
24
+
const profiles: Promise<ProfileWithBlentoFlag | undefined>[] = [];
29
25
30
26
for (const did of Array.from(uniqueDids)) {
31
31
-
const profile = getDetailedProfile({ did });
32
32
-
profiles.push(profile);
33
33
-
if (profiles.length > 30) break;
27
27
+
profiles.push(getBlentoOrBskyProfile({ did }));
34
28
}
35
29
36
30
for (let i = existingUsersArray.length - 1; i >= 0; i--) {
37
31
// if handle is handle.invalid, remove from existing users and add to profiles to refresh
38
38
-
if (existingUsersArray[i].handle === 'handle.invalid') {
32
32
+
if (
33
33
+
(existingUsersArray[i].handle === 'handle.invalid' ||
34
34
+
(!existingUsersArray[i].avatar && !existingUsersArray[i].hasBlento)) &&
35
35
+
!uniqueDids.has(existingUsersArray[i].did)
36
36
+
) {
39
37
const removed = existingUsersArray.splice(i, 1)[0];
40
40
-
profiles.push(getDetailedProfile({ did: removed.did }));
38
38
+
profiles.push(getBlentoOrBskyProfile({ did: removed.did }));
39
39
+
// if in unique dids, remove from older existing users and keep the newer one
40
40
+
// so updated profiles go first
41
41
+
} else if (uniqueDids.has(existingUsersArray[i].did)) {
42
42
+
existingUsersArray.splice(i, 1);
41
43
}
42
44
}
43
45
44
44
-
const result = [...(await Promise.all(profiles)), ...existingUsersArray].filter(
45
45
-
(v) => v && v.handle !== 'handle.invalid'
46
46
-
);
46
46
+
let result = [...(await Promise.all(profiles)), ...existingUsersArray];
47
47
+
48
48
+
result = result.filter((v) => v && v.handle !== 'handle.invalid');
47
49
48
50
if (cache) {
49
51
await cache?.put('updatedBlentos', JSON.stringify(result));