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

Commit 9dc83b0

Browse files
committed
Ignore effect later than 48h
1 parent c24661f commit 9dc83b0

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/components/structures/RoomView.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
13641364
if (containsEmoji(ev.getContent(), effect.emojis) || ev.getContent().msgtype === effect.msgType) {
13651365
// For initial threads launch, chat effects are disabled see #19731
13661366
if (!ev.isRelation(THREAD_RELATION_TYPE.name)) {
1367-
dis.dispatch({ action: `effects.${effect.command}` });
1367+
dis.dispatch({ action: `effects.${effect.command}`, event: ev });
13681368
}
13691369
}
13701370
});

src/components/views/elements/EffectsOverlay.tsx

+20-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Please see LICENSE files in the repository root for full details.
88
*/
99
import React, { FunctionComponent, useEffect, useRef } from "react";
1010
import { logger } from "matrix-js-sdk/src/logger";
11+
import { MatrixEvent } from "matrix-js-sdk/src/matrix";
1112

1213
import dis from "../../../dispatcher/dispatcher";
1314
import ICanvasEffect from "../../../effects/ICanvasEffect";
@@ -44,9 +45,10 @@ const EffectsOverlay: FunctionComponent<IProps> = ({ roomWidth }) => {
4445
canvasRef.current.height = UIStore.instance.windowHeight;
4546
}
4647
};
47-
const onAction = (payload: { action: string }): void => {
48+
const onAction = (payload: { action: string; event?: MatrixEvent }): void => {
4849
const actionPrefix = "effects.";
49-
if (canvasRef.current && payload.action.startsWith(actionPrefix)) {
50+
const isOutdated = isEventOutdated(payload.event);
51+
if (canvasRef.current && payload.action.startsWith(actionPrefix) && !isOutdated) {
5052
const effect = payload.action.slice(actionPrefix.length);
5153
lazyLoadEffectModule(effect).then((module) => module?.start(canvasRef.current!));
5254
}
@@ -88,3 +90,19 @@ const EffectsOverlay: FunctionComponent<IProps> = ({ roomWidth }) => {
8890
};
8991

9092
export default EffectsOverlay;
93+
94+
// 48 hours
95+
// 48h * 60m * 60s * 1000ms
96+
const OUTDATED_EVENT_THRESHOLD = 48 * 60 * 60 * 1000;
97+
98+
/**
99+
* Return true if the event is older than 48h.
100+
* @param event
101+
*/
102+
function isEventOutdated(event?: MatrixEvent): boolean {
103+
if (!event) return false;
104+
105+
const nowTs = Date.now();
106+
const eventTs = event.getTs();
107+
return nowTs - eventTs > OUTDATED_EVENT_THRESHOLD;
108+
}

0 commit comments

Comments
 (0)