@matrix-widget-toolkit/api 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +148 -0
- package/build/cjs/index.js +1651 -0
- package/build/esm/index.js +1620 -0
- package/build/index.d.ts +959 -0
- package/package.json +48 -0
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,959 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation This is package that wraps `matrix-widget-api` to
|
|
3
|
+
* provide a more convenient API.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Capability } from 'matrix-widget-api';
|
|
7
|
+
import { IModalWidgetCreateData } from 'matrix-widget-api';
|
|
8
|
+
import { IModalWidgetOpenRequestDataButton } from 'matrix-widget-api';
|
|
9
|
+
import { IModalWidgetReturnData } from 'matrix-widget-api';
|
|
10
|
+
import { IOpenIDCredentials } from 'matrix-widget-api';
|
|
11
|
+
import { IRoomEvent } from 'matrix-widget-api';
|
|
12
|
+
import { IWidget } from 'matrix-widget-api';
|
|
13
|
+
import { IWidgetApiRequest } from 'matrix-widget-api';
|
|
14
|
+
import { IWidgetApiRequestData } from 'matrix-widget-api';
|
|
15
|
+
import { ModalButtonID } from 'matrix-widget-api';
|
|
16
|
+
import { Observable } from 'rxjs';
|
|
17
|
+
import { Symbols } from 'matrix-widget-api';
|
|
18
|
+
import { WidgetApi as WidgetApi_2 } from 'matrix-widget-api';
|
|
19
|
+
import { WidgetEventCapability } from 'matrix-widget-api';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Calculate the power level of the user based on a `m.room.power_levels` event.
|
|
23
|
+
*
|
|
24
|
+
* @param powerLevelStateEvent - the content of the `m.room.power_levels` event.
|
|
25
|
+
* @param userId - the ID of the user.
|
|
26
|
+
* @returns the power level of the user.
|
|
27
|
+
*/
|
|
28
|
+
export declare function calculateUserPowerLevel(powerLevelStateEvent: PowerLevelsStateEvent, userId?: string): number;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Compares two room events by their origin server timestamp.
|
|
32
|
+
*
|
|
33
|
+
* @param a - A room event
|
|
34
|
+
* @param b - A room event
|
|
35
|
+
* @returns Either zero if the timestamp is equal, \>0 if a is newer, or \<0 if
|
|
36
|
+
* b is newer.
|
|
37
|
+
*/
|
|
38
|
+
export declare function compareOriginServerTS<T>(a: RoomEvent<T>, b: RoomEvent<T>): number;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Content of a room event that relates to another event.
|
|
42
|
+
*/
|
|
43
|
+
export declare type EventWithRelatesTo<RelationType extends string> = RoomEvent<{
|
|
44
|
+
/**
|
|
45
|
+
* A reference to the event that it relates to.
|
|
46
|
+
*/
|
|
47
|
+
'm.relates_to': RelatesTo<RelationType>;
|
|
48
|
+
}>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Extract the widget parameters from the current `window.location`.
|
|
52
|
+
* @returns The all unprocessed raw widget parameters.
|
|
53
|
+
*/
|
|
54
|
+
export declare function extractRawWidgetParameters(): Record<string, string>;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Extract the parameters used to initialize the widget API from the current
|
|
58
|
+
* `window.location`.
|
|
59
|
+
* @returns The parameters required for initializing the widget API.
|
|
60
|
+
*/
|
|
61
|
+
export declare function extractWidgetApiParameters(): WidgetApiParameters;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Extract the widget parameters from the current `window.location`.
|
|
65
|
+
* @returns The widget parameters.
|
|
66
|
+
*/
|
|
67
|
+
export declare function extractWidgetParameters(): WidgetParameters;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Generate a list of capabilities to access the timeline of other rooms.
|
|
71
|
+
* If enabled, all previously or future capabilities will apply to _all_
|
|
72
|
+
* selected rooms.
|
|
73
|
+
* If `Symbols.AnyRoom` is passed, this is expanded to all joined
|
|
74
|
+
* or invited rooms the client is able to see, current and future.
|
|
75
|
+
*
|
|
76
|
+
* @param roomIds - a list of room ids or `@link Symbols.AnyRoom`.
|
|
77
|
+
* @returns the generated capabilities.
|
|
78
|
+
*/
|
|
79
|
+
export declare function generateRoomTimelineCapabilities(roomIds: string[] | Symbols.AnyRoom): string[];
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Generate a registration URL for the widget based on the current URL and
|
|
83
|
+
* include all widget parameters (and their placeholders).
|
|
84
|
+
* @param options - Options for generating the URL.
|
|
85
|
+
* Use `pathName` to include an optional sub path in the URL.
|
|
86
|
+
* Use `includeParameters` to append the widget parameters to
|
|
87
|
+
* the URL, defaults to `true`.
|
|
88
|
+
* @returns The generated URL.
|
|
89
|
+
*/
|
|
90
|
+
export declare function generateWidgetRegistrationUrl(options?: {
|
|
91
|
+
pathName?: string;
|
|
92
|
+
includeParameters?: boolean;
|
|
93
|
+
widgetParameters?: Partial<WidgetParameters>;
|
|
94
|
+
}): string;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Get the content of the event, independent from whether it contains the
|
|
98
|
+
* content directly or contains a "m.new_content" key.
|
|
99
|
+
* @param event - The room event.
|
|
100
|
+
* @returns Only the content of the room event.
|
|
101
|
+
*/
|
|
102
|
+
export declare function getContent<T>(event: RoomEventOrNewContent<T>): T;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Get the original event id, or the event id of the current event if it
|
|
106
|
+
* doesn't relates to another event.
|
|
107
|
+
* @param event - The room event.
|
|
108
|
+
* @returns The event id of the original event, or the current event id.
|
|
109
|
+
*/
|
|
110
|
+
export declare function getOriginalEventId<T>(event: RoomEventOrNewContent<T>): string;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Generate a unique displayname of a user that is consistent across Matrix clients.
|
|
114
|
+
*
|
|
115
|
+
* @remarks The algorithm is based on https://spec.matrix.org/v1.1/client-server-api/#calculating-the-display-name-for-a-user
|
|
116
|
+
*
|
|
117
|
+
* @param member - the member to generate a name for.
|
|
118
|
+
* @param allRoomMembers - a list of all members of the same room.
|
|
119
|
+
* @returns the displayname that is unique in given the set of all room members.
|
|
120
|
+
*/
|
|
121
|
+
export declare function getRoomMemberDisplayName(member: StateEvent<RoomMemberStateEventContent>, allRoomMembers?: StateEvent<RoomMemberStateEventContent>[]): string;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Check if a user has the power to perform a specific action.
|
|
125
|
+
*
|
|
126
|
+
* Supported actions:
|
|
127
|
+
* * invite: Invite a new user into the room
|
|
128
|
+
* * kick: Kick a user from the room
|
|
129
|
+
* * ban: Ban a user from the room
|
|
130
|
+
* * redact: Redact a message from another user
|
|
131
|
+
*
|
|
132
|
+
* @param powerLevelStateEvent - the content of the `m.room.power_levels` event
|
|
133
|
+
* @param userId - the id of the user
|
|
134
|
+
* @param action - the action
|
|
135
|
+
* @returns if true, the user has the power
|
|
136
|
+
*/
|
|
137
|
+
export declare function hasActionPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, userId: string | undefined, action: PowerLevelsActions): boolean;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Checks whether all widget parameters were provided to the widget.
|
|
141
|
+
*
|
|
142
|
+
* @param widgetApi - The widget api to read the parameters from
|
|
143
|
+
* @returns True, if all parameters were provided.
|
|
144
|
+
*/
|
|
145
|
+
export declare function hasRequiredWidgetParameters(widgetApi: WidgetApi): boolean;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Check if a user has the power to send a specific room event.
|
|
149
|
+
*
|
|
150
|
+
* @param powerLevelStateEvent - the content of the `m.room.power_levels` event
|
|
151
|
+
* @param userId - the id of the user
|
|
152
|
+
* @param eventType - the type of room event
|
|
153
|
+
* @returns if true, the user has the power
|
|
154
|
+
*/
|
|
155
|
+
export declare function hasRoomEventPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, userId: string | undefined, eventType: string): boolean;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Check if a user has the power to send a specific state event.
|
|
159
|
+
*
|
|
160
|
+
* @param powerLevelStateEvent - the content of the `m.room.power_levels` event
|
|
161
|
+
* @param userId - the id of the user
|
|
162
|
+
* @param eventType - the type of state event
|
|
163
|
+
* @returns if true, the user has the power
|
|
164
|
+
*/
|
|
165
|
+
export declare function hasStateEventPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, userId: string | undefined, eventType: string): boolean;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Check if the given event is a {@link RoomEvent}.
|
|
169
|
+
*
|
|
170
|
+
* @param event - An event that is either a {@link RoomEvent} or a {@link StateEvent}.
|
|
171
|
+
* @returns True, if the event is a {@link RoomEvent}.
|
|
172
|
+
*/
|
|
173
|
+
export declare function isRoomEvent(event: RoomEvent | StateEvent): event is RoomEvent;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Check if the given event is a {@link StateEvent}.
|
|
177
|
+
*
|
|
178
|
+
* @param event - An event that is either a {@link RoomEvent} or a {@link StateEvent}.
|
|
179
|
+
* @returns True, if the event is a {@link StateEvent}.
|
|
180
|
+
*/
|
|
181
|
+
export declare function isStateEvent(event: RoomEvent | StateEvent): event is StateEvent;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Validates that `event` has a valid structure for a
|
|
185
|
+
* {@link EventWithRelatesTo}.
|
|
186
|
+
* @param event - The event to validate.
|
|
187
|
+
* @returns True, if the event is valid.
|
|
188
|
+
*/
|
|
189
|
+
export declare function isValidEventWithRelatesTo(event: RoomEvent): event is EventWithRelatesTo<string>;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Validates that `event` is has a valid structure for a
|
|
193
|
+
* {@link PowerLevelsStateEvent}.
|
|
194
|
+
* @param event - The event to validate.
|
|
195
|
+
* @returns True, if the event is valid.
|
|
196
|
+
*/
|
|
197
|
+
export declare function isValidPowerLevelStateEvent(event: StateEvent<unknown>): event is StateEvent<PowerLevelsStateEvent>;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Check whether the format of a redaction event is valid.
|
|
201
|
+
* @param event - The event to check.
|
|
202
|
+
* @returns True if the event format is valid, otherwise false.
|
|
203
|
+
*/
|
|
204
|
+
export declare function isValidRedactionEvent(event: RoomEvent<unknown>): event is RedactionRoomEvent;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Validates that `event` is has a valid structure for a
|
|
208
|
+
* {@link RoomMemberStateEventContent}.
|
|
209
|
+
* @param event - The event to validate.
|
|
210
|
+
* @returns True, if the event is valid.
|
|
211
|
+
*/
|
|
212
|
+
export declare function isValidRoomMemberStateEvent(event: StateEvent<unknown>): event is StateEvent<RoomMemberStateEventContent>;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The membership state of a user.
|
|
216
|
+
*/
|
|
217
|
+
export declare type MembershipState = 'join' | 'invite' | 'leave' | 'ban' | 'knock';
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Navigate the client to another matrix room.
|
|
221
|
+
*
|
|
222
|
+
* @remarks This requires the {@link WIDGET_CAPABILITY_NAVIGATE} capability.
|
|
223
|
+
*
|
|
224
|
+
* @param widgetApi - the {@link WidgetApi} instance.
|
|
225
|
+
* @param roomId - the room ID.
|
|
226
|
+
* @param opts - {@link NavigateToRoomOptions}
|
|
227
|
+
*/
|
|
228
|
+
export declare function navigateToRoom(widgetApi: WidgetApi, roomId: string, opts?: NavigateToRoomOptions): Promise<void>;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Options for the {@link navigateToRoom} function.
|
|
232
|
+
*/
|
|
233
|
+
export declare type NavigateToRoomOptions = {
|
|
234
|
+
/**
|
|
235
|
+
* Optional, array of one or more homeserver domains to discover the room.
|
|
236
|
+
*/
|
|
237
|
+
via?: string[];
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Content of a room event that replaces an existing event with
|
|
242
|
+
* the "m.replace" relation, which means that the content of the
|
|
243
|
+
* previous event is fully replaced.
|
|
244
|
+
*/
|
|
245
|
+
export declare type NewContentRelatesTo<T> = EventWithRelatesTo<'m.replace'>['content'] & {
|
|
246
|
+
/**
|
|
247
|
+
* The new content of the event.
|
|
248
|
+
*/
|
|
249
|
+
'm.new_content': T;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Observes redaction events in the current room.
|
|
254
|
+
* @param widgetApi - An instance of the widget API.
|
|
255
|
+
* @returns An observable of validated redaction events.
|
|
256
|
+
*/
|
|
257
|
+
export declare function observeRedactionEvents(widgetApi: WidgetApi): Observable<RedactionRoomEvent>;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Parse a widget id into the individual fields.
|
|
261
|
+
* @param widgetId - The widget id to parse.
|
|
262
|
+
* @returns The individual fields encoded inside a widget id.
|
|
263
|
+
*/
|
|
264
|
+
export declare function parseWidgetId(widgetId: string): WidgetId;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* The types of actions.
|
|
268
|
+
*/
|
|
269
|
+
export declare type PowerLevelsActions = 'invite' | 'kick' | 'ban' | 'redact';
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* The content of an `m.room.power_levels` event.
|
|
273
|
+
*/
|
|
274
|
+
export declare type PowerLevelsStateEvent = {
|
|
275
|
+
events?: {
|
|
276
|
+
[key: string]: number;
|
|
277
|
+
};
|
|
278
|
+
state_default?: number;
|
|
279
|
+
events_default?: number;
|
|
280
|
+
users?: {
|
|
281
|
+
[key: string]: number;
|
|
282
|
+
};
|
|
283
|
+
users_default?: number;
|
|
284
|
+
ban?: number;
|
|
285
|
+
invite?: number;
|
|
286
|
+
kick?: number;
|
|
287
|
+
redact?: number;
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Redacts an event in the current room.
|
|
292
|
+
* @param widgetApi - An instance of the widget API.
|
|
293
|
+
* @param eventId - The id of the event to redact.
|
|
294
|
+
* @returns The redaction event that was send to the room.
|
|
295
|
+
*/
|
|
296
|
+
export declare function redactEvent(widgetApi: WidgetApi, eventId: string): Promise<RedactionRoomEvent>;
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* The content of an `m.room.redaction` event.
|
|
300
|
+
*/
|
|
301
|
+
export declare type Redaction = {
|
|
302
|
+
/**
|
|
303
|
+
* The id of the event that is redacted.
|
|
304
|
+
*/
|
|
305
|
+
redacts: string;
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Types a {@link RoomEvent} to include the properties of a redaction.
|
|
310
|
+
*
|
|
311
|
+
* @remarks The redaction event is a special snowflake. The actual data is
|
|
312
|
+
* outside the content to make it readable without having to decrypt
|
|
313
|
+
* it.
|
|
314
|
+
*/
|
|
315
|
+
export declare type RedactionRoomEvent = RoomEvent<Record<string, never>> & Redaction;
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Defines a relation to another event.
|
|
319
|
+
*/
|
|
320
|
+
export declare type RelatesTo<RelationType extends string> = {
|
|
321
|
+
/**
|
|
322
|
+
* The event id of the other event.
|
|
323
|
+
*/
|
|
324
|
+
event_id: string;
|
|
325
|
+
/**
|
|
326
|
+
* The relation to the other event.
|
|
327
|
+
*/
|
|
328
|
+
rel_type: RelationType;
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Repair/configure the registration of the current widget.
|
|
333
|
+
* This steps make sure to include all the required widget parameters in the
|
|
334
|
+
* URL. Support setting a widget name and additional parameters.
|
|
335
|
+
*
|
|
336
|
+
* @param widgetApi - The widget api of the current widget.
|
|
337
|
+
* @param registration - Optional configuration options for the widget
|
|
338
|
+
* registration, like the display name of the widget.
|
|
339
|
+
*/
|
|
340
|
+
export declare function repairWidgetRegistration(widgetApi: WidgetApi, registration?: WidgetRegistration): Promise<void>;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* The name of the redaction room event.
|
|
344
|
+
*/
|
|
345
|
+
export declare const ROOM_EVENT_REDACTION = "m.room.redaction";
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Generic type for room events.
|
|
349
|
+
*/
|
|
350
|
+
export declare type RoomEvent<T = unknown> = Omit<IRoomEvent, 'content' | 'state_key' | 'unsigned'> & {
|
|
351
|
+
content: T;
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* A room event that either contains the content directly or contains an
|
|
356
|
+
* "m.new_content" object.
|
|
357
|
+
*/
|
|
358
|
+
export declare type RoomEventOrNewContent<T = unknown> = RoomEvent<T | NewContentRelatesTo<T>>;
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* The content of an `m.room.member` event.
|
|
362
|
+
*
|
|
363
|
+
* @remarks based on https://github.com/matrix-org/matrix-spec/blob/main/data/event-schemas/schema/m.room.member.yaml
|
|
364
|
+
*/
|
|
365
|
+
export declare type RoomMemberStateEventContent = {
|
|
366
|
+
/**
|
|
367
|
+
* The membership state of the user.
|
|
368
|
+
*/
|
|
369
|
+
membership: MembershipState;
|
|
370
|
+
/**
|
|
371
|
+
* The display name for this user, if any.
|
|
372
|
+
*/
|
|
373
|
+
displayname?: string;
|
|
374
|
+
/**
|
|
375
|
+
* The avatar URL for this user, if any.
|
|
376
|
+
*/
|
|
377
|
+
avatar_url?: string;
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* The name of the power levels state event.
|
|
382
|
+
*/
|
|
383
|
+
export declare const STATE_EVENT_POWER_LEVELS = "m.room.power_levels";
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* The name of the room member state event.
|
|
387
|
+
*/
|
|
388
|
+
export declare const STATE_EVENT_ROOM_MEMBER = "m.room.member";
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Generic type for state events.
|
|
392
|
+
*/
|
|
393
|
+
export declare type StateEvent<T = unknown> = Omit<IRoomEvent, 'content' | 'unsigned' | 'state_key'> & {
|
|
394
|
+
state_key: string;
|
|
395
|
+
content: T;
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* The capability that needs to be requested in order to navigate to another room.
|
|
400
|
+
*/
|
|
401
|
+
export declare const WIDGET_CAPABILITY_NAVIGATE = "org.matrix.msc2931.navigate";
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* API for communication from the widget to the client.
|
|
405
|
+
*/
|
|
406
|
+
export declare type WidgetApi = {
|
|
407
|
+
/**
|
|
408
|
+
* The widget Id of the current widget used for the registration in the room.
|
|
409
|
+
*/
|
|
410
|
+
readonly widgetId: string;
|
|
411
|
+
/**
|
|
412
|
+
* Parameters to the widget that are transmitted via the widget URL.
|
|
413
|
+
*/
|
|
414
|
+
readonly widgetParameters: Readonly<WidgetParameters>;
|
|
415
|
+
/**
|
|
416
|
+
* Get the configuration of the widget, if available.
|
|
417
|
+
*
|
|
418
|
+
* @remarks At the moment, this is only available for modal widgets,
|
|
419
|
+
* otherwise it's `undefined`.
|
|
420
|
+
*/
|
|
421
|
+
getWidgetConfig<T extends IWidgetApiRequestData>(): Readonly<WidgetConfig<T> | undefined>;
|
|
422
|
+
/**
|
|
423
|
+
* Rerequests the initialy in the constructor passed capabilities.
|
|
424
|
+
*
|
|
425
|
+
* This is useful in case the user denied one or all of them.
|
|
426
|
+
*/
|
|
427
|
+
rerequestInitialCapabilities(): Promise<void>;
|
|
428
|
+
/**
|
|
429
|
+
* True, if the initial capabilties passed via the constructor were granted.
|
|
430
|
+
*/
|
|
431
|
+
hasInitialCapabilities(): boolean;
|
|
432
|
+
/**
|
|
433
|
+
* Request a list of capabilities.
|
|
434
|
+
*
|
|
435
|
+
* Can be called at any time, not just initially.
|
|
436
|
+
* Resolves once the user has answered the capabilities request.
|
|
437
|
+
*
|
|
438
|
+
* @param capabilities - A list of capabilities that should be requested
|
|
439
|
+
* @throws error if the capabilities request or one of the capabilities was
|
|
440
|
+
* rejected by the user
|
|
441
|
+
*/
|
|
442
|
+
requestCapabilities(capabilities: Array<WidgetEventCapability | Capability>): Promise<void>;
|
|
443
|
+
/**
|
|
444
|
+
* Checks whether the widget has already access to the provided capabilities,
|
|
445
|
+
* without requesting them.
|
|
446
|
+
*
|
|
447
|
+
* @param capabilities - A list of capabilities that should be checked.
|
|
448
|
+
*/
|
|
449
|
+
hasCapabilities(capabilities: Array<WidgetEventCapability | Capability>): boolean;
|
|
450
|
+
/**
|
|
451
|
+
* Receive the last state event of a give type and state key from the current
|
|
452
|
+
* room if any exists.
|
|
453
|
+
*
|
|
454
|
+
* @remarks While one can type the returned event using the generic parameter
|
|
455
|
+
* `T`, it is not recommended to rely on this type till further
|
|
456
|
+
* validation of the event structure is performed.
|
|
457
|
+
*
|
|
458
|
+
* @param eventType - The type of the event to receive.
|
|
459
|
+
* @param stateKey - Specifies the state key to retrieve, uses `''` (empty
|
|
460
|
+
* string) if no state key is passed.
|
|
461
|
+
*/
|
|
462
|
+
receiveSingleStateEvent<T>(eventType: string, stateKey?: string): Promise<StateEvent<T> | undefined>;
|
|
463
|
+
/**
|
|
464
|
+
* Receives the state events of a give type from the current room if any
|
|
465
|
+
* exists.
|
|
466
|
+
*
|
|
467
|
+
* @remarks While one can type the returned event using the generic parameter
|
|
468
|
+
* `T`, it is not recommended to rely on this type till further
|
|
469
|
+
* validation of the event structure is performed.
|
|
470
|
+
*
|
|
471
|
+
* @param eventType - The type of the event to receive.
|
|
472
|
+
* @param options - Options for receiving the state event.
|
|
473
|
+
* Use `stateKey` to receive events with a specifc state
|
|
474
|
+
* key.
|
|
475
|
+
* Use `roomIds` to receive the state events from other
|
|
476
|
+
* rooms.
|
|
477
|
+
* Pass `Symbols.AnyRoom` to receive from all rooms of the
|
|
478
|
+
* user.
|
|
479
|
+
*/
|
|
480
|
+
receiveStateEvents<T>(eventType: string, options?: {
|
|
481
|
+
stateKey?: string;
|
|
482
|
+
roomIds?: string[] | Symbols.AnyRoom;
|
|
483
|
+
}): Promise<StateEvent<T>[]>;
|
|
484
|
+
/**
|
|
485
|
+
* Provide an observable that can be used to listen to state event updates of
|
|
486
|
+
* a given type in the current room.
|
|
487
|
+
* Initially, the current state event is emitted, if one exists.
|
|
488
|
+
*
|
|
489
|
+
* @remarks While one can type the returned event using the generic parameter
|
|
490
|
+
* `T`, it is not recommended to rely on this type till further
|
|
491
|
+
* validation of the event structure is performed.
|
|
492
|
+
*
|
|
493
|
+
* @param eventType - The type of the event to receive.
|
|
494
|
+
* @param options - Options for receiving the state event.
|
|
495
|
+
* Use `stateKey` to receive events with a specifc state
|
|
496
|
+
* key.
|
|
497
|
+
* Use `roomIds` to receive the state events from other
|
|
498
|
+
* rooms.
|
|
499
|
+
* Pass `Symbols.AnyRoom` to receive from all rooms of the
|
|
500
|
+
* user.
|
|
501
|
+
*/
|
|
502
|
+
observeStateEvents<T>(eventType: string, options?: {
|
|
503
|
+
stateKey?: string;
|
|
504
|
+
roomIds?: string[] | Symbols.AnyRoom;
|
|
505
|
+
}): Observable<StateEvent<T>>;
|
|
506
|
+
/**
|
|
507
|
+
* Send a state event with a given type to the current room and wait till the
|
|
508
|
+
* operation is completed.
|
|
509
|
+
* @param eventType - The type of the event to send.
|
|
510
|
+
* @param content - The content of the event.
|
|
511
|
+
* @param options - Options for sending the state event.
|
|
512
|
+
* Use `roomId` to send the state event to another room.
|
|
513
|
+
* Use `stateKey` to send a state event with a custom state
|
|
514
|
+
* key.
|
|
515
|
+
*/
|
|
516
|
+
sendStateEvent<T>(eventType: string, content: T, options?: {
|
|
517
|
+
roomId?: string;
|
|
518
|
+
stateKey?: string;
|
|
519
|
+
}): Promise<StateEvent<T>>;
|
|
520
|
+
/**
|
|
521
|
+
* Receive all room events of a given type from the current room.
|
|
522
|
+
*
|
|
523
|
+
* @remarks While one can type the returned event using the generic parameter
|
|
524
|
+
* `T`, it is not recommended to rely on this type till further
|
|
525
|
+
* validation of the event structure is performed.
|
|
526
|
+
*
|
|
527
|
+
* @param eventType - The type of the event to receive.
|
|
528
|
+
* @param options - Options for receiving the room event.
|
|
529
|
+
* Use `messageType` to receive events with a specifc
|
|
530
|
+
* message type.
|
|
531
|
+
* Use `roomIds` to receive the state events from other
|
|
532
|
+
* rooms.
|
|
533
|
+
* Pass `Symbols.AnyRoom` to receive from all rooms of the
|
|
534
|
+
* user.
|
|
535
|
+
*/
|
|
536
|
+
receiveRoomEvents<T>(eventType: string, options?: {
|
|
537
|
+
messageType?: string;
|
|
538
|
+
roomIds?: string[] | Symbols.AnyRoom;
|
|
539
|
+
}): Promise<Array<RoomEvent<T>>>;
|
|
540
|
+
/**
|
|
541
|
+
* Provide an observable that can be used to listen to room event updates of
|
|
542
|
+
* a given type in the current room.
|
|
543
|
+
* Initially, the previous room events are emitted.
|
|
544
|
+
*
|
|
545
|
+
* @remarks While one can type the returned event using the generic parameter
|
|
546
|
+
* `T`, it is not recommended to rely on this type till further
|
|
547
|
+
* validation of the event structure is performed.
|
|
548
|
+
*
|
|
549
|
+
* @param eventType - The type of the event to receive.
|
|
550
|
+
* @param options - Options for receiving the room event.
|
|
551
|
+
* Use `messageType` to receive events with a specifc
|
|
552
|
+
* message type.
|
|
553
|
+
* Use `roomIds` to receive the state events from other
|
|
554
|
+
* rooms.
|
|
555
|
+
* Pass `Symbols.AnyRoom` to receive from all rooms of the
|
|
556
|
+
* user.
|
|
557
|
+
*/
|
|
558
|
+
observeRoomEvents<T>(eventType: string, options?: {
|
|
559
|
+
messageType?: string;
|
|
560
|
+
roomIds?: string[] | Symbols.AnyRoom;
|
|
561
|
+
}): Observable<RoomEvent<T>>;
|
|
562
|
+
/**
|
|
563
|
+
* Send a room event with a given type to the current room and wait till the
|
|
564
|
+
* operation is completed.
|
|
565
|
+
* @param eventType - The type of the event to send.
|
|
566
|
+
* @param content - The content of the event.
|
|
567
|
+
* @param options - Options for sending the room event.
|
|
568
|
+
* Use `roomId` to send the room event to another room.
|
|
569
|
+
*/
|
|
570
|
+
sendRoomEvent<T>(eventType: string, content: T, options?: {
|
|
571
|
+
roomId?: string;
|
|
572
|
+
}): Promise<RoomEvent<T>>;
|
|
573
|
+
/**
|
|
574
|
+
* Receive an event with a given `eventId` and all events that relate to it by
|
|
575
|
+
* means of MSC2674. Both `originalEvent` and `chunk` can include state events
|
|
576
|
+
* or room events.
|
|
577
|
+
*
|
|
578
|
+
* @remarks You can only receive events where the capability to receive it was
|
|
579
|
+
* approved. If `originalEvent` is not approved, an exception is thrown.
|
|
580
|
+
* If an event in `chunk` is not approve, it is silently skipped. Note
|
|
581
|
+
* that the call might return less than `limit` events due to various
|
|
582
|
+
* reasons, including missing capabilities or encrypted events.
|
|
583
|
+
*
|
|
584
|
+
* @param eventId - The id of the event to receive
|
|
585
|
+
* @param options - Options for receiving the related events.
|
|
586
|
+
* Use `roomId` to receive the event from another room.
|
|
587
|
+
* Use `limit` to control the page size.
|
|
588
|
+
* Use `from` to request the next page of events by providing
|
|
589
|
+
* `nextToken` of a previous call. If `nextToken === undefined`,
|
|
590
|
+
* no further page exists.
|
|
591
|
+
* Use `relationType` to only return events with that `rel_type`.
|
|
592
|
+
* Use `eventType` to only return events with that `type`.
|
|
593
|
+
*
|
|
594
|
+
* @throws if the capability to receive the type of event is missing.
|
|
595
|
+
*/
|
|
596
|
+
readEventRelations(eventId: string, options?: {
|
|
597
|
+
roomId?: string;
|
|
598
|
+
limit?: number;
|
|
599
|
+
from?: string;
|
|
600
|
+
relationType?: string;
|
|
601
|
+
eventType?: string;
|
|
602
|
+
}): Promise<{
|
|
603
|
+
originalEvent?: RoomEvent | StateEvent;
|
|
604
|
+
chunk: Array<RoomEvent | StateEvent>;
|
|
605
|
+
nextToken?: string;
|
|
606
|
+
}>;
|
|
607
|
+
/**
|
|
608
|
+
* Open a new modal, wait until the modal closes, and return the result.
|
|
609
|
+
*
|
|
610
|
+
* This function can only be called from a Widget.
|
|
611
|
+
*
|
|
612
|
+
* @param pathName - The path to include a sub path in the URL.
|
|
613
|
+
* @param name - The name of the modal.
|
|
614
|
+
* @param options - Options for opening the Modal.
|
|
615
|
+
* Use `buttons` to show buttons in the widget.
|
|
616
|
+
* Use `data` to supply optional data to the modal widget.
|
|
617
|
+
* @returns The result data of the modal widget.
|
|
618
|
+
*
|
|
619
|
+
* @throws if called from a modal widget
|
|
620
|
+
*/
|
|
621
|
+
openModal<T extends Record<string, unknown> = Record<string, unknown>, U extends IModalWidgetCreateData = IModalWidgetCreateData>(pathName: string, name: string, options?: {
|
|
622
|
+
buttons?: IModalWidgetOpenRequestDataButton[];
|
|
623
|
+
data?: U;
|
|
624
|
+
}): Promise<T | undefined>;
|
|
625
|
+
/**
|
|
626
|
+
* Enable or disable a button on a modal widget.
|
|
627
|
+
*
|
|
628
|
+
* This function can only be called from a Modal.
|
|
629
|
+
*
|
|
630
|
+
* @param buttonId - The id of the button to enable/disable.
|
|
631
|
+
* @param isEnabled - If `true`, the button is enabled.
|
|
632
|
+
* If `false`, the button is disabled.
|
|
633
|
+
*
|
|
634
|
+
* @throws if called from a non-modal widget
|
|
635
|
+
*/
|
|
636
|
+
setModalButtonEnabled(buttonId: ModalButtonID, isEnabled: boolean): Promise<void>;
|
|
637
|
+
/**
|
|
638
|
+
* Provide an observable that emits button clicks.
|
|
639
|
+
* The emitted values are the button ids.
|
|
640
|
+
*
|
|
641
|
+
* This function can only be called from a Modal.
|
|
642
|
+
*
|
|
643
|
+
* @throws if called from a non-modal widget
|
|
644
|
+
*/
|
|
645
|
+
observeModalButtons(): Observable<ModalButtonID>;
|
|
646
|
+
/**
|
|
647
|
+
* Close the modal widget.
|
|
648
|
+
*
|
|
649
|
+
* This function can only be called from a Modal.
|
|
650
|
+
*
|
|
651
|
+
* @param data - Optional data to pass to the widget that opened the modal.
|
|
652
|
+
* Defaults to `{ 'm.exited': true }`.
|
|
653
|
+
*
|
|
654
|
+
* @throws if called from a non-modal widget
|
|
655
|
+
*/
|
|
656
|
+
closeModal<T extends IModalWidgetReturnData>(data?: T): Promise<void>;
|
|
657
|
+
/**
|
|
658
|
+
* Navigate the client to the given Matrix URI.
|
|
659
|
+
*
|
|
660
|
+
* This supports:
|
|
661
|
+
* - matrix.to urls ({@link https://spec.matrix.org/v1.2/appendices/#matrixto-navigation})
|
|
662
|
+
*
|
|
663
|
+
* @remarks In future, the Matrix URI scheme will also be defined. This
|
|
664
|
+
* requires the `org.matrix.msc2931.navigate` capability.
|
|
665
|
+
*
|
|
666
|
+
* @param uri - the URI to navigate to.
|
|
667
|
+
* @throws Throws if the URI is invalid or cannot be processed.
|
|
668
|
+
*/
|
|
669
|
+
navigateTo(uri: string): Promise<void>;
|
|
670
|
+
/**
|
|
671
|
+
* Requests an OIDC token that can be used to verify the identity of the
|
|
672
|
+
* current user at the `/_matrix/federation/v1/openid/userinfo` endpoint of
|
|
673
|
+
* the home server ({@link https://spec.matrix.org/v1.2/server-server-api/#openid}).
|
|
674
|
+
* The home server can be accessed from the `matrix_server_name` property.
|
|
675
|
+
*
|
|
676
|
+
* @remarks The methods caches the token and only requests a new once if the
|
|
677
|
+
* old one expired.
|
|
678
|
+
*/
|
|
679
|
+
requestOpenIDConnectToken(): Promise<IOpenIDCredentials>;
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Implementation of the API from the widget to the client.
|
|
684
|
+
*
|
|
685
|
+
* @remarks Widget API is specified here:
|
|
686
|
+
* https://docs.google.com/document/d/1uPF7XWY_dXTKVKV7jZQ2KmsI19wn9-kFRgQ1tFQP7wQ/edit#heading=h.9rn9lt6ctkgi
|
|
687
|
+
*/
|
|
688
|
+
export declare class WidgetApiImpl implements WidgetApi {
|
|
689
|
+
/**
|
|
690
|
+
* Provide access to the underlying widget API from `matrix-widget-sdk`.
|
|
691
|
+
*
|
|
692
|
+
* @remarks Normally there is no need to use it, however if features are
|
|
693
|
+
* missing from `WidgetApi` it can be handy to work with the
|
|
694
|
+
* original API.
|
|
695
|
+
*/
|
|
696
|
+
readonly matrixWidgetApi: WidgetApi_2;
|
|
697
|
+
/** {@inheritDoc WidgetApi.widgetId} */
|
|
698
|
+
readonly widgetId: string;
|
|
699
|
+
/** {@inheritDoc WidgetApi.widgetParameters} */
|
|
700
|
+
readonly widgetParameters: WidgetParameters;
|
|
701
|
+
/**
|
|
702
|
+
* Initialize a new widget API instance and wait till it is ready.
|
|
703
|
+
* There should only be one instance of the widget API. The widget API should
|
|
704
|
+
* be created as early as possible when starting the application. This is
|
|
705
|
+
* required to match the timing of the API connection establishment with the
|
|
706
|
+
* client, especially in Safari. Therefore it is recommended to create it
|
|
707
|
+
* inside the entrypoint, before initializing rendering engines like react.
|
|
708
|
+
*
|
|
709
|
+
* @param param0 - {@link WidgetApiOptions}
|
|
710
|
+
*
|
|
711
|
+
* @returns A widget API instance ready to use.
|
|
712
|
+
*/
|
|
713
|
+
static create({ capabilities, supportStandalone, }?: WidgetApiOptions): Promise<WidgetApi>;
|
|
714
|
+
private widgetConfig;
|
|
715
|
+
private outstandingCapabilitiesRequest;
|
|
716
|
+
private outstandingOpenIDConnectTokenRequest;
|
|
717
|
+
private cachedOpenIdToken;
|
|
718
|
+
private readonly events$;
|
|
719
|
+
private readonly initialCapabilities;
|
|
720
|
+
constructor(
|
|
721
|
+
/**
|
|
722
|
+
* Provide access to the underlying widget API from `matrix-widget-sdk`.
|
|
723
|
+
*
|
|
724
|
+
* @remarks Normally there is no need to use it, however if features are
|
|
725
|
+
* missing from `WidgetApi` it can be handy to work with the
|
|
726
|
+
* original API.
|
|
727
|
+
*/
|
|
728
|
+
matrixWidgetApi: WidgetApi_2,
|
|
729
|
+
/** {@inheritDoc WidgetApi.widgetId} */
|
|
730
|
+
widgetId: string,
|
|
731
|
+
/** {@inheritDoc WidgetApi.widgetParameters} */
|
|
732
|
+
widgetParameters: WidgetParameters, { capabilities, supportStandalone }?: WidgetApiOptions);
|
|
733
|
+
/**
|
|
734
|
+
* Initialize the widget API and wait till a connection with the client is
|
|
735
|
+
* fully established.
|
|
736
|
+
*
|
|
737
|
+
* Waits till the user has approved the initial set of capabilities. The
|
|
738
|
+
* method doesn't fail if the user doesn't approve all of them. It is
|
|
739
|
+
* required to check manually afterwards.
|
|
740
|
+
* In case of modal widgets it waits till the `widgetConfig` is received.
|
|
741
|
+
*
|
|
742
|
+
* @remarks Should only be called once during startup.
|
|
743
|
+
*/
|
|
744
|
+
initialize(): Promise<void>;
|
|
745
|
+
/** {@inheritDoc WidgetApi.getWidgetConfig} */
|
|
746
|
+
getWidgetConfig<T extends IWidgetApiRequestData>(): Readonly<WidgetConfig<T> | undefined>;
|
|
747
|
+
/** {@inheritDoc WidgetApi.rerequestInitialCapabilities} */
|
|
748
|
+
rerequestInitialCapabilities(): Promise<void>;
|
|
749
|
+
/** {@inheritDoc WidgetApi.hasInitialCapabilities} */
|
|
750
|
+
hasInitialCapabilities(): boolean;
|
|
751
|
+
/** {@inheritDoc WidgetApi.requestCapabilities} */
|
|
752
|
+
requestCapabilities(capabilities: Array<WidgetEventCapability | Capability>): Promise<void>;
|
|
753
|
+
private requestCapabilitiesInternal;
|
|
754
|
+
/** {@inheritDoc WidgetApi.hasCapabilities} */
|
|
755
|
+
hasCapabilities(capabilities: Array<WidgetEventCapability | Capability>): boolean;
|
|
756
|
+
/** {@inheritDoc WidgetApi.receiveSingleStateEvent} */
|
|
757
|
+
receiveSingleStateEvent<T>(eventType: string, stateKey?: string): Promise<StateEvent<T> | undefined>;
|
|
758
|
+
/** {@inheritDoc WidgetApi.receiveStateEvents} */
|
|
759
|
+
receiveStateEvents<T>(eventType: string, { stateKey, roomIds, }?: {
|
|
760
|
+
stateKey?: string;
|
|
761
|
+
roomIds?: string[] | Symbols.AnyRoom;
|
|
762
|
+
}): Promise<StateEvent<T>[]>;
|
|
763
|
+
/** {@inheritDoc WidgetApi.observeStateEvents} */
|
|
764
|
+
observeStateEvents<T>(eventType: string, { stateKey, roomIds, }?: {
|
|
765
|
+
stateKey?: string;
|
|
766
|
+
roomIds?: string[] | Symbols.AnyRoom;
|
|
767
|
+
}): Observable<StateEvent<T>>;
|
|
768
|
+
/** {@inheritDoc WidgetApi.sendStateEvent} */
|
|
769
|
+
sendStateEvent<T>(eventType: string, content: T, { roomId, stateKey }?: {
|
|
770
|
+
roomId?: string;
|
|
771
|
+
stateKey?: string;
|
|
772
|
+
}): Promise<StateEvent<T>>;
|
|
773
|
+
/** {@inheritDoc WidgetApi.receiveRoomEvents} */
|
|
774
|
+
receiveRoomEvents<T>(eventType: string, { messageType, roomIds, }?: {
|
|
775
|
+
messageType?: string;
|
|
776
|
+
roomIds?: string[] | Symbols.AnyRoom;
|
|
777
|
+
}): Promise<Array<RoomEvent<T>>>;
|
|
778
|
+
/** {@inheritDoc WidgetApi.observeRoomEvents} */
|
|
779
|
+
observeRoomEvents<T>(eventType: string, { messageType, roomIds, }?: {
|
|
780
|
+
messageType?: string;
|
|
781
|
+
roomIds?: string[] | Symbols.AnyRoom;
|
|
782
|
+
}): Observable<RoomEvent<T>>;
|
|
783
|
+
/** {@inheritDoc WidgetApi.sendRoomEvent} */
|
|
784
|
+
sendRoomEvent<T>(eventType: string, content: T, { roomId }?: {
|
|
785
|
+
roomId?: string;
|
|
786
|
+
}): Promise<RoomEvent<T>>;
|
|
787
|
+
/** {@inheritDoc WidgetApi.readEventRelations} */
|
|
788
|
+
readEventRelations(eventId: string, options?: {
|
|
789
|
+
roomId?: string;
|
|
790
|
+
limit?: number;
|
|
791
|
+
from?: string;
|
|
792
|
+
relationType?: string;
|
|
793
|
+
eventType?: string;
|
|
794
|
+
}): Promise<{
|
|
795
|
+
originalEvent?: RoomEvent | StateEvent;
|
|
796
|
+
chunk: Array<RoomEvent | StateEvent>;
|
|
797
|
+
nextToken?: string;
|
|
798
|
+
}>;
|
|
799
|
+
/** {@inheritDoc WidgetApi.openModal} */
|
|
800
|
+
openModal<T extends Record<string, unknown> = Record<string, unknown>, U extends IModalWidgetCreateData = IModalWidgetCreateData>(pathName: string, name: string, options?: {
|
|
801
|
+
buttons?: IModalWidgetOpenRequestDataButton[];
|
|
802
|
+
data?: U;
|
|
803
|
+
}): Promise<T | undefined>;
|
|
804
|
+
/** {@inheritDoc WidgetApi.setModalButtonEnabled} */
|
|
805
|
+
setModalButtonEnabled(buttonId: ModalButtonID, isEnabled: boolean): Promise<void>;
|
|
806
|
+
/** {@inheritDoc WidgetApi.observeModalButtons} */
|
|
807
|
+
observeModalButtons(): Observable<ModalButtonID>;
|
|
808
|
+
/** {@inheritDoc WidgetApi.closeModal} */
|
|
809
|
+
closeModal<T extends IModalWidgetReturnData>(data?: T): Promise<void>;
|
|
810
|
+
/** {@inheritdoc WidgetApi.navigateTo} */
|
|
811
|
+
navigateTo(uri: string): Promise<void>;
|
|
812
|
+
/** {@inheritdoc WidgetApi.requestOpenIDConnectToken} */
|
|
813
|
+
requestOpenIDConnectToken(): Promise<IOpenIDCredentials>;
|
|
814
|
+
private requestOpenIDConnectTokenInternal;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* Options for the {@link WidgetApiImpl.create} function.
|
|
819
|
+
*/
|
|
820
|
+
export declare type WidgetApiOptions = {
|
|
821
|
+
/**
|
|
822
|
+
* Optional initial capabilities that should be requested from the user on
|
|
823
|
+
* load.
|
|
824
|
+
*/
|
|
825
|
+
capabilities?: Array<WidgetEventCapability | Capability>;
|
|
826
|
+
/**
|
|
827
|
+
* Enable the the pop-out button for pinned widgets that support running
|
|
828
|
+
* without the Widget API.
|
|
829
|
+
*/
|
|
830
|
+
supportStandalone?: boolean;
|
|
831
|
+
};
|
|
832
|
+
|
|
833
|
+
/**
|
|
834
|
+
* Parameters used to initialize the widget API inside the widget.
|
|
835
|
+
*/
|
|
836
|
+
export declare type WidgetApiParameters = {
|
|
837
|
+
/**
|
|
838
|
+
* The id of the widget.
|
|
839
|
+
*/
|
|
840
|
+
widgetId: string;
|
|
841
|
+
/**
|
|
842
|
+
* The origin of the client.
|
|
843
|
+
*/
|
|
844
|
+
clientOrigin: string;
|
|
845
|
+
};
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* Configuration of a widget, including data passed to it.
|
|
849
|
+
*/
|
|
850
|
+
export declare type WidgetConfig<T extends IWidgetApiRequestData> = Omit<IWidgetApiRequest & IWidget, 'data'> & {
|
|
851
|
+
data: T;
|
|
852
|
+
};
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* Individual fields that are decoded inside a widget id.
|
|
856
|
+
*/
|
|
857
|
+
export declare type WidgetId = {
|
|
858
|
+
/**
|
|
859
|
+
* The widget id of the main widget if working with modals, or the widget id
|
|
860
|
+
* of the current widget if not.
|
|
861
|
+
*/
|
|
862
|
+
mainWidgetId: string;
|
|
863
|
+
/**
|
|
864
|
+
* The room id the widget is registered in.
|
|
865
|
+
*/
|
|
866
|
+
roomId?: string;
|
|
867
|
+
/**
|
|
868
|
+
* The user id of the user that registered the widget.
|
|
869
|
+
*/
|
|
870
|
+
creator?: string;
|
|
871
|
+
/**
|
|
872
|
+
* True, if this widget is a modal widget.
|
|
873
|
+
*/
|
|
874
|
+
isModal: boolean;
|
|
875
|
+
};
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* Parameters passed from the client to the widget during initialization.
|
|
879
|
+
*/
|
|
880
|
+
export declare type WidgetParameters = {
|
|
881
|
+
/**
|
|
882
|
+
* The user id of the current user.
|
|
883
|
+
*/
|
|
884
|
+
userId?: string;
|
|
885
|
+
/**
|
|
886
|
+
* The display name of the current user.
|
|
887
|
+
*
|
|
888
|
+
* Might be the user id, if the user has no display name configured.
|
|
889
|
+
*/
|
|
890
|
+
displayName?: string;
|
|
891
|
+
/**
|
|
892
|
+
* The URL of the avatar of the current user.
|
|
893
|
+
*
|
|
894
|
+
* Might be unset, if the user has no avatar configured.
|
|
895
|
+
*/
|
|
896
|
+
avatarUrl?: string;
|
|
897
|
+
/**
|
|
898
|
+
* The room id of the room the widget is registered in.
|
|
899
|
+
*/
|
|
900
|
+
roomId?: string;
|
|
901
|
+
/**
|
|
902
|
+
* The current selected theme in the client.
|
|
903
|
+
*
|
|
904
|
+
* Right now, it's either "light" or "dark".
|
|
905
|
+
*/
|
|
906
|
+
theme?: string;
|
|
907
|
+
/**
|
|
908
|
+
* The id of the client that this widget is running in, for example
|
|
909
|
+
* "io.element.web".
|
|
910
|
+
*/
|
|
911
|
+
clientId?: string;
|
|
912
|
+
/**
|
|
913
|
+
* The current selected language in the client.
|
|
914
|
+
*/
|
|
915
|
+
clientLanguage?: string;
|
|
916
|
+
/**
|
|
917
|
+
* Whether the widget was opened by a client or not.
|
|
918
|
+
*
|
|
919
|
+
* This is independent from whether the widget API is available or not.
|
|
920
|
+
* For example, in mobile clients this can be true, but we don't have
|
|
921
|
+
* access to widgets API there.
|
|
922
|
+
*/
|
|
923
|
+
isOpenedByClient: boolean;
|
|
924
|
+
};
|
|
925
|
+
|
|
926
|
+
/**
|
|
927
|
+
* Configuration of the widget in the room.
|
|
928
|
+
*/
|
|
929
|
+
export declare type WidgetRegistration = {
|
|
930
|
+
/**
|
|
931
|
+
* Configure an optional type.
|
|
932
|
+
*
|
|
933
|
+
* Make sure to include a custom prefix when using built-in names.
|
|
934
|
+
* You can discover the available icons in the [Element source code](https://github.com/matrix-org/matrix-react-sdk/blob/9d6d8fc666855ca0c06c71ccb30c74ac4fc8fd12/src/components/views/avatars/WidgetAvatar.tsx#L29-L39).
|
|
935
|
+
*/
|
|
936
|
+
type?: string;
|
|
937
|
+
/**
|
|
938
|
+
* The display name of the widget.
|
|
939
|
+
*/
|
|
940
|
+
name?: string;
|
|
941
|
+
/**
|
|
942
|
+
* The avatar URL used to display an icon on the widget.
|
|
943
|
+
*
|
|
944
|
+
* @remarks Not supported at the moment, as uploading avatars to the channel
|
|
945
|
+
* is not possible from a widget right now.
|
|
946
|
+
*/
|
|
947
|
+
avatarUrl?: string;
|
|
948
|
+
/**
|
|
949
|
+
* Optional additional data that can be used to initialize the widget.
|
|
950
|
+
*/
|
|
951
|
+
data?: Record<string, unknown> | {
|
|
952
|
+
/**
|
|
953
|
+
* An optional sub title for the widget.
|
|
954
|
+
*/
|
|
955
|
+
title?: string;
|
|
956
|
+
};
|
|
957
|
+
};
|
|
958
|
+
|
|
959
|
+
export { }
|