Skip to content

Commit c91aff3

Browse files
committed
Fix toDevice message type
1 parent 556f19f commit c91aff3

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

src/ClientWidgetApi.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ import {
109109
} from "./interfaces/DownloadFileAction";
110110
import { IThemeChangeActionRequestData } from "./interfaces/ThemeChangeAction";
111111
import { IUpdateStateToWidgetRequestData } from "./interfaces/UpdateStateAction";
112+
import { IToDeviceMessage } from "./interfaces/IToDeviceMessage";
112113

113114
/**
114115
* API handler for the client side of widgets. This raises events
@@ -1122,12 +1123,11 @@ export class ClientWidgetApi extends EventEmitter {
11221123
* able to receive the event due to permissions, rejects if the widget
11231124
* failed to handle the event.
11241125
*/
1125-
public async feedToDevice(rawEvent: IRoomEvent, encrypted: boolean): Promise<void> {
1126-
if (this.canReceiveToDeviceEvent(rawEvent.type)) {
1126+
public async feedToDevice(message: IToDeviceMessage, encrypted: boolean): Promise<void> {
1127+
if (this.canReceiveToDeviceEvent(message.type)) {
11271128
await this.transport.send<ISendToDeviceToWidgetRequestData>(
11281129
WidgetApiToWidgetAction.SendToDevice,
1129-
// it's compatible, but missing the index signature
1130-
{ ...rawEvent, encrypted } as ISendToDeviceToWidgetRequestData,
1130+
{ ...message, encrypted },
11311131
);
11321132
}
11331133
}

src/interfaces/IToDeviceMessage.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2025 The Matrix.org Foundation C.I.C.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export interface IToDeviceMessage {
18+
content: Record<string, unknown>;
19+
sender: string;
20+
type: string;
21+
}

src/interfaces/SendToDeviceAction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { IWidgetApiRequest, IWidgetApiRequestData } from "./IWidgetApiRequest";
1818
import { WidgetApiFromWidgetAction, WidgetApiToWidgetAction } from "./WidgetApiAction";
1919
import { IWidgetApiResponseData } from "./IWidgetApiResponse";
2020
import { IRoomEvent } from "./IRoomEvent";
21+
import { IToDeviceMessage } from "./IToDeviceMessage";
2122

2223
export interface ISendToDeviceFromWidgetRequestData extends IWidgetApiRequestData {
2324
type: string;
@@ -38,7 +39,7 @@ export interface ISendToDeviceFromWidgetActionResponse extends ISendToDeviceFrom
3839
response: ISendToDeviceFromWidgetResponseData;
3940
}
4041

41-
export interface ISendToDeviceToWidgetRequestData extends IWidgetApiRequestData, IRoomEvent {
42+
export interface ISendToDeviceToWidgetRequestData extends IWidgetApiRequestData, IToDeviceMessage {
4243
encrypted: boolean;
4344
}
4445

0 commit comments

Comments
 (0)