@@ -20,6 +20,8 @@ import {
2020import { Activity } from './BridgeRPC' ;
2121import DOMPurify from "dompurify" ;
2222
23+ // elecord rpc: parser - fetch and format rpc activity state events
24+
2325const EVENT_TYPE : any = "app.elecord.rpc.activity" ;
2426
2527export class ParseRoomRPC {
@@ -35,9 +37,7 @@ export class ParseRoomRPC {
3537 this . dmUserID = dmUserID ;
3638 }
3739
38- /**
39- * Fetch the current state event for the given user and room.
40- */
40+ // fetch current state event for given user, and room
4141 public async getActivity ( ) {
4242 logger . debug ( "ViewRPC: getActivity() called:" , this . dmUserID ) ;
4343
@@ -54,13 +54,11 @@ export class ParseRoomRPC {
5454 // an empty (content: {}) activity means rpc is disabled
5555 // if not, then we will return null
5656
57- // provide activity
57+ // return rpc activity
5858 return this . processEvent ( event ) ;
5959 }
6060
61- /**
62- * Callback when a new state event is received.
63- */
61+ // callback when new state event received
6462 public onActivity ( callback : ( activity : Activity ) => void ) : void {
6563 logger . debug ( "ViewRPC: 🏳️ onActivity() started:" , this . dmUserID ) ;
6664
@@ -73,7 +71,7 @@ export class ParseRoomRPC {
7371 const event = state . getStateEvents ( EVENT_TYPE , this . dmUserID ) ;
7472 const activity = this . processEvent ( event ) ;
7573
76- // provide activity
74+ // return rpc activity
7775 if ( activity ) {
7876 callback ( { ...activity } ) ;
7977 }
@@ -88,10 +86,7 @@ export class ParseRoomRPC {
8886 } ;
8987 }
9088
91- /**
92- * Get the room by roomId.
93- * @returns The Room object or undefined if the room is not found.
94- */
89+ // get room by roomId
9590 private getRoom ( ) : Room | undefined {
9691 const room : Room | null = this . client . getRoom ( this . roomId ) ;
9792 if ( ! room ) {
@@ -101,11 +96,7 @@ export class ParseRoomRPC {
10196 return room ;
10297 }
10398
104- /**
105- * Process the event and extract the activity.
106- * @param event The MatrixEvent to process.
107- * @returns The extracted Activity or null if the event is invalid.
108- */
99+ // process state event, and extract activity
109100 private processEvent ( event : MatrixEvent | null | undefined ) : Activity | null {
110101 if (
111102 event &&
@@ -124,18 +115,17 @@ export class ParseRoomRPC {
124115 // check activity status is valid
125116 if ( this . activity . status === true ) {
126117 logger . debug ( "ViewRPC: Activity status:" , this . activity . status , this . dmUserID ) ;
127-
128- // check the event was sent within the last 10.5 minutes
129- // if not, set status to false (as it's too old to be valid)
118+ // check event sent within last 10.5 minutes
130119 const now = new Date ( ) . getTime ( ) ;
131120 const sent = event . getTs ( ) ;
132121 const diff = now - sent ;
133122 if ( diff > 630000 ) {
134123 logger . warn ( "ViewRPC: ⌛ Activity status too old:" , Math . round ( diff / 60000 ) + "m" , this . dmUserID ) ;
135- // correct the invalid status
124+ // correct invalid status (too old to be valid)
136125 this . activity . status = false ;
137126 this . activity . timestamps . start = sent ;
138127 }
128+
139129 } else if ( this . activity . status === false ) {
140130 logger . debug ( "ViewRPC: Activity status:" , this . activity . status , this . dmUserID ) ;
141131 this . activity . timestamps . start = event . getTs ( ) ;
@@ -150,4 +140,3 @@ export class ParseRoomRPC {
150140 }
151141 }
152142}
153-
0 commit comments