@matrix-widget-toolkit/api 4.1.2 → 5.0.0

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 CHANGED
@@ -148,3 +148,12 @@ It returns a promise that resolves with the result of the modal.
148
148
  Inside the modal widget, you can use `observeModalButtons()` to listen to clicks on the bottom buttons of the modal.
149
149
  You can use `setModalButtonEnabled()` to disable buttons from within the widget.
150
150
  Once you are done, you can call `closeModal()` to close the modal and pass the results back to the main widget.
151
+
152
+ ### Delayed events
153
+
154
+ You can send and update delayed events (MSC4140). The configuration for delayed events on the homeserver
155
+ needs to be applied, for example:
156
+
157
+ ```
158
+ max_event_delay_duration: 24h
159
+ ```
@@ -1,4 +1,4 @@
1
- import { Capability, IDownloadFileActionFromWidgetResponseData, IGetMediaConfigActionFromWidgetResponseData, IModalWidgetCreateData, IModalWidgetOpenRequestDataButton, IModalWidgetReturnData, IOpenIDCredentials, ISendEventFromWidgetResponseData, IUploadFileActionFromWidgetResponseData, IWidgetApiRequestData, WidgetApi as MatrixWidgetApi, ModalButtonID, Symbols, WidgetEventCapability } from 'matrix-widget-api';
1
+ import { Capability, IDownloadFileActionFromWidgetResponseData, IGetMediaConfigActionFromWidgetResponseData, IModalWidgetCreateData, IModalWidgetOpenRequestDataButton, IModalWidgetReturnData, IOpenIDCredentials, ISendEventFromWidgetResponseData, IUploadFileActionFromWidgetResponseData, IWidgetApiRequestData, WidgetApi as MatrixWidgetApi, ModalButtonID, Symbols, UpdateDelayedEventAction, WidgetEventCapability } from 'matrix-widget-api';
2
2
  import { Observable } from 'rxjs';
3
3
  import { RoomEvent, StateEvent, ToDeviceMessageEvent, TurnServer, WidgetApi, WidgetConfig, WidgetParameters } from './types';
4
4
  /**
@@ -108,6 +108,13 @@ export declare class WidgetApiImpl implements WidgetApi {
108
108
  roomId?: string;
109
109
  stateKey?: string;
110
110
  }): Promise<ISendEventFromWidgetResponseData>;
111
+ /** {@inheritDoc WidgetApi.sendDelayedStateEvent} */
112
+ sendDelayedStateEvent<T>(eventType: string, content: T, delay: number, { roomId, stateKey }?: {
113
+ roomId?: string;
114
+ stateKey?: string;
115
+ }): Promise<{
116
+ delay_id: string;
117
+ }>;
111
118
  /** {@inheritDoc WidgetApi.receiveRoomEvents} */
