@@ -55,6 +55,7 @@ import { ISetModalButtonEnabledActionRequestData } from "./interfaces/SetModalBu
5555import { ISendEventFromWidgetRequestData , ISendEventFromWidgetResponseData } from "./interfaces/SendEventAction" ;
5656import { EventDirection , WidgetEventCapability } from "./models/WidgetEventCapability" ;
5757import { INavigateActionRequestData } from "./interfaces/NavigateAction" ;
58+ import { IReadEventFromWidgetRequestData , IReadEventFromWidgetResponseData } from "./interfaces/ReadEventAction" ;
5859
5960/**
6061 * API handler for widgets. This raises events for each action
@@ -166,6 +167,18 @@ export class WidgetApi extends EventEmitter {
166167 this . requestCapability ( WidgetEventCapability . forStateEvent ( EventDirection . Receive , eventType , stateKey ) . raw ) ;
167168 }
168169
170+ /**
171+ * Requests the capability to read a given state event with optional explicit
172+ * state key. It is not guaranteed to be allowed, but will be asked for if the
173+ * negotiation has not already happened.
174+ * @param {string } eventType The state event type to ask for.
175+ * @param {string } stateKey If specified, the specific state key to request.
176+ * Otherwise all state keys will be requested.
177+ */
178+ public requestCapabilityToReadState ( eventType : string , stateKey ?: string ) {
179+ this . requestCapability ( WidgetEventCapability . forStateEvent ( EventDirection . Read , eventType , stateKey ) . raw ) ;
180+ }
181+
169182 /**
170183 * Requests the capability to send a given room event. It is not guaranteed to be
171184 * allowed, but will be asked for if the negotiation has not already happened.
@@ -184,6 +197,15 @@ export class WidgetApi extends EventEmitter {
184197 this . requestCapability ( WidgetEventCapability . forRoomEvent ( EventDirection . Receive , eventType ) . raw ) ;
185198 }
186199
200+ /**
201+ * Requests the capability to read a given room event. It is not guaranteed to be allowed,
202+ * but will be asked for if the negotiation has not already happened.
203+ * @param {string } eventType The room event type to ask for.
204+ */
205+ public requestCapabilityToReadEvent ( eventType : string ) {
206+ this . requestCapability ( WidgetEventCapability . forRoomEvent ( EventDirection . Read , eventType ) . raw ) ;
207+ }
208+
187209 /**
188210 * Requests the capability to send a given message event with optional explicit
189211 * `msgtype`. It is not guaranteed to be allowed, but will be asked for if the
@@ -206,6 +228,17 @@ export class WidgetApi extends EventEmitter {
206228 this . requestCapability ( WidgetEventCapability . forRoomMessageEvent ( EventDirection . Receive , msgtype ) . raw ) ;
207229 }
208230
231+ /**
232+ * Requests the capability to read a given message event with optional explicit
233+ * `msgtype`. It is not guaranteed to be allowed, but will be asked for if the
234+ * negotiation has not already happened.
235+ * @param {string } msgtype If specified, the specific msgtype to request.
236+ * Otherwise all message types will be requested.
237+ */
238+ public requestCapabilityToReadMessage ( msgtype ?: string ) {
239+ this . requestCapability ( WidgetEventCapability . forRoomMessageEvent ( EventDirection . Read , msgtype ) . raw ) ;
240+ }
241+
209242 /**
210243 * Requests an OpenID Connect token from the client for the currently logged in
211244 * user. This token can be validated server-side with the federation API. Note
@@ -344,6 +377,20 @@ export class WidgetApi extends EventEmitter {
344377 ) ;
345378 }
346379
380+ public readRoomEvents ( eventType : string , limit = 25 , msgtype ?: string ) : Promise < unknown > {
381+ return this . transport . send < IReadEventFromWidgetRequestData , IReadEventFromWidgetResponseData > (
382+ WidgetApiFromWidgetAction . MSC2876ReadEvents ,
383+ { type : eventType , msgtype : msgtype , limit} ,
384+ ) . then ( r => r . events ) ;
385+ }
386+
387+ public readStateEvents ( eventType : string , limit = 25 , stateKey ?: string ) : Promise < unknown > {
388+ return this . transport . send < IReadEventFromWidgetRequestData , IReadEventFromWidgetResponseData > (
389+ WidgetApiFromWidgetAction . MSC2876ReadEvents ,
390+ { type : eventType , state_key : stateKey === undefined ? true : stateKey , limit} ,
391+ ) . then ( r => r . events ) ;
392+ }
393+
347394 /**
348395 * Sets a button as disabled or enabled on the modal widget. Buttons are enabled by default.
349396 * @param {ModalButtonID } buttonId The button ID to enable/disable.
0 commit comments