Skip to content
This repository was archived by the owner on Feb 11, 2026. It is now read-only.

Commit b987190

Browse files
committed
chore(rpc): rewrite comments for clarity
1 parent efd9ec7 commit b987190

6 files changed

Lines changed: 31 additions & 42 deletions

File tree

src/components/structures/UserRPC.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import { logger } from "matrix-js-sdk/src/logger";
1111

1212
import { BridgeRPC, Activity } from '../../elecord/rpc/BridgeRPC';
1313

14-
// elecord rpc user component - gets and displays user activity
15-
// this component starts the full rpc lifecycle
14+
// elecord rpc: user component - display local user rpc activity
15+
16+
// (starts rpc activity sender lifecycle)
1617

1718
const UserRPC: React.FC = () => {
1819
const [activity, setActivity] = useState<Activity | null | undefined>(null);
@@ -51,4 +52,3 @@ const UserRPC: React.FC = () => {
5152
};
5253

5354
export default UserRPC;
54-

src/components/views/rooms/RoomTileRPC.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,22 @@ import { MatrixClientPeg } from "../../../MatrixClientPeg";
1313
import { ParseRoomRPC } from "../../../elecord/rpc/ParseRoomRPC";
1414
import { Activity } from '../../../elecord/rpc/BridgeRPC';
1515

16-
// elecord rpc room tile component - displays user activity on dm rooms
16+
// elecord rpc: room tile component - display external user rpc activity on dm rooms
17+
18+
// (starts external user rpc activity lifecycle)
1719

1820
interface Props {
1921
roomId: string;
2022
dmUserID: string;
2123
}
2224

2325
const RoomTileRPC: FC<Props> = ({ roomId, dmUserID }) => {
24-
// State to store the activity.
26+
// state to store activity
2527
const [activity, setActivity] = useState<Activity | null | undefined>(null);
26-
// State to trigger re-renders to update the time-ago text.
28+
// state to trigger re-renders to update time-ago text
2729
const [now, setNow] = useState(Date.now());
2830

29-
// Fetch and subscribe to activity updates.
31+
// fetch and subscribe to activity updates
3032
useEffect(() => {
3133
(async () => {
3234
const client = MatrixClientPeg.safeGet();
@@ -41,7 +43,8 @@ const RoomTileRPC: FC<Props> = ({ roomId, dmUserID }) => {
4143
parseRoomRPC.cleanup();
4244
}
4345

44-
// monitor for new state events and clean up the listener when the component unmounts
46+
// monitor for new state events,
47+
// clean up listener when component unmounts
4548
parseRoomRPC.onActivity(newActivity => {
4649
logger.debug("RoomRPC: 🔦 Room state changed:", dmUserID);
4750
setActivity(newActivity);
@@ -61,26 +64,27 @@ const RoomTileRPC: FC<Props> = ({ roomId, dmUserID }) => {
6164
})();
6265
}, [roomId, dmUserID]);
6366

64-
// Self-adjusting timeout: update more frequently when activity is new,
65-
// and switch to updating every hour once it's older than an hour.
67+
// self-adjusting timeout: update more frequently when activity is new,
68+
// switch to updating every hour once it's older than an hour
6669
useEffect(() => {
6770
let timer: ReturnType<typeof setTimeout>;
6871

6972
const tick = async () => {
7073
setNow(Date.now());
7174

72-
// Default update frequency is 1 minute.
75+
// default update frequency: 1m
7376
let nextDelay = 60000;
7477
if (activity?.timestamps?.start && !activity.status) {
7578
const elapsed = Date.now() - activity.timestamps.start;
76-
// Switch to updating every hour if activity is older than one hour.
79+
// check activity older than 1h
7780
if (elapsed >= 3600000) {
81+
// update frequency: 1h
7882
nextDelay = 3600000;
7983
}
8084
}
8185
timer = setTimeout(tick, nextDelay);
8286
};
83-
// Start the cycle.
87+
// start cycle
8488
timer = setTimeout(tick, 60000);
8589

8690
return () => clearTimeout(timer);
@@ -136,4 +140,3 @@ const RoomTileRPC: FC<Props> = ({ roomId, dmUserID }) => {
136140
};
137141

138142
export default RoomTileRPC;
139-

src/elecord/rpc/BridgeRPC.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { logger } from "matrix-js-sdk/src/logger";
99

1010
import { sendActivity } from "./SendRPC";
1111

12-
// elecord rpc bridge - communicates with the local game presence websocket server
12+
// elecord rpc: bridge - communicate with local erpc websocket server
1313

1414
export type Activity = {
1515
application_id: string;
@@ -164,4 +164,3 @@ export class BridgeRPC {
164164
return this.activity;
165165
}
166166
}
167-

src/elecord/rpc/ParseRoomRPC.ts

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {
2020
import { Activity } from './BridgeRPC';
2121
import DOMPurify from "dompurify";
2222

23+
// elecord rpc: parser - fetch and format rpc activity state events
24+
2325
const EVENT_TYPE: any = "app.elecord.rpc.activity";
2426

2527
export 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-

src/elecord/rpc/RouteRPC.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { logger } from "matrix-js-sdk/src/logger";
99

1010
import DMRoomMap from "../../utils/DMRoomMap";
1111

12-
// elecord rpc route - returns routes to dm rooms for activity updates
12+
// elecord rpc: router - return routes to dm rooms
1313

1414
export async function routeActivity() {
1515

@@ -25,4 +25,3 @@ export async function routeActivity() {
2525
return dmRooms;
2626
}
2727
}
28-

src/elecord/rpc/SendRPC.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Activity } from "./BridgeRPC";
1111
import { routeActivity } from "./RouteRPC";
1212
import { MatrixClientPeg } from "../../MatrixClientPeg";
1313

14-
// elecord rpc sender - sends activity updates as room state events
14+
// elecord rpc: sender - send rpc activity state events
1515

1616
export async function sendActivity(this: any, activity: Activity, previousID: string) {
1717

@@ -54,4 +54,3 @@ export async function sendActivity(this: any, activity: Activity, previousID: st
5454
logger.info("SendRPC: 🚀 Sent activity updates");
5555
}
5656
}
57-

0 commit comments

Comments
 (0)