Skip to content

Commit

Permalink
#6579 - Vote Weights Are Reflected in Upvote Counts (#6590)
Browse files Browse the repository at this point in the history
* use weighted votes instead of reactor counts for upvotes

* use number of reactors if no weighted vote sum

* give users default 1 unit ofvote weight for comments

* give thread upvoters 1 unit of vote weight by default

* count reactors in absence of reaction weights sum
  • Loading branch information
Miaplacidus authored Feb 7, 2024
1 parent 6c81126 commit b0078f0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions packages/commonwealth/client/scripts/models/Comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class Comment<T extends IUniqueId> {
public readonly text: string;
public readonly plaintext: string;
public readonly reactions: Reaction[];
public reactionWeightsSum: number;
public readonly id: number;
public readonly createdAt: momentType.Moment;
public readonly authorChain?: string;
Expand Down Expand Up @@ -40,6 +41,7 @@ export class Comment<T extends IUniqueId> {
parent_id,
plaintext,
reactions,
reaction_weights_sum,
created_at,
deleted_at,
authorChain,
Expand Down Expand Up @@ -92,6 +94,7 @@ export class Comment<T extends IUniqueId> {
this.canvasSession = canvas_session;
this.canvasHash = canvas_hash;
this.reactions = (reactions || []).map((r) => new Reaction(r));
this.reactionWeightsSum = reaction_weights_sum;
this.rootThread = thread_id;
this.discord_meta = discord_meta;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/commonwealth/client/scripts/models/Thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export class Thread implements IUniqueId {
public readonly hasPoll: boolean;
public numberOfComments: number;
public associatedReactions: AssociatedReaction[];
public reactionWeightsSum: number;
public links: Link[];
public readonly discord_meta: any;
public readonly latestActivity: Moment;
Expand Down Expand Up @@ -200,6 +201,7 @@ export class Thread implements IUniqueId {
reactionType,
reactionTimestamps,
reactionWeights,
reaction_weights_sum,
addressesReacted,
canvasAction,
canvasSession,
Expand Down Expand Up @@ -238,6 +240,7 @@ export class Thread implements IUniqueId {
reactionType: any[]; // TODO: fix type
reactionTimestamps: string[];
reactionWeights: number[];
reaction_weights_sum: number;
version_history: any[]; // TODO: fix type
Address: any; // TODO: fix type
discord_meta?: any;
Expand Down Expand Up @@ -276,6 +279,7 @@ export class Thread implements IUniqueId {
this.links = links || [];
this.discord_meta = discord_meta;
this.versionHistory = processVersionHistory(version_history);
this.reactionWeightsSum = reaction_weights_sum;
this.associatedReactions = processAssociatedReactions(
reactions,
reactionIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const CommentReactionButton = ({
const hasReacted = !!(comment.reactions || []).find(
(x) => x?.author === activeAddress,
);
const likes = (comment.reactions || []).length;
const likes = comment.reactionWeightsSum || comment.reactions.length;

const handleVoteClick = async (e) => {
e.stopPropagation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const ViewCommentUpvotesDrawer = ({
avatarUrl: profile.avatarUrl,
address: profile.address,
updated_at: reactor?.updatedAt,
voting_weight: reactor?.calculatedVotingWeight || 0,
voting_weight: reactor?.calculatedVotingWeight || 1,
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const ViewThreadUpvotesDrawer = ({
avatarUrl: profile.avatarUrl,
address: profile.address,
updated_at: reactor?.updated_at,
voting_weight: reactor?.voting_weight || 0,
voting_weight: reactor?.voting_weight || 1,
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const ReactionButton = ({
<>
{size === 'small' ? (
<CWUpvoteSmall
voteCount={reactors.length}
voteCount={thread.reactionWeightsSum || reactors.length}
disabled={disabled}
isThreadArchived={!!thread.archivedAt}
selected={hasReacted}
Expand All @@ -133,7 +133,7 @@ export const ReactionButton = ({
<TooltipWrapper disabled={disabled} text={tooltipText}>
<CWUpvote
onClick={handleVoteClick}
voteCount={reactors.length}
voteCount={thread.reactionWeightsSum || reactors.length}
disabled={disabled}
active={hasReacted}
/>
Expand All @@ -145,7 +145,7 @@ export const ReactionButton = ({
>
<CWUpvote
onClick={handleVoteClick}
voteCount={reactors.length}
voteCount={thread.reactionWeightsSum || reactors.length}
disabled={disabled}
active={hasReacted}
/>
Expand Down

0 comments on commit b0078f0

Please sign in to comment.