Skip to content

Add voteCounts override property for remote AP polls - #157

Open
julianlam wants to merge 1 commit into
masterfrom
feature/vote-counts-override
Open

Add voteCounts override property for remote AP polls#157
julianlam wants to merge 1 commit into
masterfrom
feature/vote-counts-override

Conversation

@julianlam

@julianlamjulianlam commented May 21, 2026

Copy link
Copy Markdown
Member

I am implementing ActivityPub integration into the poll plugin. While core can remix the incoming activities into a plugin-compatible polls property, there is one difference that requires a plugin change:

  • The poll plugin tracks votes based on uids (one uid, one vote).
  • ActivityPub Polls do not share voter identification data, only aggregate vote counts (e.g. Option A: 5 votes, Option B: 10 votes)

One solution is to introduce a voteCounts property in the poll hash itself which is a JSON-serialized aggregate of vote counts. This would only apply to remote polls created via AP. Local polls would not be affected.

AI summary

Introduce a read-only voteCounts property on poll objects that allows
polls created from remote ActivityPub Question activities to display
correct vote counts without requiring individual voter identity data.

When voteCounts is present as a JSON field on poll:{pollId}, all vote
counting methods short-circuit and use the stored values instead of
reading from vote sorted sets. This enables aggregate-only vote data
from remote servers to be displayed correctly.

The override shape: { total, uniqueVoters, options: [{ id, voteCount }] }

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF

Summary of changes

New method: Poll.getVoteCountsOverride(pollId) — reads the voteCounts field from the poll hash, validates the shape ({ total, options: [{
id, voteCount }] }), and returns the parsed object or null.

Five callers short-circuit when an override exists:

MethodOverride behavior
Poll.getInfoUses override.total for voteCount; sets override.uniqueVoters
loadOptionsSkips DB sorted set reads; populates option.voteCount from override.options
Poll.getOptionSkips DB reads entirely; returns optionData with override count
Poll.getVoteCountReturns override.total
Poll.getOptionVoteCountLooks up the option in override.options by ID
Poll.getVotersCountReturns override.uniqueVoters

How to set the override (from your AP code)

awaitdb.setObjectField(`poll:${pollId}`,'voteCounts',JSON.stringify({total: 42,uniqueVoters: 38,options: [{id: "opt1",voteCount: 25},{id: "opt2",voteCount: 17},],}));

Introduce a read-only voteCounts property on poll objects that allows
polls created from remote ActivityPub Question activities to display
correct vote counts without requiring individual voter identity data.
When voteCounts is present as a JSON field on poll:{pollId}, all vote
counting methods short-circuit and use the stored values instead of
reading from vote sorted sets. This enables aggregate-only vote data
from remote servers to be displayed correctly.
The override shape: { total, uniqueVoters, options: [{ id, voteCount }] }
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF
@julianlam

Copy link
Copy Markdown
MemberAuthor

I should note that this voteCounts override property is my hair-brained idea, so if it sucks, just let me know 😛

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@julianlam