Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 7 additions & 7 deletions src/ClientWidgetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ import {
} from "./interfaces/DownloadFileAction";
import { IThemeChangeActionRequestData } from "./interfaces/ThemeChangeAction";
import { IUpdateStateToWidgetRequestData } from "./interfaces/UpdateStateAction";
import { IToDeviceMessage } from "./interfaces/IToDeviceMessage";

/**
* API handler for the client side of widgets. This raises events
Expand Down Expand Up @@ -1122,13 +1123,12 @@ export class ClientWidgetApi extends EventEmitter {
* able to receive the event due to permissions, rejects if the widget
* failed to handle the event.
*/
public async feedToDevice(rawEvent: IRoomEvent, encrypted: boolean): Promise<void> {
if (this.canReceiveToDeviceEvent(rawEvent.type)) {
await this.transport.send<ISendToDeviceToWidgetRequestData>(
WidgetApiToWidgetAction.SendToDevice,
// it's compatible, but missing the index signature
{ ...rawEvent, encrypted } as ISendToDeviceToWidgetRequestData,
);
public async feedToDevice(message: IToDeviceMessage, encrypted: boolean): Promise<void> {
if (this.canReceiveToDeviceEvent(message.type)) {
await this.transport.send<ISendToDeviceToWidgetRequestData>(WidgetApiToWidgetAction.SendToDevice, {
...message,
encrypted,
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IRoomAccountData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
export interface IRoomAccountData {
type: string;
room_id: string; // eslint-disable-line camelcase
content: unknown;
content: Record<string, unknown>;
}
4 changes: 2 additions & 2 deletions src/interfaces/IRoomEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export interface IRoomEvent {
room_id: string; // eslint-disable-line camelcase
state_key?: string; // eslint-disable-line camelcase
origin_server_ts: number; // eslint-disable-line camelcase
content: unknown;
unsigned: unknown;
content: Record<string, unknown>;
unsigned: Record<string, unknown>;
}
21 changes: 21 additions & 0 deletions src/interfaces/IToDeviceMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2025 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export interface IToDeviceMessage {
content: Record<string, unknown>;
sender: string;
type: string;
}
4 changes: 2 additions & 2 deletions src/interfaces/SendToDeviceAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { IWidgetApiRequest, IWidgetApiRequestData } from "./IWidgetApiRequest";
import { WidgetApiFromWidgetAction, WidgetApiToWidgetAction } from "./WidgetApiAction";
import { IWidgetApiResponseData } from "./IWidgetApiResponse";
import { IRoomEvent } from "./IRoomEvent";
import { IToDeviceMessage } from "./IToDeviceMessage";

export interface ISendToDeviceFromWidgetRequestData extends IWidgetApiRequestData {
type: string;
Expand All @@ -38,7 +38,7 @@ export interface ISendToDeviceFromWidgetActionResponse extends ISendToDeviceFrom
response: ISendToDeviceFromWidgetResponseData;
}

export interface ISendToDeviceToWidgetRequestData extends IWidgetApiRequestData, IRoomEvent {
export interface ISendToDeviceToWidgetRequestData extends IWidgetApiRequestData, IToDeviceMessage {
encrypted: boolean;
}

Expand Down