@@ -8,6 +8,7 @@ Please see LICENSE files in the repository root for full details.
8
8
*/
9
9
import React , { FunctionComponent , useEffect , useRef } from "react" ;
10
10
import { logger } from "matrix-js-sdk/src/logger" ;
11
+ import { MatrixEvent } from "matrix-js-sdk/src/matrix" ;
11
12
12
13
import dis from "../../../dispatcher/dispatcher" ;
13
14
import ICanvasEffect from "../../../effects/ICanvasEffect" ;
@@ -44,9 +45,10 @@ const EffectsOverlay: FunctionComponent<IProps> = ({ roomWidth }) => {
44
45
canvasRef . current . height = UIStore . instance . windowHeight ;
45
46
}
46
47
} ;
47
- const onAction = ( payload : { action : string } ) : void => {
48
+ const onAction = ( payload : { action : string ; event ?: MatrixEvent } ) : void => {
48
49
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 ) {
50
52
const effect = payload . action . slice ( actionPrefix . length ) ;
51
53
lazyLoadEffectModule ( effect ) . then ( ( module ) => module ?. start ( canvasRef . current ! ) ) ;
52
54
}
@@ -88,3 +90,19 @@ const EffectsOverlay: FunctionComponent<IProps> = ({ roomWidth }) => {
88
90
} ;
89
91
90
92
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