Skip to content

Commit

Permalink
Add poll answer stats to feed aggregator
Browse files Browse the repository at this point in the history
  • Loading branch information
keaysma committed Dec 15, 2024
1 parent 55baf04 commit 29fe345
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/bsky/proto/bsky.proto
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,17 @@ message GetInteractionCountsRequest {
repeated RecordRef refs = 1;
}

message PollAnswerCount {
repeated int32 count = 3;
}

message GetInteractionCountsResponse {
repeated int32 likes = 1;
repeated int32 reposts = 2;
repeated int32 replies = 3;
repeated int32 quotes = 4;
repeated int32 poll_answer_count = 5;
repeated PollAnswerCount poll_answers = 6;
}

message GetCountsForUsersRequest {
Expand Down
8 changes: 8 additions & 0 deletions packages/bsky/src/hydration/feed.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DataPlaneClient } from '../data-plane/client'
import { Record as PostRecord } from '../lexicon/types/app/bsky/feed/post'
import { Record as LikeRecord } from '../lexicon/types/app/bsky/feed/like'
import { Record as PollAnswerRecord } from '../lexicon/types/app/bsky/feed/pollAnswer'
import { Record as RepostRecord } from '../lexicon/types/app/bsky/feed/repost'
import { Record as FeedGenRecord } from '../lexicon/types/app/bsky/feed/generator'
import { Record as ThreadgateRecord } from '../lexicon/types/app/bsky/feed/threadgate'
Expand Down Expand Up @@ -37,6 +38,8 @@ export type PostAgg = {
replies: number
reposts: number
quotes: number
pollAnswerCount: number
pollAnswers: number[]
}

export type PostAggs = HydrationMap<PostAgg>
Expand All @@ -47,6 +50,9 @@ export type Likes = HydrationMap<Like>
export type Repost = RecordInfo<RepostRecord>
export type Reposts = HydrationMap<Repost>

export type PollAnswer = RecordInfo<PollAnswerRecord>
export type PollAnswers = HydrationMap<PollAnswer>

export type FeedGenAgg = {
likes: number
}
Expand Down Expand Up @@ -166,6 +172,8 @@ export class FeedHydrator {
reposts: counts.reposts[i] ?? 0,
replies: counts.replies[i] ?? 0,
quotes: counts.quotes[i] ?? 0,
pollAnswerCount: counts.pollAnswerCount[i] ?? 0,
pollAnswers: counts.pollAnswers[i]?.count ?? [],
})
}, new HydrationMap<PostAgg>())
}
Expand Down

0 comments on commit 29fe345

Please sign in to comment.