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
This commit is contained in:
parent
1f3d99c25c
commit
053b564d75
3 changed files with 11 additions and 6 deletions
|
@ -18,6 +18,7 @@ import React, { SyntheticEvent } from "react";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
|
import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
|
||||||
import { Relations, RelationsEvent } from "matrix-js-sdk/src/models/relations";
|
import { Relations, RelationsEvent } from "matrix-js-sdk/src/models/relations";
|
||||||
|
import { uniqBy } from "lodash";
|
||||||
|
|
||||||
import { _t } from "../../../languageHandler";
|
import { _t } from "../../../languageHandler";
|
||||||
import { isContentActionable } from "../../../utils/EventUtils";
|
import { isContentActionable } from "../../../utils/EventUtils";
|
||||||
|
@ -177,6 +178,10 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
|
||||||
if (!count) {
|
if (!count) {
|
||||||
return null;
|
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) => {
|
const myReactionEvent = myReactions?.find((mxEvent) => {
|
||||||
if (mxEvent.isRedacted()) {
|
if (mxEvent.isRedacted()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -187,9 +192,9 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
|
||||||
<ReactionsRowButton
|
<ReactionsRowButton
|
||||||
key={content}
|
key={content}
|
||||||
content={content}
|
content={content}
|
||||||
count={count}
|
count={deduplicatedEvents.length}
|
||||||
mxEvent={mxEvent}
|
mxEvent={mxEvent}
|
||||||
reactionEvents={events}
|
reactionEvents={deduplicatedEvents}
|
||||||
myReactionEvent={myReactionEvent}
|
myReactionEvent={myReactionEvent}
|
||||||
disabled={
|
disabled={
|
||||||
!this.context.canReact ||
|
!this.context.canReact ||
|
||||||
|
|
|
@ -31,8 +31,8 @@ interface IProps {
|
||||||
content: string;
|
content: string;
|
||||||
// The count of votes for this key
|
// The count of votes for this key
|
||||||
count: number;
|
count: number;
|
||||||
// A Set of Matrix reaction events for this key
|
// A list of Matrix reaction events for this key
|
||||||
reactionEvents: Set<MatrixEvent>;
|
reactionEvents: MatrixEvent[];
|
||||||
// A possible Matrix event if the current user has voted for this type
|
// A possible Matrix event if the current user has voted for this type
|
||||||
myReactionEvent?: MatrixEvent;
|
myReactionEvent?: MatrixEvent;
|
||||||
// Whether to prevent quick-reactions by clicking on this reaction
|
// Whether to prevent quick-reactions by clicking on this reaction
|
||||||
|
|
|
@ -27,8 +27,8 @@ interface IProps {
|
||||||
mxEvent: MatrixEvent;
|
mxEvent: MatrixEvent;
|
||||||
// The reaction content / key / emoji
|
// The reaction content / key / emoji
|
||||||
content: string;
|
content: string;
|
||||||
// A Set of Matrix reaction events for this key
|
// A list of Matrix reaction events for this key
|
||||||
reactionEvents: Set<MatrixEvent>;
|
reactionEvents: MatrixEvent[];
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue