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

Commit 053b564

Browse files
authored
De-duplicate reactions by sender to account for faulty/malicious servers (#11340)
* De-duplicate reactions by sender to account for faulty/malicious servers * Fix copyrights
1 parent 1f3d99c commit 053b564

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/components/views/messages/ReactionsRow.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import React, { SyntheticEvent } from "react";
1818
import classNames from "classnames";
1919
import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
2020
import { Relations, RelationsEvent } from "matrix-js-sdk/src/models/relations";
21+
import { uniqBy } from "lodash";
2122

2223
import { _t } from "../../../languageHandler";
2324
import { isContentActionable } from "../../../utils/EventUtils";
@@ -177,6 +178,10 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
177178
if (!count) {
178179
return null;
179180
}
181+
// Deduplicate the events as per the spec https://spec.matrix.org/v1.7/client-server-api/#annotations-client-behaviour
182+
// This isn't done by the underlying data model as applications may still need access to the whole list of events
183+
// for moderation purposes.
184+
const deduplicatedEvents = uniqBy([...events], (e) => e.getSender());
180185
const myReactionEvent = myReactions?.find((mxEvent) => {
181186
if (mxEvent.isRedacted()) {
182187
return false;
@@ -187,9 +192,9 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
187192
<ReactionsRowButton
188193
key={content}
189194
content={content}
190-
count={count}
195+
count={deduplicatedEvents.length}
191196
mxEvent={mxEvent}
192-
reactionEvents={events}
197+
reactionEvents={deduplicatedEvents}
193198
myReactionEvent={myReactionEvent}
194199
disabled={
195200
!this.context.canReact ||

src/components/views/messages/ReactionsRowButton.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ interface IProps {
3131
content: string;
3232
// The count of votes for this key
3333
count: number;
34-
// A Set of Matrix reaction events for this key
35-
reactionEvents: Set<MatrixEvent>;
34+
// A list of Matrix reaction events for this key
35+
reactionEvents: MatrixEvent[];
3636
// A possible Matrix event if the current user has voted for this type
3737
myReactionEvent?: MatrixEvent;
3838
// Whether to prevent quick-reactions by clicking on this reaction

src/components/views/messages/ReactionsRowButtonTooltip.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ interface IProps {
2727
mxEvent: MatrixEvent;
2828
// The reaction content / key / emoji
2929
content: string;
30-
// A Set of Matrix reaction events for this key
31-
reactionEvents: Set<MatrixEvent>;
30+
// A list of Matrix reaction events for this key
31+
reactionEvents: MatrixEvent[];
3232
visible: boolean;
3333
}
3434

0 commit comments

Comments
 (0)