112
119
  receiveRoomEvents<T>(eventType: string, { messageType, roomIds, }?: {
113
120
  messageType?: string;
@@ -122,6 +129,14 @@ export declare class WidgetApiImpl implements WidgetApi {
122
129
  sendRoomEvent<T>(eventType: string, content: T, { roomId }?: {
123
130
  roomId?: string;
124
131
  }): Promise<RoomEvent<T>>;
132
+ /** {@inheritDoc WidgetApi.sendDelayedRoomEvent} */
133
+ sendDelayedRoomEvent<T>(eventType: string, content: T, delay: number, { roomId }?: {
134
+ roomId?: string;
135
+ }): Promise<{
136
+ delay_id: string;
137
+ }>;
138
+ /** {@inheritDoc WidgetApi.updateDelayedEvent} */
139
+ updateDelayedEvent(delayId: string, action: UpdateDelayedEventAction): Promise<void>;
125
140
  /** {@inheritDoc WidgetApi.readEventRelations} */
126
141
  readEventRelations(eventId: string, options?: {
127
142
  roomId?: string;
@@ -1,5 +1,13 @@
1
1
  import Joi from 'joi';
2
2
  import { RoomEvent, StateEvent, ToDeviceMessageEvent } from '../types';
3
+ /**
4
+ * The type of the power levels state event.
5
+ */
6
+ export declare const STATE_EVENT_POWER_LEVELS = "m.room.power_levels";
7
+ /**
8
+ * The types of type of the create event.
9
+ */
10
+ export declare const STATE_EVENT_CREATE = "m.room.create";
3
11
  /**
4
12
  * Check if the given event is a {@link StateEvent}.
5
13
  *
@@ -38,3 +46,46 @@ export declare function isValidToDeviceMessageEvent(event: unknown): event is To
38
46
  export declare const roomEventSchema: Joi.ObjectSchema<RoomEvent>;
39
47
  export declare const stateEventSchema: Joi.ObjectSchema<StateEvent>;
40
48
  export declare const toDeviceMessageSchema: Joi.ObjectSchema<ToDeviceMessageEvent>;
49
+ export type StateEventCreateContent = {
50
+ room_version?: string;
51
+ creator?: string;
52
+ additional_creators?: string[];
53
+ };
54
+ export declare const createEventSchema: Joi.ObjectSchema<StateEvent<StateEventCreateContent>>;
55
+ /**
56
+ * Validates that `event` is has a valid structure for a
57
+ * {@link StateEventCreateContent}.
58
+ * @param event - The event to validate.
59
+ * @returns True, if the event is valid.
60
+ */
61
+ export declare function isValidCreateEventSchema(event: StateEvent<unknown> | undefined): event is StateEvent<StateEventCreateContent>;
62
+ /**
63
+ * The types of actions.
64
+ */
65
+ export type PowerLevelsActions = 'invite' | 'kick' | 'ban' | 'redact';
66
+ /**
67
+ * The content of an `m.room.power_levels` event.
68
+ */
69
+ export type PowerLevelsStateEvent = {
70
+ events?: {
71
+ [key: string]: number;
72
+ };
73
+ state_default?: number;
74
+ events_default?: number;
75
+ users?: {
76
+ [key: string]: number;
77
+ };
78
+ users_default?: number;
79
+ ban?: number;
80
+ invite?: number;
81
+ kick?: number;
82
+ redact?: number;
83
+ };
84
+ export declare const powerLevelsEventSchema: Joi.ObjectSchema<StateEvent<PowerLevelsStateEvent>>;
85
+ /**
86
+ * Validates that `event` is has a valid structure for a
87
+ * {@link PowerLevelsStateEvent}.
88
+ * @param event - The event to validate.
89
+ * @returns True, if the event is valid.
90
+ */
91
+ export declare function isValidPowerLevelStateEvent(event: StateEvent<unknown>): event is StateEvent<PowerLevelsStateEvent>;
@@ -1,11 +1,12 @@
1
1
  export { generateRoomTimelineCapabilities } from './capabilities';
2
2
  export { getRoomMemberDisplayName } from './displayName';
3
- export { isRoomEvent, isStateEvent, isValidRoomEvent, isValidStateEvent as isValidStateEVent, isValidToDeviceMessageEvent, } from './events';
3
+ export { STATE_EVENT_CREATE, isRoomEvent, isStateEvent, isValidCreateEventSchema, isValidRoomEvent, isValidStateEvent as isValidStateEVent, isValidToDeviceMessageEvent, } from './events';
4
+ export type { PowerLevelsActions, PowerLevelsStateEvent, StateEventCreateContent, } from './events';
4
5
  export { WIDGET_CAPABILITY_NAVIGATE, navigateToRoom } from './navigateTo';
5
6
  export type { NavigateToRoomOptions } from './navigateTo';
6
7
  export { compareOriginServerTS } from './originServerTs';
7
8
  export { STATE_EVENT_POWER_LEVELS, calculateUserPowerLevel, hasActionPower, hasRoomEventPower, hasStateEventPower, isValidPowerLevelStateEvent, } from './powerLevel';
8
- export type { PowerLevelsActions, PowerLevelsStateEvent } from './powerLevel';
9
+ export type { ROOM_VERSION_12_CREATOR, UserPowerLevelType } from './powerLevel';
9
10
  export { ROOM_EVENT_REDACTION, isValidRedactionEvent, observeRedactionEvents, redactEvent, } from './redactions';
10
11
  export type { Redaction, RedactionRoomEvent } from './redactions';
11
12
  export { getContent, getOriginalEventId, isValidEventWithRelatesTo, } from './relatesTo';
@@ -1,55 +1,32 @@
1
1
  import { StateEvent } from '../types';
2
+ import type { PowerLevelsActions, PowerLevelsStateEvent, StateEventCreateContent } from './events';
3
+ export { isValidPowerLevelStateEvent, STATE_EVENT_POWER_LEVELS, } from './events';
2
4
  /**
3
- * The name of the power levels state event.
5
+ * Room version 12 requires us to have something larger than Max integer for room creators.
6
+ * This is a workaround to allow the room creator to always have the highest power level.
4
7
  */
5
- export declare const STATE_EVENT_POWER_LEVELS = "m.room.power_levels";
6
- /**
7
- * The types of actions.
8
- */
9
- export type PowerLevelsActions = 'invite' | 'kick' | 'ban' | 'redact';
10
- /**
11
- * The content of an `m.room.power_levels` event.
12
- */
13
- export type PowerLevelsStateEvent = {
14
- events?: {
15
- [key: string]: number;
16
- };
17
- state_default?: number;
18
- events_default?: number;
19
- users?: {
20
- [key: string]: number;
21
- };
22
- users_default?: number;
23
- ban?: number;
24
- invite?: number;
25
- kick?: number;
26
- redact?: number;
27
- };
28
- /**
29
- * Validates that `event` is has a valid structure for a
30
- * {@link PowerLevelsStateEvent}.
31
- * @param event - The event to validate.
32
- * @returns True, if the event is valid.
33
- */
34
- export declare function isValidPowerLevelStateEvent(event: StateEvent<unknown>): event is StateEvent<PowerLevelsStateEvent>;
8
+ export declare const ROOM_VERSION_12_CREATOR = "ROOM_VERSION_12_CREATOR";
9
+ export type UserPowerLevelType = number | typeof ROOM_VERSION_12_CREATOR;
35
10
  /**
36
11
  * Check if a user has the power to send a specific room event.
37
12
  *
38
13
  * @param powerLevelStateEvent - the content of the `m.room.power_levels` event
14
+ * @param createRoomStateEvent - the `m.room.create` event for the room
39
15
  * @param userId - the id of the user
40
16
  * @param eventType - the type of room event
41
17
  * @returns if true, the user has the power
42
18
  */
43
- export declare function hasRoomEventPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, userId: string | undefined, eventType: string): boolean;
19
+ export declare function hasRoomEventPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, createRoomStateEvent: StateEvent<StateEventCreateContent> | undefined, userId: string | undefined, eventType: string): boolean;
44
20
  /**
45
21
  * Check if a user has the power to send a specific state event.
46
22
  *
47
23
  * @param powerLevelStateEvent - the content of the `m.room.power_levels` event
24
+ * @param createRoomStateEvent - the `m.room.create` event for the room
48
25
  * @param userId - the id of the user
49
26
  * @param eventType - the type of state event
50
27
  * @returns if true, the user has the power
51
28
  */
52
- export declare function hasStateEventPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, userId: string | undefined, eventType: string): boolean;
29
+ export declare function hasStateEventPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, createRoomStateEvent: StateEvent<StateEventCreateContent> | undefined, userId: string | undefined, eventType: string): boolean;
53
30
  /**
54
31
  * Check if a user has the power to perform a specific action.
55
32
  *
@@ -60,19 +37,25 @@ export declare function hasStateEventPower(powerLevelStateEvent: PowerLevelsStat
60
37
  * * redact: Redact a message from another user
61
38
  *
62
39
  * @param powerLevelStateEvent - the content of the `m.room.power_levels` event
40
+ * @param createRoomStateEvent - the `m.room.create` event for the room
63
41
  * @param userId - the id of the user
64
42
  * @param action - the action
65
43
  * @returns if true, the user has the power
66
44
  */
67
- export declare function hasActionPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, userId: string | undefined, action: PowerLevelsActions): boolean;
45
+ export declare function hasActionPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, createRoomStateEvent: StateEvent<StateEventCreateContent> | undefined, userId: string | undefined, action: PowerLevelsActions): boolean;
68
46
  /**
69
47
  * Calculate the power level of the user based on a `m.room.power_levels` event.
70
48
  *
49
+ * Note that we return the @see UserPowerLevelType type instead of a number as Room Version 12
50
+ * gives a Room creator (and additionalCreators) always the highest power level regardless
51
+ * of the highest next Powerlevel number.
52
+ *
71
53
  * @param powerLevelStateEvent - the content of the `m.room.power_levels` event.
54
+ * @param createRoomStateEvent - the `m.room.create` event for the room.
72
55
  * @param userId - the ID of the user.
73
56
  * @returns the power level of the user.
74
57
  */
