Skip to content

Commit 818269a

Browse files
committed
Distinguish room state and timeline events
1 parent bbff7c1 commit 818269a

File tree

6 files changed

+656
-56
lines changed

6 files changed

+656
-56
lines changed

src/ClientWidgetApi.ts

Lines changed: 262 additions & 44 deletions
Large diffs are not rendered by default.

src/driver/WidgetDriver.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ export abstract class WidgetDriver {
196196
* the client will return all the events.
197197
* @param eventType The event type to be read.
198198
* @param msgtype The msgtype of the events to be read, if applicable/defined.
199+
* @param stateKey The state key of the events to be read, if applicable/defined.
199200
* @param limit The maximum number of events to retrieve per room. Will be zero to denote "as many
200201
* as possible".
201202
* @param roomIds When null, the user's currently viewed room. Otherwise, the list of room IDs
@@ -204,6 +205,7 @@ export abstract class WidgetDriver {
204205
* Otherwise, the event ID at which only subsequent events will be returned, as many as specified
205206
* in "limit".
206207
* @returns {Promise<IRoomEvent[]>} Resolves to the room events, or an empty array.
208+
* @deprecated Clients are advised to implement {@link WidgetDriver.readRoomTimeline} instead.
207209
*/
208210
public readRoomEvents(
209211
eventType: string,
@@ -229,6 +231,7 @@ export abstract class WidgetDriver {
229231
* @param roomIds When null, the user's currently viewed room. Otherwise, the list of room IDs
230232
* to look within, possibly containing Symbols.AnyRoom to denote all known rooms.
231233
* @returns {Promise<IRoomEvent[]>} Resolves to the state events, or an empty array.
234+
* @deprecated Clients are advised to implement {@link WidgetDriver.readRoomTimeline} instead.
232235
*/
233236
public readStateEvents(
234237
eventType: string,
@@ -239,6 +242,46 @@ export abstract class WidgetDriver {
239242
return Promise.resolve([]);
240243
}
241244

245+
/**
246+
* Reads all events of the given type, and optionally `msgtype` (if applicable/defined),
247+
* the user has access to. The widget API will have already verified that the widget is
248+
* capable of receiving the events. Less events than the limit are allowed to be returned,
249+
* but not more. If `roomIds` is supplied, it may contain `Symbols.AnyRoom` to denote that
250+
* `limit` in each of the client's known rooms should be returned. When `null`, only the
251+
* room the user is currently looking at should be considered. If `since` is specified but
252+
* the event ID isn't present in the number of events fetched by the client due to `limit`,
253+
* the client will return all the events.
254+
* @param roomId The ID of the room to look within.
255+
* @param eventType The event type to be read.
256+
* @param msgtype The msgtype of the events to be read, if applicable/defined.
257+
* @param stateKey The state key of the events to be read, if applicable/defined.
258+
* @param limit The maximum number of events to retrieve per room. Will be zero to denote "as many
259+
* as possible".
260+
* @param since When null, retrieves the number of events specified by the "limit" parameter.
261+
* Otherwise, the event ID at which only subsequent events will be returned, as many as specified
262+
* in "limit".
263+
* @returns {Promise<IRoomEvent[]>} Resolves to the room events, or an empty array.
264+
*/
265+
public readRoomTimeline(
266+
roomId: string,
267+
eventType: string,
268+
msgtype: string | undefined,
269+
stateKey: string | undefined,
270+
limit: number,
271+
since: string | undefined,
272+
): Promise<IRoomEvent[]> {
273+
if (stateKey === undefined) return this.readRoomEvents(eventType, msgtype, limit, [roomId], since);
274+
else return this.readStateEvents(eventType, stateKey, limit, [roomId]);
275+
}
276+
277+
public readRoomState(
278+
roomId: string,
279+
eventType: string,
280+
stateKey: string | undefined,
281+
): Promise<IRoomEvent[]> {
282+
return Promise.resolve([]);
283+
}
284+
242285
/**
243286
* Reads all events that are related to a given event. The widget API will
244287
* have already verified that the widget is capable of receiving the event,
@@ -360,6 +403,15 @@ export abstract class WidgetDriver {
360403
throw new Error("Download file is not implemented");
361404
}
362405

406+
/**
407+
* Gets the IDs of all joined or invited rooms currently known to the
408+
* client.
409+
* @returns The room IDs.
410+
*/
411+
public getKnownRooms(): string[] {
412+
throw new Error("Querying known rooms is not implemented");
413+
}
414+
363415
/**
364416
* Expresses an error thrown by this driver in a format compatible with the Widget API.
365417
* @param error The error to handle.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2024 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+
import { IWidgetApiRequest, IWidgetApiRequestEmptyData } from "./IWidgetApiRequest";
18+
import { WidgetApiToWidgetAction } from "./WidgetApiAction";
19+
import { IWidgetApiAcknowledgeResponseData } from "./IWidgetApiResponse";
20+
21+
export interface IRoomStateSyncedActionRequest extends IWidgetApiRequest {
22+
action: WidgetApiToWidgetAction.RoomStateSynced;
23+
data: IWidgetApiRequestEmptyData;
24+
}
25+
26+
export interface IRoomStateSyncedActionResponse extends IRoomStateSyncedActionRequest {
27+
response: IWidgetApiAcknowledgeResponseData;
28+
}

src/interfaces/SendEventAction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export interface ISendEventFromWidgetActionResponse extends ISendEventFromWidget
4848
}
4949

5050
export interface ISendEventToWidgetRequestData extends IWidgetApiRequestData, IRoomEvent {
51+
block: 'timeline' | 'state';
5152
}
5253

5354
export interface ISendEventToWidgetActionRequest extends IWidgetApiRequest {

src/interfaces/WidgetApiAction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export enum WidgetApiToWidgetAction {
2626
ButtonClicked = "button_clicked",
2727
SendEvent = "send_event",
2828
SendToDevice = "send_to_device",
29+
RoomStateSynced = "room_state_synced",
2930
UpdateTurnServers = "update_turn_servers",
3031
}
3132

0 commit comments

Comments
 (0)