@@ -17,7 +17,6 @@ limitations under the License.
1717*/
1818
1919import { logger } from "matrix-js-sdk/src/logger" ;
20- import { SetPresence } from "matrix-js-sdk/src/sync" ;
2120
2221import { MatrixClientPeg } from "./MatrixClientPeg" ;
2322import dis from "./dispatcher/dispatcher" ;
@@ -27,10 +26,16 @@ import { ActionPayload } from "./dispatcher/payloads";
2726// Time in ms after that a user is considered as unavailable/away
2827const UNAVAILABLE_TIME_MS = 3 * 60 * 1000 ; // 3 mins
2928
29+ enum State {
30+ Online = "online" ,
31+ Offline = "offline" ,
32+ Unavailable = "unavailable" ,
33+ }
34+
3035class Presence {
3136 private unavailableTimer : Timer | null = null ;
3237 private dispatcherRef : string | null = null ;
33- private state : SetPresence | null = null ;
38+ private state : State | null = null ;
3439
3540 /**
3641 * Start listening the user activity to evaluate his presence state.
@@ -43,7 +48,7 @@ class Presence {
4348 while ( this . unavailableTimer ) {
4449 try {
4550 await this . unavailableTimer . finished ( ) ;
46- this . setState ( SetPresence . Unavailable ) ;
51+ this . setState ( State . Unavailable ) ;
4752 } catch ( e ) {
4853 /* aborted, stop got called */
4954 }
@@ -68,13 +73,13 @@ class Presence {
6873 * Get the current presence state.
6974 * @returns {string } the presence state (see PRESENCE enum)
7075 */
71- public getState ( ) : SetPresence | null {
76+ public getState ( ) : State | null {
7277 return this . state ;
7378 }
7479
7580 private onAction = ( payload : ActionPayload ) : void => {
7681 if ( payload . action === "user_activity" ) {
77- this . setState ( SetPresence . Online ) ;
82+ this . setState ( State . Online ) ;
7883 this . unavailableTimer ?. restart ( ) ;
7984 }
8085 } ;
@@ -84,7 +89,7 @@ class Presence {
8489 * If the state has changed, the homeserver will be notified.
8590 * @param {string } newState the new presence state (see PRESENCE enum)
8691 */
87- private async setState ( newState : SetPresence ) : Promise < void > {
92+ private async setState ( newState : State ) : Promise < void > {
8893 if ( newState === this . state ) {
8994 return ;
9095 }
@@ -97,7 +102,7 @@ class Presence {
97102 }
98103
99104 try {
100- await MatrixClientPeg . safeGet ( ) . setSyncPresence ( this . state ) ;
105+ await MatrixClientPeg . safeGet ( ) . setPresence ( { presence : this . state } ) ;
101106 logger . info ( "Presence:" , newState ) ;
102107 } catch ( err ) {
103108 logger . error ( "Failed to set presence:" , err ) ;
0 commit comments