@@ -17,16 +17,20 @@ limitations under the License.
17
17
18
18
import React from 'react' ;
19
19
import { MatrixEvent } from "matrix-js-sdk/src/models/event" ;
20
+ import { Relations , RelationsEvent } from 'matrix-js-sdk/src/models/relations' ;
21
+ import { EventType , RelationType } from 'matrix-js-sdk/src/@types/event' ;
20
22
21
23
import EmojiPicker from "./EmojiPicker" ;
22
24
import { MatrixClientPeg } from "../../../MatrixClientPeg" ;
23
25
import dis from "../../../dispatcher/dispatcher" ;
24
26
import { replaceableComponent } from "../../../utils/replaceableComponent" ;
25
27
import { Action } from '../../../dispatcher/actions' ;
28
+ import RoomContext from "../../../contexts/RoomContext" ;
29
+ import { FocusComposerPayload } from '../../../dispatcher/payloads/FocusComposerPayload' ;
26
30
27
31
interface IProps {
28
32
mxEvent : MatrixEvent ;
29
- reactions : any ; // TODO type this once js-sdk is more typescripted
33
+ reactions ?: Relations ;
30
34
onFinished ( ) : void ;
31
35
}
32
36
@@ -36,8 +40,11 @@ interface IState {
36
40
37
41
@replaceableComponent ( "views.emojipicker.ReactionPicker" )
38
42
class ReactionPicker extends React . Component < IProps , IState > {
39
- constructor ( props ) {
40
- super ( props ) ;
43
+ static contextType = RoomContext ;
44
+ public context ! : React . ContextType < typeof RoomContext > ;
45
+
46
+ constructor ( props : IProps , context : React . ContextType < typeof RoomContext > ) {
47
+ super ( props , context ) ;
41
48
42
49
this . state = {
43
50
selectedEmojis : new Set ( Object . keys ( this . getReactions ( ) ) ) ,
@@ -54,17 +61,17 @@ class ReactionPicker extends React.Component<IProps, IState> {
54
61
55
62
private addListeners ( ) {
56
63
if ( this . props . reactions ) {
57
- this . props . reactions . on ( "Relations.add" , this . onReactionsChange ) ;
58
- this . props . reactions . on ( "Relations.remove" , this . onReactionsChange ) ;
59
- this . props . reactions . on ( "Relations.redaction" , this . onReactionsChange ) ;
64
+ this . props . reactions . on ( RelationsEvent . Add , this . onReactionsChange ) ;
65
+ this . props . reactions . on ( RelationsEvent . Remove , this . onReactionsChange ) ;
66
+ this . props . reactions . on ( RelationsEvent . Redaction , this . onReactionsChange ) ;
60
67
}
61
68
}
62
69
63
70
componentWillUnmount ( ) {
64
71
if ( this . props . reactions ) {
65
- this . props . reactions . removeListener ( "Relations.add" , this . onReactionsChange ) ;
66
- this . props . reactions . removeListener ( "Relations.remove" , this . onReactionsChange ) ;
67
- this . props . reactions . removeListener ( "Relations.redaction" , this . onReactionsChange ) ;
72
+ this . props . reactions . removeListener ( RelationsEvent . Add , this . onReactionsChange ) ;
73
+ this . props . reactions . removeListener ( RelationsEvent . Remove , this . onReactionsChange ) ;
74
+ this . props . reactions . removeListener ( RelationsEvent . Redaction , this . onReactionsChange ) ;
68
75
}
69
76
}
70
77
@@ -85,28 +92,31 @@ class ReactionPicker extends React.Component<IProps, IState> {
85
92
} ) ;
86
93
} ;
87
94
88
- onChoose = ( reaction : string ) => {
95
+ private onChoose = ( reaction : string ) => {
89
96
this . componentWillUnmount ( ) ;
90
97
this . props . onFinished ( ) ;
91
98
const myReactions = this . getReactions ( ) ;
92
99
if ( myReactions . hasOwnProperty ( reaction ) ) {
93
- MatrixClientPeg . get ( ) . redactEvent (
94
- this . props . mxEvent . getRoomId ( ) ,
95
- myReactions [ reaction ] ,
96
- ) ;
97
- dis . fire ( Action . FocusAComposer ) ;
100
+ MatrixClientPeg . get ( ) . redactEvent ( this . props . mxEvent . getRoomId ( ) , myReactions [ reaction ] ) ;
101
+ dis . dispatch < FocusComposerPayload > ( {
102
+ action : Action . FocusAComposer ,
103
+ context : this . context . timelineRenderingType ,
104
+ } ) ;
98
105
// Tell the emoji picker not to bump this in the more frequently used list.
99
106
return false ;
100
107
} else {
101
- MatrixClientPeg . get ( ) . sendEvent ( this . props . mxEvent . getRoomId ( ) , "m.reaction" , {
108
+ MatrixClientPeg . get ( ) . sendEvent ( this . props . mxEvent . getRoomId ( ) , EventType . Reaction , {
102
109
"m.relates_to" : {
103
- "rel_type" : "m.annotation" ,
110
+ "rel_type" : RelationType . Annotation ,
104
111
"event_id" : this . props . mxEvent . getId ( ) ,
105
112
"key" : reaction ,
106
113
} ,
107
114
} ) ;
108
115
dis . dispatch ( { action : "message_sent" } ) ;
109
- dis . fire ( Action . FocusAComposer ) ;
116
+ dis . dispatch < FocusComposerPayload > ( {
117
+ action : Action . FocusAComposer ,
118
+ context : this . context . timelineRenderingType ,
119
+ } ) ;
110
120
return true ;
111
121
}
112
122
} ;
0 commit comments