Skip to content

Commit

Permalink
Label profiles in feeds (bluesky-social#805)
Browse files Browse the repository at this point in the history
* Label profiles in feeds

* send empty array
  • Loading branch information
dholms authored Apr 12, 2023
1 parent 521c1c1 commit d6ac47d
Show file tree
Hide file tree
Showing 11 changed files with 1,334 additions and 517 deletions.
66 changes: 35 additions & 31 deletions packages/pds/src/app-view/services/feed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,37 +78,40 @@ export class FeedService {
): Promise<ActorViewMap> {
if (dids.length < 1) return {}
const { ref } = this.db.db.dynamic
const actors = await this.db.db
.selectFrom('did_handle')
.where('did_handle.did', 'in', dids)
.leftJoin('profile', 'profile.creator', 'did_handle.did')
.selectAll('did_handle')
.select([
'profile.uri as profileUri',
'profile.displayName as displayName',
'profile.description as description',
'profile.avatarCid as avatarCid',
'profile.indexedAt as indexedAt',
this.db.db
.selectFrom('follow')
.where('creator', '=', requester)
.whereRef('subjectDid', '=', ref('did_handle.did'))
.select('uri')
.as('requesterFollowing'),
this.db.db
.selectFrom('follow')
.whereRef('creator', '=', ref('did_handle.did'))
.where('subjectDid', '=', requester)
.select('uri')
.as('requesterFollowedBy'),
this.db.db
.selectFrom('mute')
.whereRef('did', '=', ref('did_handle.did'))
.where('mutedByDid', '=', requester)
.select('did')
.as('requesterMuted'),
])
.execute()
const [actors, labels] = await Promise.all([
this.db.db
.selectFrom('did_handle')
.where('did_handle.did', 'in', dids)
.leftJoin('profile', 'profile.creator', 'did_handle.did')
.selectAll('did_handle')
.select([
'profile.uri as profileUri',
'profile.displayName as displayName',
'profile.description as description',
'profile.avatarCid as avatarCid',
'profile.indexedAt as indexedAt',
this.db.db
.selectFrom('follow')
.where('creator', '=', requester)
.whereRef('subjectDid', '=', ref('did_handle.did'))
.select('uri')
.as('requesterFollowing'),
this.db.db
.selectFrom('follow')
.whereRef('creator', '=', ref('did_handle.did'))
.where('subjectDid', '=', requester)
.select('uri')
.as('requesterFollowedBy'),
this.db.db
.selectFrom('mute')
.whereRef('did', '=', ref('did_handle.did'))
.where('mutedByDid', '=', requester)
.select('did')
.as('requesterMuted'),
])
.execute(),
this.services.label(this.db).getLabelsForProfiles(dids),
])
return actors.reduce((acc, cur) => {
return {
...acc,
Expand All @@ -124,6 +127,7 @@ export class FeedService {
following: cur?.requesterFollowing || undefined,
followedBy: cur?.requesterFollowedBy || undefined,
},
labels: labels[cur.did] ?? [],
},
}
}, {} as ActorViewMap)
Expand Down
2 changes: 2 additions & 0 deletions packages/pds/tests/__snapshots__/indexing.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Object {
"did": "user(0)",
"displayName": "ali",
"handle": "alice.test",
"labels": Array [],
"viewer": Object {
"muted": false,
},
Expand Down Expand Up @@ -57,6 +58,7 @@ Object {
"did": "user(0)",
"displayName": "ali",
"handle": "alice.test",
"labels": Array [],
"viewer": Object {
"muted": false,
},
Expand Down
Loading

0 comments on commit d6ac47d

Please sign in to comment.