Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back unencrypted path in StopGapWidgetDriver.sendToDevice #28295

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/stores/widgets/StopGapWidgetDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,30 @@ export class StopGapWidgetDriver extends WidgetDriver {
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[] {
const client = MatrixClientPeg.get();
if (!client) throw new Error("Not attached to a client");
Expand Down
38 changes: 38 additions & 0 deletions test/unit-tests/stores/widgets/StopGapWidgetDriver-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,44 @@ describe("StopGapWidgetDriver", () => {
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", () => {
let driver: WidgetDriver;

Expand Down
Loading