Add back unencrypted path in `StopGapWidgetDriver.sendToDevice` (#28295)

pull/28297/head
Florian Duros 2024-10-25 15:07:45 +02:00 committed by GitHub
parent da5c97f9fa
commit 7de5c84b3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 62 additions and 0 deletions

View File

@ -414,6 +414,30 @@ export class StopGapWidgetDriver extends WidgetDriver {
await client._unstable_updateDelayedEvent(delayId, action); await client._unstable_updateDelayedEvent(delayId, action);
} }
/**
* Implements {@link WidgetDriver#sendToDevice}
* Encrypted to-device events are not supported.
*/
public async sendToDevice(
eventType: string,
encrypted: boolean,
contentMap: { [userId: string]: { [deviceId: string]: object } },
): Promise<void> {
if (encrypted) throw new Error("Encrypted to-device events are not supported");
const client = MatrixClientPeg.safeGet();
await client.queueToDevice({
eventType,
batch: Object.entries(contentMap).flatMap(([userId, userContentMap]) =>
Object.entries(userContentMap).map(([deviceId, content]) => ({
userId,
deviceId,
payload: content,
})),
),
});
}
private pickRooms(roomIds?: (string | Symbols.AnyRoom)[]): Room[] { private pickRooms(roomIds?: (string | Symbols.AnyRoom)[]): Room[] {
const client = MatrixClientPeg.get(); const client = MatrixClientPeg.get();
if (!client) throw new Error("Not attached to a client"); if (!client) throw new Error("Not attached to a client");

View File

@ -170,6 +170,44 @@ describe("StopGapWidgetDriver", () => {
expect(listener).toHaveBeenCalledWith(openIdUpdate); expect(listener).toHaveBeenCalledWith(openIdUpdate);
}); });
describe("sendToDevice", () => {
const contentMap = {
"@alice:example.org": {
"*": {
hello: "alice",
},
},
"@bob:example.org": {
bobDesktop: {
hello: "bob",
},
},
};
let driver: WidgetDriver;
beforeEach(() => {
driver = mkDefaultDriver();
});
it("sends unencrypted messages", async () => {
await driver.sendToDevice("org.example.foo", false, contentMap);
expect(client.queueToDevice).toHaveBeenCalledWith({
eventType: "org.example.foo",
batch: [
{ deviceId: "*", payload: { hello: "alice" }, userId: "@alice:example.org" },
{ deviceId: "bobDesktop", payload: { hello: "bob" }, userId: "@bob:example.org" },
],
});
});
it("raises an error if encrypted", async () => {
await expect(driver.sendToDevice("org.example.foo", true, contentMap)).rejects.toThrow(
"Encrypted to-device events are not supported",
);
});
});
describe("getTurnServers", () => { describe("getTurnServers", () => {
let driver: WidgetDriver; let driver: WidgetDriver;