75
- export declare function calculateUserPowerLevel(powerLevelStateEvent: PowerLevelsStateEvent, userId?: string): number;
58
+ export declare function calculateUserPowerLevel(powerLevelStateEvent: PowerLevelsStateEvent | undefined, createRoomStateEvent: StateEvent<StateEventCreateContent> | undefined, userId: string): UserPowerLevelType;
76
59
  /**
77
60
  * Calculate the power level that a user needs send a specific room event.
78
61
  *
@@ -80,15 +63,16 @@ export declare function calculateUserPowerLevel(powerLevelStateEvent: PowerLevel
80
63
  * @param eventType - the type of room event
81
64
  * @returns the power level that is needed
82
65
  */
83
- export declare function calculateRoomEventPowerLevel(powerLevelStateEvent: PowerLevelsStateEvent, eventType: string): number;
66
+ export declare function calculateRoomEventPowerLevel(powerLevelStateEvent: PowerLevelsStateEvent | undefined, eventType: string): number;
84
67
  /**
85
68
  * Calculate the power level that a user needs send a specific state event.
86
69
  *
87
70
  * @param powerLevelStateEvent - the content of the `m.room.power_levels` event
71
+ * @param createRoomStateEvent - the `m.room.create` event
88
72
  * @param eventType - the type of state event
89
73
  * @returns the power level that is needed
90
74
  */
