mirror of
https://github.com/vector-im/element-web.git
synced 2025-11-28 14:01:16 +01:00
Widgets: Use the new ClientEvent.ReceivedToDeviceMessage instead of ToDeviceEvent (#30239)
This commit is contained in:
parent
366eeb7d61
commit
2d92b73e5f
@ -13,6 +13,7 @@ import {
|
||||
type MatrixClient,
|
||||
ClientEvent,
|
||||
RoomStateEvent,
|
||||
type ReceivedToDeviceMessage,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import {
|
||||
@ -360,7 +361,7 @@ export class StopGapWidget extends EventEmitter {
|
||||
this.client.on(ClientEvent.Event, this.onEvent);
|
||||
this.client.on(MatrixEventEvent.Decrypted, this.onEventDecrypted);
|
||||
this.client.on(RoomStateEvent.Events, this.onStateUpdate);
|
||||
this.client.on(ClientEvent.ToDeviceEvent, this.onToDeviceEvent);
|
||||
this.client.on(ClientEvent.ReceivedToDeviceMessage, this.onToDeviceMessage);
|
||||
|
||||
this.messaging.on(
|
||||
`action:${WidgetApiFromWidgetAction.UpdateAlwaysOnScreen}`,
|
||||
@ -493,7 +494,7 @@ export class StopGapWidget extends EventEmitter {
|
||||
this.client.off(ClientEvent.Event, this.onEvent);
|
||||
this.client.off(MatrixEventEvent.Decrypted, this.onEventDecrypted);
|
||||
this.client.off(RoomStateEvent.Events, this.onStateUpdate);
|
||||
this.client.off(ClientEvent.ToDeviceEvent, this.onToDeviceEvent);
|
||||
this.client.off(ClientEvent.ReceivedToDeviceMessage, this.onToDeviceMessage);
|
||||
}
|
||||
|
||||
private onEvent = (ev: MatrixEvent): void => {
|
||||
@ -513,10 +514,10 @@ export class StopGapWidget extends EventEmitter {
|
||||
});
|
||||
};
|
||||
|
||||
private onToDeviceEvent = async (ev: MatrixEvent): Promise<void> => {
|
||||
await this.client.decryptEventIfNeeded(ev);
|
||||
if (ev.isDecryptionFailure()) return;
|
||||
await this.messaging?.feedToDevice(ev.getEffectiveEvent() as IRoomEvent, ev.isEncrypted());
|
||||
private onToDeviceMessage = async (payload: ReceivedToDeviceMessage): Promise<void> => {
|
||||
const { message, encryptionInfo } = payload;
|
||||
// TODO: Update the widget API to use a proper IToDeviceMessage instead of a IRoomEvent
|
||||
await this.messaging?.feedToDevice(message as IRoomEvent, encryptionInfo != null);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -83,16 +83,42 @@ describe("StopGapWidget", () => {
|
||||
});
|
||||
|
||||
it("feeds incoming to-device messages to the widget", async () => {
|
||||
const event = mkEvent({
|
||||
event: true,
|
||||
const receivedToDevice = {
|
||||
message: {
|
||||
type: "org.example.foo",
|
||||
user: "@alice:example.org",
|
||||
content: { hello: "world" },
|
||||
sender: "@alice:example.org",
|
||||
content: {
|
||||
hello: "world",
|
||||
},
|
||||
},
|
||||
encryptionInfo: null,
|
||||
};
|
||||
|
||||
client.emit(ClientEvent.ReceivedToDeviceMessage, receivedToDevice);
|
||||
await Promise.resolve(); // flush promises
|
||||
expect(messaging.feedToDevice).toHaveBeenCalledWith(receivedToDevice.message, false);
|
||||
});
|
||||
|
||||
client.emit(ClientEvent.ToDeviceEvent, event);
|
||||
it("feeds incoming encrypted to-device messages to the widget", async () => {
|
||||
const receivedToDevice = {
|
||||
message: {
|
||||
type: "org.example.foo",
|
||||
sender: "@alice:example.org",
|
||||
content: {
|
||||
hello: "world",
|
||||
},
|
||||
},
|
||||
encryptionInfo: {
|
||||
senderVerified: false,
|
||||
sender: "@alice:example.org",
|
||||
senderCurve25519KeyBase64: "",
|
||||
senderDevice: "ABCDEFGHI",
|
||||
},
|
||||
};
|
||||
|
||||
client.emit(ClientEvent.ReceivedToDeviceMessage, receivedToDevice);
|
||||
await Promise.resolve(); // flush promises
|
||||
expect(messaging.feedToDevice).toHaveBeenCalledWith(event.getEffectiveEvent(), false);
|
||||
expect(messaging.feedToDevice).toHaveBeenCalledWith(receivedToDevice.message, true);
|
||||
});
|
||||
|
||||
it("feeds incoming state updates to the widget", () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user