@@ -57,7 +57,7 @@ capability of `com.example.event` and an event type of the same name).
5757
5858The new capabilities are:
5959
60- * ` m.send.event:<event type> ` (eg: ` m.send.event:m.room.message ` ) - Used for sending room messages of
60+ * ` m.send.event:<event type> ` (eg: ` m.send.event:m.room.message ` ) - Used for sending non-state events of
6161 a given type.
6262* ` m.send.state_event:<event type> ` (eg: ` m.send.state_event:m.room.topic ` ) - Used for sending state
6363 events of a given type.
@@ -180,12 +180,12 @@ on behalf of the widget.
180180
181181In addition to being able to send events into the room, some widgets have an interest in reacting
182182to particular events that appear in the room. Using a similar approach to the sending of events,
183- a new capability matching ` m.receive.event:<event type> ` and ` m.receive.state_event:<event type> `
183+ new capabilities matching ` m.receive.event:<event type> ` and ` m.receive.state_event:<event type> `
184184are introduced, with the same formatting requirements as the ` m.send.event ` and ` m.send.state_event `
185185capabilities above (ie: ` m.receive.event:m.room.message#m.text ` ).
186186
187- For each event type requested and approved, the client sends a ` toWidget ` request with action ` event `
188- is sent to the widget with the ` data ` being the event itself. For example:
187+ For each event type requested and approved, the client sends a ` toWidget ` request with action
188+ ` send_event ` to the widget, with the ` data ` being the event itself. For example:
189189
190190``` json
191191{
@@ -220,6 +220,54 @@ unless they asked for it (and were approved), and they receive *decrypted* event
220220Note that the client should also be sending the widget any events in rooms where the widget is permitted
221221to receive events from. The exact details of these permissions are covered later in this document.
222222
223+ ## Proposal (receiving room state in a widget)
224+
225+ When a widget is approved to receive some state events, the client begins syncing all room state
226+ entries matching the capabilities in rooms where the widget is permitted to receive events. It
227+ communicates the current state by sending a ` toWidget ` request with action ` update_state ` .
228+
229+ ``` json
230+ {
231+ "api" : " toWidget" ,
232+ "widgetId" : " 20200827_WidgetExample" ,
233+ "requestid" : " generated-id-1234" ,
234+ "action" : " update_state" ,
235+ "data" : {
236+ "state" : [
237+ {
238+ "type" : " m.room.topic" ,
239+ "sender" : " @alice:example.org" ,
240+ "event_id" : " $example" ,
241+ "room_id" : " !room:example.org" ,
242+ "state_key" : " " ,
243+ "origin_server_ts" : 1574383781154 ,
244+ "content" : {
245+ "topic" : " Hello world!"
246+ },
247+ "unsigned" : {
248+ "age" : 12345
249+ }
250+ }
251+ ]
252+ }
253+ }
254+ ```
255+
256+ ` data.state ` is an array of state events representing the current values of the room state for each
257+ (` room_id ` , ` type ` , ` state_key ` ) tuple. The widget acknowledges receipt of this request with an
258+ empty ` response ` object.
259+
260+ Whenever a widget is granted the ability to receive some room state (through a capability
261+ negotiation or renegotiation), the widget may wait upon the next ` update_state ` action to know when
262+ the requested room state has finished loading. Therefore, if all new room state entries that the
263+ widget may receive are empty, the client must send an ` update_state ` action with an empty
264+ ` data.state ` array.
265+
266+ The client continues sending ` update_state ` actions whenever it observes a change in the relevant
267+ room state. Each action only has to mention the events that changed.
268+
269+ ## Proposal (reading events in a widget)
270+
223271Widgets can also read the events they were approved to receive on demand with the following ` fromWidget `
224272API action:
225273
@@ -239,9 +287,12 @@ API action:
239287
240288When a ` state_key ` is present, the client will respond with state events matching that state key. If
241289` state_key ` is instead a boolean ` true ` , the client will respond with state events of the given type
242- with any state key. For clarity, ` "state_key": "@alice:example.org" ` would return the state event with
243- the specified state key (there can only be one or zero), while ` "state_key": true ` would return any
244- state events of the type, regardless of state key.
290+ with any state key.
291+
292+ For clarity, the state events returned should * not* be understood to represent the current state of
293+ the room. Rather, they are simply events from the room's timeline that match the requested filter,
294+ and may or may not belong to the resolved room state. Multiple events may be returned, even when
295+ requesting a specific state key.
245296
246297To support the ability to read particular msgtypes, the widget can specify a ` msgtype ` in place of the
247298` state_key ` for ` m.room.message ` requests.
@@ -260,10 +311,7 @@ being able to send events. Web clients, for example, may be more able to send *e
260311about. The default assumption is that the client will send over as much as possible as an upper limit.
261312
262313The client is not required to backfill (use the ` /messages ` endpoint) to get more events for the
263- widget, and is able to return less than the requested amount of events. When returning state events,
264- the client should always return the current state event (in the client's view) rather than the history
265- of an event. For example, ` {"type":"m.room.topic", "state_key": "", "limit": 5} ` should return zero
266- or one topic events, not 5, even if the topic has changed more than once.
314+ widget, and is able to return less than the requested amount of events.
267315
268316An optional ` room_ids ` property may also be added to the ` data ` object by the widget, indicating which
269317room(s) to listen for events in. This is either an array of room IDs, undefined, or the special string
@@ -327,8 +375,8 @@ because they'll always send events to the user's currently viewed room, and the
327375without special room timeline permissions.
328376
329377There is no Widget API action exposed for listing the user's invited/joined rooms: the widget can request
330- permission to read/ receive the ` m.room.create ` state event of rooms and query that way. Clients should be
331- aware of this trick and describe the situation appropriately to users.
378+ permission to receive the ` m.room.create ` state entries of rooms and learn about them that way. Clients
379+ should be aware of this trick and describe the situation appropriately to users.
332380
333381## Alternatives
334382
0 commit comments