@@ -17,7 +17,6 @@ limitations under the License.
17
17
*/
18
18
19
19
import { logger } from "matrix-js-sdk/src/logger" ;
20
- import { SetPresence } from "matrix-js-sdk/src/sync" ;
21
20
22
21
import { MatrixClientPeg } from "./MatrixClientPeg" ;
23
22
import dis from "./dispatcher/dispatcher" ;
@@ -27,10 +26,16 @@ import { ActionPayload } from "./dispatcher/payloads";
27
26
// Time in ms after that a user is considered as unavailable/away
28
27
const UNAVAILABLE_TIME_MS = 3 * 60 * 1000 ; // 3 mins
29
28
29
+ enum State {
30
+ Online = "online" ,
31
+ Offline = "offline" ,
32
+ Unavailable = "unavailable" ,
33
+ }
34
+
30
35
class Presence {
31
36
private unavailableTimer : Timer | null = null ;
32
37
private dispatcherRef : string | null = null ;
33
- private state : SetPresence | null = null ;
38
+ private state : State | null = null ;
34
39
35
40
/**
36
41
* Start listening the user activity to evaluate his presence state.
@@ -43,7 +48,7 @@ class Presence {
43
48
while ( this . unavailableTimer ) {
44
49
try {
45
50
await this . unavailableTimer . finished ( ) ;
46
- this . setState ( SetPresence . Unavailable ) ;
51
+ this . setState ( State . Unavailable ) ;
47
52
} catch ( e ) {
48
53
/* aborted, stop got called */
49
54
}
@@ -68,13 +73,13 @@ class Presence {
68
73
* Get the current presence state.
69
74
* @returns {string } the presence state (see PRESENCE enum)
70
75
*/
71
- public getState ( ) : SetPresence | null {
76
+ public getState ( ) : State | null {
72
77
return this . state ;
73
78
}
74
79
75
80
private onAction = ( payload : ActionPayload ) : void => {
76
81
if ( payload . action === "user_activity" ) {
77
- this . setState ( SetPresence . Online ) ;
82
+ this . setState ( State . Online ) ;
78
83
this . unavailableTimer ?. restart ( ) ;
79
84
}
80
85
} ;
@@ -84,7 +89,7 @@ class Presence {
84
89
* If the state has changed, the homeserver will be notified.
85
90
* @param {string } newState the new presence state (see PRESENCE enum)
86
91
*/
87
- private async setState ( newState : SetPresence ) : Promise < void > {
92
+ private async setState ( newState : State ) : Promise < void > {
88
93
if ( newState === this . state ) {
89
94
return ;
90
95
}
@@ -97,7 +102,7 @@ class Presence {
97
102
}
98
103
99
104
try {
100
- await MatrixClientPeg . safeGet ( ) . setSyncPresence ( this . state ) ;
105
+ await MatrixClientPeg . safeGet ( ) . setPresence ( { presence : this . state } ) ;
101
106
logger . info ( "Presence:" , newState ) ;
102
107
} catch ( err ) {
103
108
logger . error ( "Failed to set presence:" , err ) ;
0 commit comments