Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
De-duplicate reactions by sender to account for faulty/malicious serv…
Browse files Browse the repository at this point in the history
…ers (#11340)

* De-duplicate reactions by sender to account for faulty/malicious servers

* Fix copyrights
  • Loading branch information
t3chguy authored Jul 31, 2023
1 parent 1f3d99c commit 053b564
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/components/views/messages/ReactionsRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import React, { SyntheticEvent } from "react";
import classNames from "classnames";
import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
import { Relations, RelationsEvent } from "matrix-js-sdk/src/models/relations";
import { uniqBy } from "lodash";

import { _t } from "../../../languageHandler";
import { isContentActionable } from "../../../utils/EventUtils";
Expand Down Expand Up @@ -177,6 +178,10 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
if (!count) {
return null;
}
// Deduplicate the events as per the spec https://spec.matrix.org/v1.7/client-server-api/#annotations-client-behaviour
// This isn't done by the underlying data model as applications may still need access to the whole list of events
// for moderation purposes.
const deduplicatedEvents = uniqBy([...events], (e) => e.getSender());
const myReactionEvent = myReactions?.find((mxEvent) => {
if (mxEvent.isRedacted()) {
return false;
Expand All @@ -187,9 +192,9 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
<ReactionsRowButton
key={content}
content={content}
count={count}
count={deduplicatedEvents.length}
mxEvent={mxEvent}
reactionEvents={events}
reactionEvents={deduplicatedEvents}
myReactionEvent={myReactionEvent}
disabled={
!this.context.canReact ||
Expand Down
4 changes: 2 additions & 2 deletions src/components/views/messages/ReactionsRowButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ interface IProps {
content: string;
// The count of votes for this key
count: number;
// A Set of Matrix reaction events for this key
reactionEvents: Set<MatrixEvent>;
// A list of Matrix reaction events for this key
reactionEvents: MatrixEvent[];
// A possible Matrix event if the current user has voted for this type
myReactionEvent?: MatrixEvent;
// Whether to prevent quick-reactions by clicking on this reaction
Expand Down
4 changes: 2 additions & 2 deletions src/components/views/messages/ReactionsRowButtonTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ interface IProps {
mxEvent: MatrixEvent;
// The reaction content / key / emoji
content: string;
// A Set of Matrix reaction events for this key
reactionEvents: Set<MatrixEvent>;
// A list of Matrix reaction events for this key
reactionEvents: MatrixEvent[];
visible: boolean;
}

Expand Down

0 comments on commit 053b564

Please sign in to comment.