Set auto on-a-call status (#34306)

* Support for reading m.call status

(well, the prefixed version)

* Abstract the details away in userStatusFromProfile

make the validate functions non-exported

* Write on on-=a-call status

* Add tests

* Move user call status logic to its own listener

* Move tests

* use vi rather than jest

* add more mocks

* call async
This commit is contained in:
David Baker
2026-07-21 14:58:00 +00:00
committed by GitHub
parent a509a32a5c
commit 8effa81ad8
10 changed files with 191 additions and 2 deletions
+27
View File
@@ -14,6 +14,7 @@ import { stubClient } from "test-utils";
import {
clearUserStatus,
fetchUserStatus,
setUserOnCall,
setUserStatus,
userStatusFromProfile,
userStatusTextWithinMaxLength,
@@ -155,4 +156,30 @@ describe("userStatus utils", () => {
expect(client.setExtendedProfileProperty).toHaveBeenCalledWith("org.matrix.msc4426.status", null);
});
});
describe("setUserOnCall", () => {
let client: MatrixClient;
beforeEach(() => {
client = stubClient();
});
it("sets the call status with the current time if onCall is true", async () => {
vi.useFakeTimers().setSystemTime(12345);
await setUserOnCall(client, true);
expect(client.setExtendedProfileProperty).toHaveBeenCalledWith("org.matrix.msc4426.call", {
call_joined_ts: 12345,
});
vi.useRealTimers();
});
it("clears the call status if onCall is false", async () => {
await setUserOnCall(client, false);
expect(client.setExtendedProfileProperty).toHaveBeenCalledWith("org.matrix.msc4426.call", null);
});
});
});
+18
View File
@@ -146,3 +146,21 @@ export function setUserStatus(client: MatrixClient, userStatus: UserStatus): Pro
export function clearUserStatus(client: MatrixClient): Promise<void> {
return client.setExtendedProfileProperty("org.matrix.msc4426.status", null);
}
/**
* Sets or clears the user's m.call status to represent that they are currently on a call or not.
* If onCall is true, the status will be set to show that they joined the call at the time when this
* function is called.
* @param client The matrix client to use
* @param onCall Whether the user is currently on a call.
*/
export function setUserOnCall(client: MatrixClient, onCall: boolean): Promise<void> {
return client.setExtendedProfileProperty(
"org.matrix.msc4426.call",
onCall
? {
call_joined_ts: Date.now(),
}
: null,
);
}