91
- export declare function calculateStateEventPowerLevel(powerLevelStateEvent: PowerLevelsStateEvent, eventType: string): number;
75
+ export declare function calculateStateEventPowerLevel(powerLevelStateEvent: PowerLevelsStateEvent | undefined, createRoomStateEvent: StateEvent<StateEventCreateContent> | undefined, eventType: string): number;
92
76
  /**
93
77
  * Calculate the power level that a user needs to perform an action.
94
78
  *
@@ -102,4 +86,4 @@ export declare function calculateStateEventPowerLevel(powerLevelStateEvent: Powe
102
86
  * @param action - the action
103
87
  * @returns the power level that is needed
104
88
  */
105
- export declare function calculateActionPowerLevel(powerLevelStateEvent: PowerLevelsStateEvent, action: PowerLevelsActions): number;
89
+ export declare function calculateActionPowerLevel(powerLevelStateEvent: PowerLevelsStateEvent | undefined, action: PowerLevelsActions): number;
@@ -1,4 +1,4 @@
1
- import { Capability, IDownloadFileActionFromWidgetResponseData, IGetMediaConfigActionFromWidgetResponseData, IModalWidgetCreateData, IModalWidgetOpenRequestDataButton, IModalWidgetReturnData, IOpenIDCredentials, IRoomEvent, ISendEventFromWidgetResponseData, IUploadFileActionFromWidgetResponseData, IWidget, IWidgetApiRequest, IWidgetApiRequestData, ModalButtonID, Symbols, WidgetEventCapability } from 'matrix-widget-api';
1
+ import { Capability, IDownloadFileActionFromWidgetResponseData, IGetMediaConfigActionFromWidgetResponseData, IModalWidgetCreateData, IModalWidgetOpenRequestDataButton, IModalWidgetReturnData, IOpenIDCredentials, IRoomEvent, ISendEventFromWidgetResponseData, IUploadFileActionFromWidgetResponseData, IWidget, IWidgetApiRequest, IWidgetApiRequestData, ModalButtonID, Symbols, UpdateDelayedEventAction, WidgetEventCapability } from 'matrix-widget-api';
2
2
  import { Observable } from 'rxjs';
3
3
  /**
4
4
  * Enumeration of widget parameters that can be checked if they are available upon registration.
@@ -265,6 +265,23 @@ export type WidgetApi = {
265
265
  roomId?: string;
266
266
  stateKey?: string;
267
267
  }): Promise<ISendEventFromWidgetResponseData>;
268
+ /**
269
+ * Send a delayed state event with a given type to the current room.
270
+ * @param eventType - The type of the event to send.
271
+ * @param content - The content of the event.
272
+ * @param delay - The delay of the event in milliseconds.
273
+ * @param options - Options for sending the state event.
274
+ * Use `roomId` to send the state event to another room.
275
+ * Use `stateKey` to send a state event with a custom state
276
+ * key.
277
+ * @returns The result data of delayed event with delay_id.
278
+ */
279
+ sendDelayedStateEvent<T>(eventType: string, content: T, delay: number, options?: {
280
+ roomId?: string;
281
+ stateKey?: string;
282
+ }): Promise<{
283
+ delay_id: string;
284
+ }>;
268
285
  /**
269
286
  * Receive all room events of a given type from the current room.
270
287
  *
@@ -318,6 +335,28 @@ export type WidgetApi = {
318
335
  sendRoomEvent<T>(eventType: string, content: T, options?: {
319
336
  roomId?: string;
320
337
  }): Promise<RoomEvent<T>>;
338
+ /**
339
+ * Send a delayed room event with a given type to the current room.
340
+ * @param eventType - The type of the event to send.
341
+ * @param content - The content of the event.
342
+ * @param delay - The delay of the event in milliseconds.
343
+ * @param options - Options for sending the state event.
344
+ * Use `roomId` to send the state event to another room.
345
+ * Use `stateKey` to send a state event with a custom state
346
+ * key.
347
+ * @returns The result data of delayed event with delay_id.
348
+ */
349
+ sendDelayedRoomEvent<T>(eventType: string, content: T, delay: number, options?: {
350
+ roomId?: string;
351
+ }): Promise<{
352
+ delay_id: string;
353
+ }>;
354
+ /**
355
+ * Update a delayed event by delay id
356
+ * @param delayId - The delay id of the event
357
+ * @param action - The action to update
358
+ */
359
+ updateDelayedEvent(delayId: string, action: UpdateDelayedEventAction): Promise<void>;
321
360
  /**
322
361
  * Receive all events that relate to a given `eventId` by means of MSC2674.
323
362
  * `chunk` can include state events or room events.