Skip to content

Commit

Permalink
Always include counts on post and profile views (bluesky-social#2357)
Browse files Browse the repository at this point in the history
* appview: ensure counts are set in all views, even when aggs are missing

* pds: ensure counts are set on post view in read-after-write, fix $type typo
  • Loading branch information
devinivy authored Apr 5, 2024
1 parent 692d1b2 commit 7570d31
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
16 changes: 8 additions & 8 deletions packages/bsky/src/views/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ export class Views {
cidFromBlobJson(actor.profile.banner),
)
: undefined,
followersCount: profileAggs?.followers,
followsCount: profileAggs?.follows,
postsCount: profileAggs?.posts,
followersCount: profileAggs?.followers ?? 0,
followsCount: profileAggs?.follows ?? 0,
postsCount: profileAggs?.posts ?? 0,
associated: {
lists: profileAggs?.lists,
feedgens: profileAggs?.feeds,
Expand Down Expand Up @@ -296,7 +296,7 @@ export class Views {
uri,
cid: labeler.cid.toString(),
creator,
likeCount: aggs?.likes,
likeCount: aggs?.likes ?? 0,
viewer: viewer
? {
like: viewer.like,
Expand Down Expand Up @@ -371,7 +371,7 @@ export class Views {
cidFromBlobJson(feedgen.record.avatar),
)
: undefined,
likeCount: aggs?.likes,
likeCount: aggs?.likes ?? 0,
labels,
viewer: viewer
? {
Expand Down Expand Up @@ -427,9 +427,9 @@ export class Views {
depth < 2 && post.record.embed
? this.embed(uri, post.record.embed, state, depth + 1)
: undefined,
replyCount: aggs?.replies,
repostCount: aggs?.reposts,
likeCount: aggs?.likes,
replyCount: aggs?.replies ?? 0,
repostCount: aggs?.reposts ?? 0,
likeCount: aggs?.likes ?? 0,
indexedAt: post.sortedAt.toISOString(),
viewer: viewer
? {
Expand Down
19 changes: 8 additions & 11 deletions packages/pds/src/read-after-write/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ export class LocalViewer {
return {
uri: uri.toString(),
cid: cid.toString(),
likeCount: 0, // counts presumed to be 0 directly after post creation
replyCount: 0,
repostCount: 0,
author,
record,
embed: embed ?? undefined,
Expand Down Expand Up @@ -240,9 +243,7 @@ export class LocalViewer {
const collection = new AtUri(embed.record.uri).collection
if (collection === ids.AppBskyFeedPost) {
const res = await this.appViewAgent.api.app.bsky.feed.getPosts(
{
uris: [embed.record.uri],
},
{ uris: [embed.record.uri] },
await this.serviceAuthHeaders(this.did),
)
const post = res.data.posts[0]
Expand All @@ -259,24 +260,20 @@ export class LocalViewer {
}
} else if (collection === ids.AppBskyFeedGenerator) {
const res = await this.appViewAgent.api.app.bsky.feed.getFeedGenerator(
{
feed: embed.record.uri,
},
{ feed: embed.record.uri },
await this.serviceAuthHeaders(this.did),
)
return {
$type: 'app.bsaky.feed.defs#generatorView',
$type: 'app.bsky.feed.defs#generatorView',
...res.data.view,
}
} else if (collection === ids.AppBskyGraphList) {
const res = await this.appViewAgent.api.app.bsky.graph.getList(
{
list: embed.record.uri,
},
{ list: embed.record.uri },
await this.serviceAuthHeaders(this.did),
)
return {
$type: 'app.bsaky.graph.defs#listView',
$type: 'app.bsky.graph.defs#listView',
...res.data.list,
}
}
Expand Down

0 comments on commit 7570d31

Please sign in to comment.