Skip to content

Commit 8eedf1d

Browse files
committed
Add timeline access
1 parent b671246 commit 8eedf1d

File tree

1 file changed

+52
-7
lines changed

1 file changed

+52
-7
lines changed

proposals/2762-widget-event-receiving.md

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ have been excluded from the specification due to lack of documentation and lack
1010
implementation to influence the spec writing process.
1111

1212
This proposal aims to bring the functionality originally proposed by MSC1236 into the widget
13-
specification with the accuracy and implementation validation required by modern MSCs.
13+
specification with the accuracy and implementation validation required by modern MSCs. Additionally,
14+
this MSC explores options for widgets being able to see events/state for rooms in which they aren't
15+
operating directly. An example usecase of this is a calendar system built on top of Matrix where a
16+
calendar view might belong to a room but needs information from "calendar event rooms". The widget
17+
would therefore need to query state from these other rooms.
1418

1519
## Prerequisite background
1620

@@ -115,13 +119,18 @@ properties of `data` are required.
115119
The client is responsible for encrypting the event before sending, if required by the room. The widget
116120
should not need to be made aware of encryption or have to encrypt events.
117121

118-
If the widget did not get approved for the capability required to send the event, the client MUST
119-
send an error response (as required currently by the capabilities system for widgets). If the widget
120-
was approved, the client MUST only send the event to the room the user is currently viewing.
122+
The widget can add an additional `room_id` property to the `data` object if it would like to target
123+
a specific room. This requires that the widget be approved for sending to that room, which is dicussed
124+
later in this document.
125+
126+
If the widget did not get approved for the capability/capabilities required to send the event, the
127+
client MUST send an error response (as required currently by the capabilities system for widgets). If
128+
the widget has permission to send to the room, defaulting to whichever room the user is currently
129+
viewing, the client MUST try to send the event to that room.
121130

122131
The client SHOULD NOT modify the `type`, `state_key`, or `content` of the request unless required for
123132
encryption. The widget is responsible for producing valid events - the client MUST pass through any
124-
errors to the widget using the standard error response in the Widget API.
133+
errors, such as permission errors, to the widget using the standard error response in the Widget API.
125134

126135
For added clarity, the client picks either the `/send` or `/state` endpoint to use on the homeserver
127136
depending on the presence of a `state_key` in the request data. The client then forms a request using
@@ -201,6 +210,9 @@ established with the widget (after the widget's capabilities are negotiated). Cl
201210
to apply the same semantics as the send event capabilities: widgets don't receive `m.emote` msgtypes
202211
unless they asked for it (and were approved), and they receive *decrypted* events.
203212

213+
Note that the client should also be sending the widget any events in rooms where the widget is permitted
214+
to receive events from. The exact details of these permissions are covered later in this document.
215+
204216
Widgets can also read the events they were approved to receive on demand with the following `fromWidget`
205217
API action:
206218

@@ -238,15 +250,20 @@ can reject the request with an error.
238250

239251
The recommended maximum `limit`s are:
240252

241-
* For `m.room.member` state events, no limit.
242-
* For all other events, 25.
253+
* For `m.room.member` state events, no limit per room.
254+
* For all other events, 25 per room.
243255

244256
The client is not required to backfill (use the `/messages` endpoint) to get more events for the
245257
client, and is able to return less than the requested amount of events. When returning state events,
246258
the client should always return the current state event (in the client's view) rather than the history
247259
of an event. For example, `{"type":"m.room.topic", "state_key": "", "limit": 5}` should return zero
248260
or one topic events, not 5, even if the topic has changed more than once.
249261

262+
An optional `room_ids` property may also be added to the `data` object by the widget, indicating which
263+
room(s) to listen for events in. This is either an array of room IDs, undefined, or the special string
264+
`"*"` to denote "any room in which the widget has permission for reading that event" (covered later).
265+
When undefined, the client should send events sent in the user's currently viewed room only.
266+
250267
The client's response would look like so (note that because of how Widget API actions work, the request
251268
itself is repeated in the response - the actual response from the client is held within the `response`
252269
object):
@@ -286,6 +303,27 @@ object):
286303
The `events` array is simply the array of events requested. When no matching events are found, this
287304
array must be defined but can be empty.
288305

306+
## Proposal (accessing other rooms)
307+
308+
As mentioned earlier in this MSC, widgets are typically limited to the room in which the user is currently
309+
viewing - they cannot typically reach out into other rooms or see what other rooms are out there. This
310+
has limitations on certain kinds of widgets which rely on room structures to store data outside of a
311+
single canonical room, however.
312+
313+
To complement the send/receive event capabilities, a single capability is introduced to access the timelines
314+
of other rooms: `m.timeline:<Room ID>`. The `<Room ID>` can either be an actual room ID, or a `*` to denote
315+
all joined or invited rooms the client is able to see, current and future. The widget can limit its exposure
316+
by simply requesting highly scoped send/receive capabilities to accompany the timeline capability.
317+
318+
Do note that a widget does not need to request capabilities for all rooms if it only ever interacts with the
319+
user's currently viewed room. Widgets such as stickerpickers will not need to request timeline capabilities
320+
because they'll always send events to the user's currently viewed room, and the client will let them do that
321+
without special room timeline permissions.
322+
323+
There is no Widget API action exposed for listing the user's invited/joined rooms: the widget can request
324+
permission to read/receive the `m.room.create` state event of rooms and query that way. Clients should be
325+
aware of this trick and describe the situation appropriately to users.
326+
289327
## Alternatives
290328

291329
Widgets could be powered by a bot or some sort of backend which allows them to filter the room state
@@ -308,6 +346,13 @@ and ensure that users are prompted to explicitly approve the permissions request
308346

309347
Clients may also wish to consider putting iconography next to room messages when a widget reads them.
310348

349+
This MSC allows widgets to arbitrarily access/modify history in, at worst, all of the user's rooms.
350+
Clients should apply strict limits or checks to ensure the user understands what the widget is trying
351+
to do and isn't unreasonably accessing the user's account. For example, a large warning saying that
352+
a room-based widget is trying to access messages in *all rooms* might be suitable. Another approach
353+
might be to simply limit the number of rooms a widget can access, requiring the widget to know what
354+
room IDs it specifically wants (ie: denying the `*` request on behalf of the user).
355+
311356
## Unstable prefix
312357

313358
While this MSC is not present in the spec, clients and widgets should:

0 commit comments

Comments
 (0)