@matrix-widget-toolkit/api 3.3.1 → 3.3.2
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/build/cjs/index.js +1473 -1473
- package/build/esm/index.js +1467 -1467
- package/package.json +6 -5
package/build/cjs/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var matrixWidgetApi = require('matrix-widget-api');
|
|
4
|
-
var rxjs = require('rxjs');
|
|
5
4
|
var qs = require('qs');
|
|
5
|
+
var rxjs = require('rxjs');
|
|
6
6
|
|
|
7
7
|
/*
|
|
8
8
|
* Copyright 2022 Nordeck IT + Consulting GmbH
|
|
@@ -19,93 +19,112 @@ var qs = require('qs');
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
-
var __assign$1 = (undefined && undefined.__assign) || function () {
|
|
23
|
-
__assign$1 = Object.assign || function(t) {
|
|
24
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
25
|
-
s = arguments[i];
|
|
26
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
27
|
-
t[p] = s[p];
|
|
28
|
-
}
|
|
29
|
-
return t;
|
|
30
|
-
};
|
|
31
|
-
return __assign$1.apply(this, arguments);
|
|
32
|
-
};
|
|
33
22
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
23
|
+
* Generate a list of capabilities to access the timeline of other rooms.
|
|
24
|
+
* If enabled, all previously or future capabilities will apply to _all_
|
|
25
|
+
* selected rooms.
|
|
26
|
+
* If `Symbols.AnyRoom` is passed, this is expanded to all joined
|
|
27
|
+
* or invited rooms the client is able to see, current and future.
|
|
28
|
+
*
|
|
29
|
+
* @param roomIds - a list of room ids or `@link Symbols.AnyRoom`.
|
|
30
|
+
* @returns the generated capabilities.
|
|
37
31
|
*/
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// want to inform the user that the widget only works inside of element.
|
|
42
|
-
if (typeof query.parentUrl !== 'string') {
|
|
43
|
-
throw Error('Missing parameter "parentUrl"');
|
|
32
|
+
function generateRoomTimelineCapabilities(roomIds) {
|
|
33
|
+
if (roomIds === matrixWidgetApi.Symbols.AnyRoom) {
|
|
34
|
+
return ['org.matrix.msc2762.timeline:*'];
|
|
44
35
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
throw Error('Missing parameter "widgetId"');
|
|
36
|
+
if (Array.isArray(roomIds)) {
|
|
37
|
+
return roomIds.map(function (id) { return "org.matrix.msc2762.timeline:".concat(id); });
|
|
48
38
|
}
|
|
49
|
-
|
|
50
|
-
return { widgetId: widgetId, clientOrigin: clientOrigin };
|
|
39
|
+
return [];
|
|
51
40
|
}
|
|
41
|
+
|
|
42
|
+
/*
|
|
43
|
+
* Copyright 2022 Nordeck IT + Consulting GmbH
|
|
44
|
+
*
|
|
45
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
46
|
+
* you may not use this file except in compliance with the License.
|
|
47
|
+
* You may obtain a copy of the License at
|
|
48
|
+
*
|
|
49
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
50
|
+
*
|
|
51
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
52
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
53
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
54
|
+
* See the License for the specific language governing permissions and
|
|
55
|
+
* limitations under the License.
|
|
56
|
+
*/
|
|
52
57
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
58
|
+
* Generate a unique displayname of a user that is consistent across Matrix clients.
|
|
59
|
+
*
|
|
60
|
+
* @remarks The algorithm is based on https://spec.matrix.org/v1.1/client-server-api/#calculating-the-display-name-for-a-user
|
|
61
|
+
*
|
|
62
|
+
* @param member - the member to generate a name for.
|
|
63
|
+
* @param allRoomMembers - a list of all members of the same room.
|
|
64
|
+
* @returns the displayname that is unique in given the set of all room members.
|
|
55
65
|
*/
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
function getRoomMemberDisplayName(member, allRoomMembers) {
|
|
67
|
+
if (allRoomMembers === void 0) { allRoomMembers = []; }
|
|
68
|
+
// If the m.room.member state event has no displayname field, or if that field
|
|
69
|
+
// has a null value, use the raw user id as the display name.
|
|
70
|
+
if (typeof member.content.displayname !== 'string') {
|
|
71
|
+
return member.state_key;
|
|
72
|
+
}
|
|
73
|
+
// If the m.room.member event has a displayname which is unique among members of
|
|
74
|
+
// the room with membership: join or membership: invite, ...
|
|
75
|
+
var hasDuplicateDisplayName = allRoomMembers.some(function (m) {
|
|
76
|
+
// same room
|
|
77
|
+
return m.room_id === member.room_id &&
|
|
78
|
+
// not the own event
|
|
79
|
+
m.state_key !== member.state_key &&
|
|
80
|
+
// only join or invite state
|
|
81
|
+
['join', 'invite'].includes(m.content.membership) &&
|
|
82
|
+
// same displayname
|
|
83
|
+
m.content.displayname === member.content.displayname;
|
|
84
|
+
});
|
|
85
|
+
if (!hasDuplicateDisplayName) {
|
|
86
|
+
// ... use the given displayname as the user-visible display name.
|
|
87
|
+
return member.content.displayname;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
// The m.room.member event has a non-unique displayname. This should be
|
|
91
|
+
// disambiguated using the user id, for example “display name (@id:homeserver.org)”.
|
|
92
|
+
return "".concat(member.content.displayname, " (").concat(member.state_key, ")");
|
|
93
|
+
}
|
|
63
94
|
}
|
|
95
|
+
|
|
96
|
+
/*
|
|
97
|
+
* Copyright 2022 Nordeck IT + Consulting GmbH
|
|
98
|
+
*
|
|
99
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
100
|
+
* you may not use this file except in compliance with the License.
|
|
101
|
+
* You may obtain a copy of the License at
|
|
102
|
+
*
|
|
103
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
104
|
+
*
|
|
105
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
106
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
107
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
108
|
+
* See the License for the specific language governing permissions and
|
|
109
|
+
* limitations under the License.
|
|
110
|
+
*/
|
|
64
111
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
112
|
+
* Check if the given event is a {@link StateEvent}.
|
|
113
|
+
*
|
|
114
|
+
* @param event - An event that is either a {@link RoomEvent} or a {@link StateEvent}.
|
|
115
|
+
* @returns True, if the event is a {@link StateEvent}.
|
|
67
116
|
*/
|
|
68
|
-
function
|
|
69
|
-
|
|
70
|
-
// This is a hack to detect whether we are in a mobile client that supports widgets,
|
|
71
|
-
// but not the widget API. Mobile clients are not passing the parameters required for
|
|
72
|
-
// the widget API (like widgetId), but are passing the replaced placeholder values for
|
|
73
|
-
// the widget parameters.
|
|
74
|
-
var roomId = params['matrix_room_id'];
|
|
75
|
-
var isOpenedByClient = typeof roomId === 'string' && roomId !== '$matrix_room_id';
|
|
76
|
-
return {
|
|
77
|
-
userId: params['matrix_user_id'],
|
|
78
|
-
displayName: params['matrix_display_name'],
|
|
79
|
-
avatarUrl: params['matrix_avatar_url'],
|
|
80
|
-
roomId: roomId,
|
|
81
|
-
theme: params['theme'],
|
|
82
|
-
clientId: params['matrix_client_id'],
|
|
83
|
-
clientLanguage: params['matrix_client_language'],
|
|
84
|
-
baseUrl: params['matrix_base_url'],
|
|
85
|
-
isOpenedByClient: isOpenedByClient,
|
|
86
|
-
};
|
|
117
|
+
function isStateEvent(event) {
|
|
118
|
+
return 'state_key' in event && typeof event.state_key === 'string';
|
|
87
119
|
}
|
|
88
120
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* @
|
|
121
|
+
* Check if the given event is a {@link RoomEvent}.
|
|
122
|
+
*
|
|
123
|
+
* @param event - An event that is either a {@link RoomEvent} or a {@link StateEvent}.
|
|
124
|
+
* @returns True, if the event is a {@link RoomEvent}.
|
|
92
125
|
*/
|
|
93
|
-
function
|
|
94
|
-
|
|
95
|
-
var mainWidgetId = decodeURIComponent(widgetId).replace(/^modal_/, '');
|
|
96
|
-
var roomId = mainWidgetId.indexOf('_')
|
|
97
|
-
? decodeURIComponent(mainWidgetId.split('_')[0])
|
|
98
|
-
: undefined;
|
|
99
|
-
var creator = (mainWidgetId.match(/_/g) || []).length > 1
|
|
100
|
-
? decodeURIComponent(mainWidgetId.split('_')[1])
|
|
101
|
-
: undefined;
|
|
102
|
-
var isModal = decodeURIComponent(widgetId).startsWith('modal_');
|
|
103
|
-
return {
|
|
104
|
-
mainWidgetId: mainWidgetId,
|
|
105
|
-
roomId: roomId,
|
|
106
|
-
creator: creator,
|
|
107
|
-
isModal: isModal,
|
|
108
|
-
};
|
|
126
|
+
function isRoomEvent(event) {
|
|
127
|
+
return !('state_key' in event);
|
|
109
128
|
}
|
|
110
129
|
|
|
111
130
|
/*
|
|
@@ -123,17 +142,6 @@ function parseWidgetId(widgetId) {
|
|
|
123
142
|
* See the License for the specific language governing permissions and
|
|
124
143
|
* limitations under the License.
|
|
125
144
|
*/
|
|
126
|
-
var __assign = (undefined && undefined.__assign) || function () {
|
|
127
|
-
__assign = Object.assign || function(t) {
|
|
128
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
129
|
-
s = arguments[i];
|
|
130
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
131
|
-
t[p] = s[p];
|
|
132
|
-
}
|
|
133
|
-
return t;
|
|
134
|
-
};
|
|
135
|
-
return __assign.apply(this, arguments);
|
|
136
|
-
};
|
|
137
145
|
var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
138
146
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
139
147
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -170,125 +178,63 @@ var __generator$3 = (undefined && undefined.__generator) || function (thisArg, b
|
|
|
170
178
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
171
179
|
}
|
|
172
180
|
};
|
|
173
|
-
var __rest = (undefined && undefined.__rest) || function (s, e) {
|
|
174
|
-
var t = {};
|
|
175
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
176
|
-
t[p] = s[p];
|
|
177
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
178
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
179
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
180
|
-
t[p[i]] = s[p[i]];
|
|
181
|
-
}
|
|
182
|
-
return t;
|
|
183
|
-
};
|
|
184
181
|
/**
|
|
185
|
-
*
|
|
182
|
+
* The capability that needs to be requested in order to navigate to another room.
|
|
183
|
+
*/
|
|
184
|
+
var WIDGET_CAPABILITY_NAVIGATE = 'org.matrix.msc2931.navigate';
|
|
185
|
+
/**
|
|
186
|
+
* Navigate the client to another matrix room.
|
|
186
187
|
*
|
|
187
|
-
* @
|
|
188
|
-
*
|
|
188
|
+
* @remarks This requires the {@link WIDGET_CAPABILITY_NAVIGATE} capability.
|
|
189
|
+
*
|
|
190
|
+
* @param widgetApi - the {@link WidgetApi} instance.
|
|
191
|
+
* @param roomId - the room ID.
|
|
192
|
+
* @param opts - {@link NavigateToRoomOptions}
|
|
189
193
|
*/
|
|
190
|
-
function
|
|
191
|
-
return (
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
194
|
+
function navigateToRoom(widgetApi_1, roomId_1) {
|
|
195
|
+
return __awaiter$3(this, arguments, void 0, function (widgetApi, roomId, opts) {
|
|
196
|
+
var _a, via, params, url;
|
|
197
|
+
if (opts === void 0) { opts = {}; }
|
|
198
|
+
return __generator$3(this, function (_b) {
|
|
199
|
+
switch (_b.label) {
|
|
200
|
+
case 0:
|
|
201
|
+
_a = opts.via, via = _a === void 0 ? [] : _a;
|
|
202
|
+
params = qs.stringify({ via: via }, { addQueryPrefix: true, arrayFormat: 'repeat' });
|
|
203
|
+
url = "https://matrix.to/#/".concat(encodeURIComponent(roomId)).concat(params);
|
|
204
|
+
return [4 /*yield*/, widgetApi.navigateTo(url)];
|
|
205
|
+
case 1:
|
|
206
|
+
_b.sent();
|
|
207
|
+
return [2 /*return*/];
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
});
|
|
199
211
|
}
|
|
212
|
+
|
|
213
|
+
/*
|
|
214
|
+
* Copyright 2022 Nordeck IT + Consulting GmbH
|
|
215
|
+
*
|
|
216
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
217
|
+
* you may not use this file except in compliance with the License.
|
|
218
|
+
* You may obtain a copy of the License at
|
|
219
|
+
*
|
|
220
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
221
|
+
*
|
|
222
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
223
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
224
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
225
|
+
* See the License for the specific language governing permissions and
|
|
226
|
+
* limitations under the License.
|
|
227
|
+
*/
|
|
200
228
|
/**
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
* @param
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
* @returns The generated URL.
|
|
229
|
+
* Compares two room events by their origin server timestamp.
|
|
230
|
+
*
|
|
231
|
+
* @param a - A room event
|
|
232
|
+
* @param b - A room event
|
|
233
|
+
* @returns Either zero if the timestamp is equal, \>0 if a is newer, or \<0 if
|
|
234
|
+
* b is newer.
|
|
208
235
|
*/
|
|
209
|
-
function
|
|
210
|
-
|
|
211
|
-
if (options === void 0) { options = {}; }
|
|
212
|
-
var pathName = options.pathName, _j = options.includeParameters, includeParameters = _j === void 0 ? true : _j, widgetParameters = options.widgetParameters;
|
|
213
|
-
// don't forward widgetId and parentUrl as they will be generated by the client
|
|
214
|
-
var _k = extractRawWidgetParameters(); _k.widgetId; _k.parentUrl; var rawWidgetParameters = __rest(_k, ["widgetId", "parentUrl"]);
|
|
215
|
-
var parameters = Object.entries(__assign(__assign({}, rawWidgetParameters), { theme: (_a = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.theme) !== null && _a !== void 0 ? _a : '$org.matrix.msc2873.client_theme', matrix_user_id: (_b = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.userId) !== null && _b !== void 0 ? _b : '$matrix_user_id', matrix_display_name: (_c = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.displayName) !== null && _c !== void 0 ? _c : '$matrix_display_name', matrix_avatar_url: (_d = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.avatarUrl) !== null && _d !== void 0 ? _d : '$matrix_avatar_url', matrix_room_id: (_e = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.roomId) !== null && _e !== void 0 ? _e : '$matrix_room_id', matrix_client_id: (_f = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.clientId) !== null && _f !== void 0 ? _f : '$org.matrix.msc2873.client_id', matrix_client_language: (_g = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.clientLanguage) !== null && _g !== void 0 ? _g : '$org.matrix.msc2873.client_language', matrix_base_url: (_h = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.baseUrl) !== null && _h !== void 0 ? _h : '$org.matrix.msc4039.matrix_base_url' }))
|
|
216
|
-
.map(function (_a) {
|
|
217
|
-
var k = _a[0], v = _a[1];
|
|
218
|
-
return "".concat(k, "=").concat(v);
|
|
219
|
-
})
|
|
220
|
-
.join('&');
|
|
221
|
-
var url = new URL(window.location.href);
|
|
222
|
-
if (pathName) {
|
|
223
|
-
url.pathname = pathName;
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
// ensure trailing '/'
|
|
227
|
-
url.pathname = url.pathname.replace(/\/?$/, '/');
|
|
228
|
-
}
|
|
229
|
-
url.search = '';
|
|
230
|
-
url.hash = includeParameters ? "#/?".concat(parameters) : '';
|
|
231
|
-
return url.toString();
|
|
232
|
-
}
|
|
233
|
-
var STATE_EVENT_WIDGETS = 'im.vector.modular.widgets';
|
|
234
|
-
/**
|
|
235
|
-
* Repair/configure the registration of the current widget.
|
|
236
|
-
* This steps make sure to include all the required widget parameters in the
|
|
237
|
-
* URL. Support setting a widget name and additional parameters.
|
|
238
|
-
*
|
|
239
|
-
* @param widgetApi - The widget api of the current widget.
|
|
240
|
-
* @param registration - Optional configuration options for the widget
|
|
241
|
-
* registration, like the display name of the widget.
|
|
242
|
-
*/
|
|
243
|
-
function repairWidgetRegistration(widgetApi, registration) {
|
|
244
|
-
if (registration === void 0) { registration = {}; }
|
|
245
|
-
return __awaiter$3(this, void 0, void 0, function () {
|
|
246
|
-
var readResult, url, name, type, data;
|
|
247
|
-
return __generator$3(this, function (_a) {
|
|
248
|
-
switch (_a.label) {
|
|
249
|
-
case 0: return [4 /*yield*/, widgetApi.requestCapabilities([
|
|
250
|
-
matrixWidgetApi.WidgetEventCapability.forStateEvent(matrixWidgetApi.EventDirection.Send, STATE_EVENT_WIDGETS, widgetApi.widgetId),
|
|
251
|
-
matrixWidgetApi.WidgetEventCapability.forStateEvent(matrixWidgetApi.EventDirection.Receive, STATE_EVENT_WIDGETS, widgetApi.widgetId),
|
|
252
|
-
])];
|
|
253
|
-
case 1:
|
|
254
|
-
_a.sent();
|
|
255
|
-
return [4 /*yield*/, widgetApi.receiveSingleStateEvent(STATE_EVENT_WIDGETS, widgetApi.widgetId)];
|
|
256
|
-
case 2:
|
|
257
|
-
readResult = _a.sent();
|
|
258
|
-
if (!readResult) {
|
|
259
|
-
throw new Error("Error while repairing registration, can't find existing registration.");
|
|
260
|
-
}
|
|
261
|
-
url = generateWidgetRegistrationUrl();
|
|
262
|
-
name = registration.name &&
|
|
263
|
-
(!readResult.content.name ||
|
|
264
|
-
readResult.content.name === 'Custom Widget' ||
|
|
265
|
-
readResult.content.name === 'Custom')
|
|
266
|
-
? registration.name
|
|
267
|
-
: readResult.content.name;
|
|
268
|
-
type = registration.type &&
|
|
269
|
-
(!readResult.content.type || readResult.content.type === 'm.custom')
|
|
270
|
-
? registration.type
|
|
271
|
-
: readResult.content.type;
|
|
272
|
-
data = registration.data
|
|
273
|
-
? __assign(__assign({}, readResult.content.data), registration.data) : readResult.content.data;
|
|
274
|
-
// This is a workaround because changing the widget config is breaking the
|
|
275
|
-
// widget API communication. However we need to fail in case the power level
|
|
276
|
-
// for this change is missing. As the error happens quite fast, we just wait
|
|
277
|
-
// a moment and then consider the operation as succeeded.
|
|
278
|
-
return [4 /*yield*/, Promise.race([
|
|
279
|
-
widgetApi.sendStateEvent(STATE_EVENT_WIDGETS, __assign(__assign({}, readResult.content), { url: url.toString(), name: name, type: type, data: data }), { stateKey: widgetApi.widgetId }),
|
|
280
|
-
new Promise(function (resolve) { return setTimeout(resolve, 1000); }),
|
|
281
|
-
])];
|
|
282
|
-
case 3:
|
|
283
|
-
// This is a workaround because changing the widget config is breaking the
|
|
284
|
-
// widget API communication. However we need to fail in case the power level
|
|
285
|
-
// for this change is missing. As the error happens quite fast, we just wait
|
|
286
|
-
// a moment and then consider the operation as succeeded.
|
|
287
|
-
_a.sent();
|
|
288
|
-
return [2 /*return*/];
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
});
|
|
236
|
+
function compareOriginServerTS(a, b) {
|
|
237
|
+
return a.origin_server_ts - b.origin_server_ts;
|
|
292
238
|
}
|
|
293
239
|
|
|
294
240
|
/*
|
|
@@ -306,838 +252,674 @@ function repairWidgetRegistration(widgetApi, registration) {
|
|
|
306
252
|
* See the License for the specific language governing permissions and
|
|
307
253
|
* limitations under the License.
|
|
308
254
|
*/
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
function unique(items) {
|
|
316
|
-
return Array.from(new Set(items));
|
|
255
|
+
/**
|
|
256
|
+
* The name of the power levels state event.
|
|
257
|
+
*/
|
|
258
|
+
var STATE_EVENT_POWER_LEVELS = 'm.room.power_levels';
|
|
259
|
+
function isNumberOrUndefined(value) {
|
|
260
|
+
return value === undefined || typeof value === 'number';
|
|
317
261
|
}
|
|
318
|
-
function
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
262
|
+
function isStringToNumberMapOrUndefined(value) {
|
|
263
|
+
return (value === undefined ||
|
|
264
|
+
(value !== null &&
|
|
265
|
+
typeof value === 'object' &&
|
|
266
|
+
Object.entries(value).every(function (_a) {
|
|
267
|
+
var k = _a[0], v = _a[1];
|
|
268
|
+
return typeof k === 'string' && typeof v === 'number';
|
|
269
|
+
})));
|
|
322
270
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
271
|
+
/**
|
|
272
|
+
* Validates that `event` is has a valid structure for a
|
|
273
|
+
* {@link PowerLevelsStateEvent}.
|
|
274
|
+
* @param event - The event to validate.
|
|
275
|
+
* @returns True, if the event is valid.
|
|
276
|
+
*/
|
|
277
|
+
function isValidPowerLevelStateEvent(event) {
|
|
278
|
+
if (event.type !== STATE_EVENT_POWER_LEVELS ||
|
|
279
|
+
typeof event.content !== 'object') {
|
|
280
|
+
return false;
|
|
326
281
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
return true;
|
|
282
|
+
var content = event.content;
|
|
283
|
+
if (!isStringToNumberMapOrUndefined(content.events)) {
|
|
284
|
+
return false;
|
|
332
285
|
}
|
|
333
|
-
|
|
286
|
+
if (!isNumberOrUndefined(content.state_default)) {
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
if (!isNumberOrUndefined(content.events_default)) {
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
if (!isStringToNumberMapOrUndefined(content.users)) {
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
if (!isNumberOrUndefined(content.users_default)) {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
if (!isNumberOrUndefined(content.ban)) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
if (!isNumberOrUndefined(content.invite)) {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
if (!isNumberOrUndefined(content.kick)) {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
if (!isNumberOrUndefined(content.redact)) {
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
return true;
|
|
334
311
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
* Copyright 2022 Nordeck IT + Consulting GmbH
|
|
338
|
-
*
|
|
339
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
340
|
-
* you may not use this file except in compliance with the License.
|
|
341
|
-
* You may obtain a copy of the License at
|
|
342
|
-
*
|
|
343
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
312
|
+
/**
|
|
313
|
+
* Check if a user has the power to send a specific room event.
|
|
344
314
|
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
* limitations under the License.
|
|
315
|
+
* @param powerLevelStateEvent - the content of the `m.room.power_levels` event
|
|
316
|
+
* @param userId - the id of the user
|
|
317
|
+
* @param eventType - the type of room event
|
|
318
|
+
* @returns if true, the user has the power
|
|
350
319
|
*/
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
356
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
357
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
358
|
-
});
|
|
359
|
-
};
|
|
360
|
-
var __generator$2 = (undefined && undefined.__generator) || function (thisArg, body) {
|
|
361
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
362
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
363
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
364
|
-
function step(op) {
|
|
365
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
366
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
367
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
368
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
369
|
-
switch (op[0]) {
|
|
370
|
-
case 0: case 1: t = op; break;
|
|
371
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
372
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
373
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
374
|
-
default:
|
|
375
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
376
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
377
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
378
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
379
|
-
if (t[2]) _.ops.pop();
|
|
380
|
-
_.trys.pop(); continue;
|
|
381
|
-
}
|
|
382
|
-
op = body.call(thisArg, _);
|
|
383
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
384
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
320
|
+
function hasRoomEventPower(powerLevelStateEvent, userId, eventType) {
|
|
321
|
+
if (!powerLevelStateEvent) {
|
|
322
|
+
// See https://github.com/matrix-org/matrix-spec/blob/203b9756f52adfc2a3b63d664f18cdbf9f8bf126/data/event-schemas/schema/m.room.power_levels.yaml#L36-L43
|
|
323
|
+
return true;
|
|
385
324
|
}
|
|
386
|
-
|
|
387
|
-
var
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
325
|
+
var userLevel = calculateUserPowerLevel(powerLevelStateEvent, userId);
|
|
326
|
+
var eventLevel = calculateRoomEventPowerLevel(powerLevelStateEvent, eventType);
|
|
327
|
+
return userLevel >= eventLevel;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Check if a user has the power to send a specific state event.
|
|
331
|
+
*
|
|
332
|
+
* @param powerLevelStateEvent - the content of the `m.room.power_levels` event
|
|
333
|
+
* @param userId - the id of the user
|
|
334
|
+
* @param eventType - the type of state event
|
|
335
|
+
* @returns if true, the user has the power
|
|
336
|
+
*/
|
|
337
|
+
function hasStateEventPower(powerLevelStateEvent, userId, eventType) {
|
|
338
|
+
if (!powerLevelStateEvent) {
|
|
339
|
+
// See https://github.com/matrix-org/matrix-spec/blob/203b9756f52adfc2a3b63d664f18cdbf9f8bf126/data/event-schemas/schema/m.room.power_levels.yaml#L36-L43
|
|
340
|
+
return true;
|
|
393
341
|
}
|
|
394
|
-
|
|
395
|
-
|
|
342
|
+
var userLevel = calculateUserPowerLevel(powerLevelStateEvent, userId);
|
|
343
|
+
var eventLevel = calculateStateEventPowerLevel(powerLevelStateEvent, eventType);
|
|
344
|
+
return userLevel >= eventLevel;
|
|
345
|
+
}
|
|
396
346
|
/**
|
|
397
|
-
*
|
|
347
|
+
* Check if a user has the power to perform a specific action.
|
|
398
348
|
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
349
|
+
* Supported actions:
|
|
350
|
+
* * invite: Invite a new user into the room
|
|
351
|
+
* * kick: Kick a user from the room
|
|
352
|
+
* * ban: Ban a user from the room
|
|
353
|
+
* * redact: Redact a message from another user
|
|
354
|
+
*
|
|
355
|
+
* @param powerLevelStateEvent - the content of the `m.room.power_levels` event
|
|
356
|
+
* @param userId - the id of the user
|
|
357
|
+
* @param action - the action
|
|
358
|
+
* @returns if true, the user has the power
|
|
401
359
|
*/
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
360
|
+
function hasActionPower(powerLevelStateEvent, userId, action) {
|
|
361
|
+
if (!powerLevelStateEvent) {
|
|
362
|
+
// See https://github.com/matrix-org/matrix-spec/blob/203b9756f52adfc2a3b63d664f18cdbf9f8bf126/data/event-schemas/schema/m.room.power_levels.yaml#L36-L43
|
|
363
|
+
return true;
|
|
364
|
+
}
|
|
365
|
+
var userLevel = calculateUserPowerLevel(powerLevelStateEvent, userId);
|
|
366
|
+
var eventLevel = calculateActionPowerLevel(powerLevelStateEvent, action);
|
|
367
|
+
return userLevel >= eventLevel;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Calculate the power level of the user based on a `m.room.power_levels` event.
|
|
371
|
+
*
|
|
372
|
+
* @param powerLevelStateEvent - the content of the `m.room.power_levels` event.
|
|
373
|
+
* @param userId - the ID of the user.
|
|
374
|
+
* @returns the power level of the user.
|
|
375
|
+
*/
|
|
376
|
+
function calculateUserPowerLevel(powerLevelStateEvent, userId) {
|
|
377
|
+
var _a, _b, _c;
|
|
378
|
+
// See https://github.com/matrix-org/matrix-spec/blob/203b9756f52adfc2a3b63d664f18cdbf9f8bf126/data/event-schemas/schema/m.room.power_levels.yaml#L8-L12
|
|
379
|
+
return ((_c = (_b = (userId ? (_a = powerLevelStateEvent.users) === null || _a === void 0 ? void 0 : _a[userId] : undefined)) !== null && _b !== void 0 ? _b : powerLevelStateEvent.users_default) !== null && _c !== void 0 ? _c : 0);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Calculate the power level that a user needs send a specific room event.
|
|
383
|
+
*
|
|
384
|
+
* @param powerLevelStateEvent - the content of the `m.room.power_levels` event
|
|
385
|
+
* @param eventType - the type of room event
|
|
386
|
+
* @returns the power level that is needed
|
|
387
|
+
*/
|
|
388
|
+
function calculateRoomEventPowerLevel(powerLevelStateEvent, eventType) {
|
|
389
|
+
var _a, _b, _c;
|
|
390
|
+
// See https://github.com/matrix-org/matrix-spec/blob/203b9756f52adfc2a3b63d664f18cdbf9f8bf126/data/event-schemas/schema/m.room.power_levels.yaml#L14-L19
|
|
391
|
+
return ((_c = (_b = (_a = powerLevelStateEvent.events) === null || _a === void 0 ? void 0 : _a[eventType]) !== null && _b !== void 0 ? _b : powerLevelStateEvent.events_default) !== null && _c !== void 0 ? _c : 0);
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Calculate the power level that a user needs send a specific state event.
|
|
395
|
+
*
|
|
396
|
+
* @param powerLevelStateEvent - the content of the `m.room.power_levels` event
|
|
397
|
+
* @param eventType - the type of state event
|
|
398
|
+
* @returns the power level that is needed
|
|
399
|
+
*/
|
|
400
|
+
function calculateStateEventPowerLevel(powerLevelStateEvent, eventType) {
|
|
401
|
+
var _a, _b, _c;
|
|
402
|
+
// See https://github.com/matrix-org/matrix-spec/blob/203b9756f52adfc2a3b63d664f18cdbf9f8bf126/data/event-schemas/schema/m.room.power_levels.yaml#L14-L19
|
|
403
|
+
return ((_c = (_b = (_a = powerLevelStateEvent.events) === null || _a === void 0 ? void 0 : _a[eventType]) !== null && _b !== void 0 ? _b : powerLevelStateEvent.state_default) !== null && _c !== void 0 ? _c : 50);
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Calculate the power level that a user needs to perform an action.
|
|
407
|
+
*
|
|
408
|
+
* Supported actions:
|
|
409
|
+
* * invite: Invite a new user into the room
|
|
410
|
+
* * kick: Kick a user from the room
|
|
411
|
+
* * ban: Ban a user from the room
|
|
412
|
+
* * redact: Redact a message from another user
|
|
413
|
+
*
|
|
414
|
+
* @param powerLevelStateEvent - the content of the `m.room.power_levels` event
|
|
415
|
+
* @param action - the action
|
|
416
|
+
* @returns the power level that is needed
|
|
417
|
+
*/
|
|
418
|
+
function calculateActionPowerLevel(powerLevelStateEvent, action) {
|
|
419
|
+
var _a, _b;
|
|
420
|
+
// See https://github.com/matrix-org/matrix-spec/blob/203b9756f52adfc2a3b63d664f18cdbf9f8bf126/data/event-schemas/schema/m.room.power_levels.yaml#L27-L32
|
|
421
|
+
if (action === 'invite') {
|
|
422
|
+
return (_a = powerLevelStateEvent === null || powerLevelStateEvent === void 0 ? void 0 : powerLevelStateEvent[action]) !== null && _a !== void 0 ? _a : 0;
|
|
423
|
+
}
|
|
424
|
+
return (_b = powerLevelStateEvent === null || powerLevelStateEvent === void 0 ? void 0 : powerLevelStateEvent[action]) !== null && _b !== void 0 ? _b : 50;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/*
|
|
428
|
+
* Copyright 2022 Nordeck IT + Consulting GmbH
|
|
429
|
+
*
|
|
430
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
431
|
+
* you may not use this file except in compliance with the License.
|
|
432
|
+
* You may obtain a copy of the License at
|
|
433
|
+
*
|
|
434
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
435
|
+
*
|
|
436
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
437
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
438
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
439
|
+
* See the License for the specific language governing permissions and
|
|
440
|
+
* limitations under the License.
|
|
441
|
+
*/
|
|
442
|
+
var __awaiter$2 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
443
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
444
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
445
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
446
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
447
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
448
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
449
|
+
});
|
|
450
|
+
};
|
|
451
|
+
var __generator$2 = (undefined && undefined.__generator) || function (thisArg, body) {
|
|
452
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
453
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
454
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
455
|
+
function step(op) {
|
|
456
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
457
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
458
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
459
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
460
|
+
switch (op[0]) {
|
|
461
|
+
case 0: case 1: t = op; break;
|
|
462
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
463
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
464
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
465
|
+
default:
|
|
466
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
467
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
468
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
469
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
470
|
+
if (t[2]) _.ops.pop();
|
|
471
|
+
_.trys.pop(); continue;
|
|
438
472
|
}
|
|
439
|
-
|
|
440
|
-
}
|
|
441
|
-
|
|
473
|
+
op = body.call(thisArg, _);
|
|
474
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
475
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
442
476
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
477
|
+
};
|
|
478
|
+
/**
|
|
479
|
+
* The name of the redaction room event.
|
|
480
|
+
*/
|
|
481
|
+
var ROOM_EVENT_REDACTION = 'm.room.redaction';
|
|
482
|
+
/**
|
|
483
|
+
* Check whether the format of a redaction event is valid.
|
|
484
|
+
* @param event - The event to check.
|
|
485
|
+
* @returns True if the event format is valid, otherwise false.
|
|
486
|
+
*/
|
|
487
|
+
function isValidRedactionEvent(event) {
|
|
488
|
+
if (event.type === ROOM_EVENT_REDACTION &&
|
|
489
|
+
typeof event.redacts === 'string') {
|
|
490
|
+
return true;
|
|
491
|
+
}
|
|
492
|
+
return false;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Redacts an event in the current room.
|
|
496
|
+
* @param widgetApi - An instance of the widget API.
|
|
497
|
+
* @param eventId - The id of the event to redact.
|
|
498
|
+
* @returns The redaction event that was send to the room.
|
|
499
|
+
*/
|
|
500
|
+
function redactEvent(widgetApi, eventId) {
|
|
501
|
+
return __awaiter$2(this, void 0, void 0, function () {
|
|
502
|
+
var result;
|
|
503
|
+
return __generator$2(this, function (_a) {
|
|
504
|
+
switch (_a.label) {
|
|
505
|
+
case 0: return [4 /*yield*/, widgetApi.sendRoomEvent(ROOM_EVENT_REDACTION, { redacts: eventId })];
|
|
506
|
+
case 1:
|
|
507
|
+
result = _a.sent();
|
|
508
|
+
// The redaction event is special and needs to be casted, as the widget
|
|
509
|
+
// toolkit assumes that the content of an event is returned as we send it.
|
|
510
|
+
// However for redactions the content is copied directly into the event to
|
|
511
|
+
// make it available without decrypting the content.
|
|
512
|
+
return [2 /*return*/, result];
|
|
513
|
+
}
|
|
472
514
|
});
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Observes redaction events in the current room.
|
|
519
|
+
* @param widgetApi - An instance of the widget API.
|
|
520
|
+
* @returns An observable of validated redaction events.
|
|
521
|
+
*/
|
|
522
|
+
function observeRedactionEvents(widgetApi) {
|
|
523
|
+
return widgetApi
|
|
524
|
+
.observeRoomEvents(ROOM_EVENT_REDACTION)
|
|
525
|
+
.pipe(rxjs.filter(isValidRedactionEvent));
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/*
|
|
529
|
+
* Copyright 2022 Nordeck IT + Consulting GmbH
|
|
530
|
+
*
|
|
531
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
532
|
+
* you may not use this file except in compliance with the License.
|
|
533
|
+
* You may obtain a copy of the License at
|
|
534
|
+
*
|
|
535
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
536
|
+
*
|
|
537
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
538
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
539
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
540
|
+
* See the License for the specific language governing permissions and
|
|
541
|
+
* limitations under the License.
|
|
542
|
+
*/
|
|
543
|
+
/**
|
|
544
|
+
* Get the original event id, or the event id of the current event if it
|
|
545
|
+
* doesn't relates to another event.
|
|
546
|
+
* @param event - The room event.
|
|
547
|
+
* @returns The event id of the original event, or the current event id.
|
|
548
|
+
*/
|
|
549
|
+
function getOriginalEventId(event) {
|
|
550
|
+
var _a, _b, _c;
|
|
551
|
+
var newContentRelatesTo = event.content;
|
|
552
|
+
if (((_a = newContentRelatesTo['m.relates_to']) === null || _a === void 0 ? void 0 : _a.rel_type) === 'm.replace') {
|
|
553
|
+
return (_c = (_b = newContentRelatesTo['m.relates_to']) === null || _b === void 0 ? void 0 : _b.event_id) !== null && _c !== void 0 ? _c : event.event_id;
|
|
554
|
+
}
|
|
555
|
+
return event.event_id;
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Get the content of the event, independent from whether it contains the
|
|
559
|
+
* content directly or contains a "m.new_content" key.
|
|
560
|
+
* @param event - The room event.
|
|
561
|
+
* @returns Only the content of the room event.
|
|
562
|
+
*/
|
|
563
|
+
function getContent(event) {
|
|
564
|
+
var _a;
|
|
565
|
+
var newContentRelatesTo = event.content;
|
|
566
|
+
return (_a = newContentRelatesTo['m.new_content']) !== null && _a !== void 0 ? _a : event.content;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Validates that `event` has a valid structure for a
|
|
570
|
+
* {@link EventWithRelatesTo}.
|
|
571
|
+
* @param event - The event to validate.
|
|
572
|
+
* @returns True, if the event is valid.
|
|
573
|
+
*/
|
|
574
|
+
function isValidEventWithRelatesTo(event) {
|
|
575
|
+
if (!event.content || typeof event.content !== 'object') {
|
|
576
|
+
return false;
|
|
577
|
+
}
|
|
578
|
+
var relatedEvent = event;
|
|
579
|
+
if (!relatedEvent.content['m.relates_to'] ||
|
|
580
|
+
typeof relatedEvent.content['m.relates_to'] !== 'object') {
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
if (typeof relatedEvent.content['m.relates_to'].rel_type !== 'string' ||
|
|
584
|
+
typeof relatedEvent.content['m.relates_to'].event_id !== 'string') {
|
|
585
|
+
return false;
|
|
586
|
+
}
|
|
587
|
+
return true;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/*
|
|
591
|
+
* Copyright 2022 Nordeck IT + Consulting GmbH
|
|
592
|
+
*
|
|
593
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
594
|
+
* you may not use this file except in compliance with the License.
|
|
595
|
+
* You may obtain a copy of the License at
|
|
596
|
+
*
|
|
597
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
598
|
+
*
|
|
599
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
600
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
601
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
602
|
+
* See the License for the specific language governing permissions and
|
|
603
|
+
* limitations under the License.
|
|
604
|
+
*/
|
|
605
|
+
/**
|
|
606
|
+
* The name of the room member state event.
|
|
607
|
+
*/
|
|
608
|
+
var STATE_EVENT_ROOM_MEMBER = 'm.room.member';
|
|
609
|
+
function isStringUndefinedOrNull(value) {
|
|
610
|
+
return value === undefined || value === null || typeof value === 'string';
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Validates that `event` is has a valid structure for a
|
|
614
|
+
* {@link RoomMemberStateEventContent}.
|
|
615
|
+
* @param event - The event to validate.
|
|
616
|
+
* @returns True, if the event is valid.
|
|
617
|
+
*/
|
|
618
|
+
function isValidRoomMemberStateEvent(event) {
|
|
619
|
+
if (event.type !== STATE_EVENT_ROOM_MEMBER ||
|
|
620
|
+
typeof event.content !== 'object') {
|
|
621
|
+
return false;
|
|
622
|
+
}
|
|
623
|
+
var content = event.content;
|
|
624
|
+
if (typeof content.membership !== 'string') {
|
|
625
|
+
return false;
|
|
626
|
+
}
|
|
627
|
+
if (!isStringUndefinedOrNull(content.displayname)) {
|
|
628
|
+
return false;
|
|
629
|
+
}
|
|
630
|
+
// the avatar_url shouldn't be null, but some implementations
|
|
631
|
+
// set it as a valid value
|
|
632
|
+
if (!isStringUndefinedOrNull(content.avatar_url)) {
|
|
633
|
+
return false;
|
|
634
|
+
}
|
|
635
|
+
return true;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/*
|
|
639
|
+
* Copyright 2022 Nordeck IT + Consulting GmbH
|
|
640
|
+
*
|
|
641
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
642
|
+
* you may not use this file except in compliance with the License.
|
|
643
|
+
* You may obtain a copy of the License at
|
|
644
|
+
*
|
|
645
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
646
|
+
*
|
|
647
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
648
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
649
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
650
|
+
* See the License for the specific language governing permissions and
|
|
651
|
+
* limitations under the License.
|
|
652
|
+
*/
|
|
653
|
+
var __assign$1 = (undefined && undefined.__assign) || function () {
|
|
654
|
+
__assign$1 = Object.assign || function(t) {
|
|
655
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
656
|
+
s = arguments[i];
|
|
657
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
658
|
+
t[p] = s[p];
|
|
659
|
+
}
|
|
660
|
+
return t;
|
|
473
661
|
};
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
}
|
|
530
|
-
});
|
|
531
|
-
});
|
|
532
|
-
};
|
|
533
|
-
/** {@inheritDoc WidgetApi.getWidgetConfig} */
|
|
534
|
-
WidgetApiImpl.prototype.getWidgetConfig = function () {
|
|
535
|
-
return this.widgetConfig;
|
|
536
|
-
};
|
|
537
|
-
/** {@inheritDoc WidgetApi.rerequestInitialCapabilities} */
|
|
538
|
-
WidgetApiImpl.prototype.rerequestInitialCapabilities = function () {
|
|
539
|
-
return __awaiter$2(this, void 0, void 0, function () {
|
|
540
|
-
return __generator$2(this, function (_a) {
|
|
541
|
-
switch (_a.label) {
|
|
542
|
-
case 0: return [4 /*yield*/, this.requestCapabilities(this.initialCapabilities)];
|
|
543
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
544
|
-
}
|
|
545
|
-
});
|
|
546
|
-
});
|
|
662
|
+
return __assign$1.apply(this, arguments);
|
|
663
|
+
};
|
|
664
|
+
/**
|
|
665
|
+
* Extract the parameters used to initialize the widget API from the current
|
|
666
|
+
* `window.location`.
|
|
667
|
+
* @returns The parameters required for initializing the widget API.
|
|
668
|
+
*/
|
|
669
|
+
function extractWidgetApiParameters() {
|
|
670
|
+
var query = qs.parse(window.location.search, { ignoreQueryPrefix: true });
|
|
671
|
+
// If either parentUrl or widgetId is missing, we have no element context and
|
|
672
|
+
// want to inform the user that the widget only works inside of element.
|
|
673
|
+
if (typeof query.parentUrl !== 'string') {
|
|
674
|
+
throw Error('Missing parameter "parentUrl"');
|
|
675
|
+
}
|
|
676
|
+
var clientOrigin = new URL(query.parentUrl).origin;
|
|
677
|
+
if (typeof query.widgetId !== 'string') {
|
|
678
|
+
throw Error('Missing parameter "widgetId"');
|
|
679
|
+
}
|
|
680
|
+
var widgetId = query.widgetId;
|
|
681
|
+
return { widgetId: widgetId, clientOrigin: clientOrigin };
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Extract the widget parameters from the current `window.location`.
|
|
685
|
+
* @returns The all unprocessed raw widget parameters.
|
|
686
|
+
*/
|
|
687
|
+
function extractRawWidgetParameters() {
|
|
688
|
+
var hash = window.location.hash.substring(window.location.hash.indexOf('?') + 1);
|
|
689
|
+
var params = __assign$1(__assign$1({}, qs.parse(window.location.search, { ignoreQueryPrefix: true })), qs.parse(hash));
|
|
690
|
+
return Object.fromEntries(Object.entries(params).filter(
|
|
691
|
+
// For now only use simple values, don't allow them to be specified more
|
|
692
|
+
// than once.
|
|
693
|
+
function (e) { return typeof e[1] === 'string'; }));
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Extract the widget parameters from the current `window.location`.
|
|
697
|
+
* @returns The widget parameters.
|
|
698
|
+
*/
|
|
699
|
+
function extractWidgetParameters() {
|
|
700
|
+
var params = extractRawWidgetParameters();
|
|
701
|
+
// This is a hack to detect whether we are in a mobile client that supports widgets,
|
|
702
|
+
// but not the widget API. Mobile clients are not passing the parameters required for
|
|
703
|
+
// the widget API (like widgetId), but are passing the replaced placeholder values for
|
|
704
|
+
// the widget parameters.
|
|
705
|
+
var roomId = params['matrix_room_id'];
|
|
706
|
+
var isOpenedByClient = typeof roomId === 'string' && roomId !== '$matrix_room_id';
|
|
707
|
+
return {
|
|
708
|
+
userId: params['matrix_user_id'],
|
|
709
|
+
displayName: params['matrix_display_name'],
|
|
710
|
+
avatarUrl: params['matrix_avatar_url'],
|
|
711
|
+
roomId: roomId,
|
|
712
|
+
theme: params['theme'],
|
|
713
|
+
clientId: params['matrix_client_id'],
|
|
714
|
+
clientLanguage: params['matrix_client_language'],
|
|
715
|
+
baseUrl: params['matrix_base_url'],
|
|
716
|
+
isOpenedByClient: isOpenedByClient,
|
|
547
717
|
};
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* Parse a widget id into the individual fields.
|
|
721
|
+
* @param widgetId - The widget id to parse.
|
|
722
|
+
* @returns The individual fields encoded inside a widget id.
|
|
723
|
+
*/
|
|
724
|
+
function parseWidgetId(widgetId) {
|
|
725
|
+
// TODO: Is this whole parsing still working for user widgets?
|
|
726
|
+
var mainWidgetId = decodeURIComponent(widgetId).replace(/^modal_/, '');
|
|
727
|
+
var roomId = mainWidgetId.indexOf('_')
|
|
728
|
+
? decodeURIComponent(mainWidgetId.split('_')[0])
|
|
729
|
+
: undefined;
|
|
730
|
+
var creator = (mainWidgetId.match(/_/g) || []).length > 1
|
|
731
|
+
? decodeURIComponent(mainWidgetId.split('_')[1])
|
|
732
|
+
: undefined;
|
|
733
|
+
var isModal = decodeURIComponent(widgetId).startsWith('modal_');
|
|
734
|
+
return {
|
|
735
|
+
mainWidgetId: mainWidgetId,
|
|
736
|
+
roomId: roomId,
|
|
737
|
+
creator: creator,
|
|
738
|
+
isModal: isModal,
|
|
551
739
|
};
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
_b.sent();
|
|
576
|
-
return [3 /*break*/, 7];
|
|
577
|
-
case 6:
|
|
578
|
-
this.outstandingCapabilitiesRequest = undefined;
|
|
579
|
-
return [7 /*endfinally*/];
|
|
580
|
-
case 7: return [2 /*return*/];
|
|
581
|
-
}
|
|
582
|
-
});
|
|
583
|
-
});
|
|
584
|
-
};
|
|
585
|
-
WidgetApiImpl.prototype.requestCapabilitiesInternal = function (capabilities) {
|
|
586
|
-
return __awaiter$2(this, void 0, void 0, function () {
|
|
587
|
-
var rawCapabilities, requestedSet, capabilities$;
|
|
588
|
-
var _this = this;
|
|
589
|
-
return __generator$2(this, function (_a) {
|
|
590
|
-
switch (_a.label) {
|
|
591
|
-
case 0:
|
|
592
|
-
rawCapabilities = unique(convertToRawCapabilities(capabilities));
|
|
593
|
-
// Take shortcut if possible, that avoid extra roundtrips over the API.
|
|
594
|
-
if (this.hasCapabilities(rawCapabilities)) {
|
|
595
|
-
return [2 /*return*/];
|
|
596
|
-
}
|
|
597
|
-
requestedSet = new Set(rawCapabilities);
|
|
598
|
-
capabilities$ = rxjs.fromEvent(this.matrixWidgetApi, "action:".concat(matrixWidgetApi.WidgetApiToWidgetAction.NotifyCapabilities), function (ev) { return ev; }).pipe(
|
|
599
|
-
// TODO: `hasCapability` in the matrix-widget-api isn't consistent when capability
|
|
600
|
-
// upgrades happened. But `updateRequestedCapabilities` will deduplicate already
|
|
601
|
-
// approved capabilities, so the the `requested` field will be inconsistent.
|
|
602
|
-
// If we would enable this check, the function will never resolve. This should
|
|
603
|
-
// be reactivated once the capability upgrade is working correctly. See also:
|
|
604
|
-
// https://github.com/matrix-org/matrix-widget-api/issues/52
|
|
605
|
-
// Ignore events from other parallel capability requests
|
|
606
|
-
//filter((ev) =>
|
|
607
|
-
// equalsSet(new Set(ev.detail.data.requested), requestedSet)
|
|
608
|
-
//),
|
|
609
|
-
rxjs.map(function (ev) {
|
|
610
|
-
var approvedSet = new Set(ev.detail.data.approved);
|
|
611
|
-
var missingSet = subtractSet(requestedSet, approvedSet);
|
|
612
|
-
if (missingSet.size > 0) {
|
|
613
|
-
throw new Error("Capabilities rejected: ".concat(Array.from(missingSet).join(', ')));
|
|
614
|
-
}
|
|
615
|
-
}), rxjs.first());
|
|
616
|
-
return [4 /*yield*/, new Promise(function (resolve, reject) { return __awaiter$2(_this, void 0, void 0, function () {
|
|
617
|
-
var subscription, err_1;
|
|
618
|
-
return __generator$2(this, function (_a) {
|
|
619
|
-
switch (_a.label) {
|
|
620
|
-
case 0:
|
|
621
|
-
subscription = capabilities$.subscribe({
|
|
622
|
-
next: resolve,
|
|
623
|
-
error: reject,
|
|
624
|
-
});
|
|
625
|
-
_a.label = 1;
|
|
626
|
-
case 1:
|
|
627
|
-
_a.trys.push([1, 3, , 4]);
|
|
628
|
-
this.matrixWidgetApi.requestCapabilities(rawCapabilities);
|
|
629
|
-
return [4 /*yield*/, this.matrixWidgetApi.updateRequestedCapabilities()];
|
|
630
|
-
case 2:
|
|
631
|
-
_a.sent();
|
|
632
|
-
return [3 /*break*/, 4];
|
|
633
|
-
case 3:
|
|
634
|
-
err_1 = _a.sent();
|
|
635
|
-
subscription.unsubscribe();
|
|
636
|
-
reject(err_1);
|
|
637
|
-
return [3 /*break*/, 4];
|
|
638
|
-
case 4: return [2 /*return*/];
|
|
639
|
-
}
|
|
640
|
-
});
|
|
641
|
-
}); })];
|
|
642
|
-
case 1:
|
|
643
|
-
_a.sent();
|
|
644
|
-
return [2 /*return*/];
|
|
645
|
-
}
|
|
646
|
-
});
|
|
647
|
-
});
|
|
648
|
-
};
|
|
649
|
-
/** {@inheritDoc WidgetApi.hasCapabilities} */
|
|
650
|
-
WidgetApiImpl.prototype.hasCapabilities = function (capabilities) {
|
|
651
|
-
var _this = this;
|
|
652
|
-
var rawCapabilities = convertToRawCapabilities(capabilities);
|
|
653
|
-
return rawCapabilities.every(function (c) { return _this.matrixWidgetApi.hasCapability(c); });
|
|
654
|
-
};
|
|
655
|
-
/** {@inheritDoc WidgetApi.receiveSingleStateEvent} */
|
|
656
|
-
WidgetApiImpl.prototype.receiveSingleStateEvent = function (eventType, stateKey) {
|
|
657
|
-
if (stateKey === void 0) { stateKey = ''; }
|
|
658
|
-
return __awaiter$2(this, void 0, void 0, function () {
|
|
659
|
-
var events;
|
|
660
|
-
return __generator$2(this, function (_a) {
|
|
661
|
-
switch (_a.label) {
|
|
662
|
-
case 0: return [4 /*yield*/, this.receiveStateEvents(eventType, { stateKey: stateKey })];
|
|
663
|
-
case 1:
|
|
664
|
-
events = _a.sent();
|
|
665
|
-
return [2 /*return*/, events && events[0]];
|
|
666
|
-
}
|
|
667
|
-
});
|
|
668
|
-
});
|
|
669
|
-
};
|
|
670
|
-
/** {@inheritDoc WidgetApi.receiveStateEvents} */
|
|
671
|
-
WidgetApiImpl.prototype.receiveStateEvents = function (eventType, _a) {
|
|
672
|
-
var _b = _a === void 0 ? {} : _a, stateKey = _b.stateKey, roomIds = _b.roomIds;
|
|
673
|
-
return __awaiter$2(this, void 0, void 0, function () {
|
|
674
|
-
return __generator$2(this, function (_c) {
|
|
675
|
-
switch (_c.label) {
|
|
676
|
-
case 0: return [4 /*yield*/, this.matrixWidgetApi.readStateEvents(eventType, Number.MAX_SAFE_INTEGER, stateKey, typeof roomIds === 'string' ? [matrixWidgetApi.Symbols.AnyRoom] : roomIds)];
|
|
677
|
-
case 1: return [2 /*return*/, (_c.sent())];
|
|
678
|
-
}
|
|
679
|
-
});
|
|
680
|
-
});
|
|
681
|
-
};
|
|
682
|
-
/** {@inheritDoc WidgetApi.observeStateEvents} */
|
|
683
|
-
WidgetApiImpl.prototype.observeStateEvents = function (eventType, _a) {
|
|
684
|
-
var _b = _a === void 0 ? {} : _a, stateKey = _b.stateKey, roomIds = _b.roomIds;
|
|
685
|
-
var currentRoomId = this.widgetParameters.roomId;
|
|
686
|
-
if (!currentRoomId) {
|
|
687
|
-
return rxjs.throwError(function () { return new Error('Current room id is unknown'); });
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
/*
|
|
743
|
+
* Copyright 2022 Nordeck IT + Consulting GmbH
|
|
744
|
+
*
|
|
745
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
746
|
+
* you may not use this file except in compliance with the License.
|
|
747
|
+
* You may obtain a copy of the License at
|
|
748
|
+
*
|
|
749
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
750
|
+
*
|
|
751
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
752
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
753
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
754
|
+
* See the License for the specific language governing permissions and
|
|
755
|
+
* limitations under the License.
|
|
756
|
+
*/
|
|
757
|
+
var __assign = (undefined && undefined.__assign) || function () {
|
|
758
|
+
__assign = Object.assign || function(t) {
|
|
759
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
760
|
+
s = arguments[i];
|
|
761
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
762
|
+
t[p] = s[p];
|
|
688
763
|
}
|
|
689
|
-
|
|
690
|
-
var futureEvent$ = this.events$.pipe(rxjs.map(function (event) {
|
|
691
|
-
var matrixEvent = event.detail.data;
|
|
692
|
-
if (matrixEvent.type === eventType &&
|
|
693
|
-
matrixEvent.state_key !== undefined &&
|
|
694
|
-
(stateKey === undefined || matrixEvent.state_key === stateKey) &&
|
|
695
|
-
isInRoom(matrixEvent, currentRoomId, roomIds)) {
|
|
696
|
-
return event.detail.data;
|
|
697
|
-
}
|
|
698
|
-
return undefined;
|
|
699
|
-
}), rxjs.filter(isDefined));
|
|
700
|
-
return rxjs.concat(historyEvent$, futureEvent$);
|
|
701
|
-
};
|
|
702
|
-
/** {@inheritDoc WidgetApi.sendStateEvent} */
|
|
703
|
-
WidgetApiImpl.prototype.sendStateEvent = function (eventType, content, _a) {
|
|
704
|
-
var _b = _a === void 0 ? {} : _a, roomId = _b.roomId, _c = _b.stateKey, stateKey = _c === void 0 ? '' : _c;
|
|
705
|
-
return __awaiter$2(this, void 0, void 0, function () {
|
|
706
|
-
var subject, subscription, _d, event_id_1, room_id_1, event_1;
|
|
707
|
-
return __generator$2(this, function (_e) {
|
|
708
|
-
switch (_e.label) {
|
|
709
|
-
case 0:
|
|
710
|
-
subject = new rxjs.ReplaySubject();
|
|
711
|
-
subscription = this.events$.subscribe(function (e) { return subject.next(e); });
|
|
712
|
-
_e.label = 1;
|
|
713
|
-
case 1:
|
|
714
|
-
_e.trys.push([1, , 4, 5]);
|
|
715
|
-
return [4 /*yield*/, this.matrixWidgetApi.sendStateEvent(eventType, stateKey, content, roomId)];
|
|
716
|
-
case 2:
|
|
717
|
-
_d = _e.sent(), event_id_1 = _d.event_id, room_id_1 = _d.room_id;
|
|
718
|
-
return [4 /*yield*/, rxjs.firstValueFrom(subject.pipe(rxjs.filter(function (event) {
|
|
719
|
-
var matrixEvent = event.detail.data;
|
|
720
|
-
return (matrixEvent.event_id === event_id_1 &&
|
|
721
|
-
matrixEvent.room_id === room_id_1);
|
|
722
|
-
}), rxjs.map(function (event) { return event.detail.data; })))];
|
|
723
|
-
case 3:
|
|
724
|
-
event_1 = _e.sent();
|
|
725
|
-
return [2 /*return*/, event_1];
|
|
726
|
-
case 4:
|
|
727
|
-
subscription.unsubscribe();
|
|
728
|
-
return [7 /*endfinally*/];
|
|
729
|
-
case 5: return [2 /*return*/];
|
|
730
|
-
}
|
|
731
|
-
});
|
|
732
|
-
});
|
|
733
|
-
};
|
|
734
|
-
/** {@inheritDoc WidgetApi.receiveRoomEvents} */
|
|
735
|
-
WidgetApiImpl.prototype.receiveRoomEvents = function (eventType, _a) {
|
|
736
|
-
var _b = _a === void 0 ? {} : _a, messageType = _b.messageType, roomIds = _b.roomIds;
|
|
737
|
-
return __awaiter$2(this, void 0, void 0, function () {
|
|
738
|
-
return __generator$2(this, function (_c) {
|
|
739
|
-
switch (_c.label) {
|
|
740
|
-
case 0: return [4 /*yield*/, this.matrixWidgetApi.readRoomEvents(eventType, Number.MAX_SAFE_INTEGER, messageType, typeof roomIds === 'string' ? [matrixWidgetApi.Symbols.AnyRoom] : roomIds)];
|
|
741
|
-
case 1: return [2 /*return*/, (_c.sent())];
|
|
742
|
-
}
|
|
743
|
-
});
|
|
744
|
-
});
|
|
764
|
+
return t;
|
|
745
765
|
};
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
766
|
+
return __assign.apply(this, arguments);
|
|
767
|
+
};
|
|
768
|
+
var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
769
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
770
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
771
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
772
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
773
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
774
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
775
|
+
});
|
|
776
|
+
};
|
|
777
|
+
var __generator$1 = (undefined && undefined.__generator) || function (thisArg, body) {
|
|
778
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
779
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
780
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
781
|
+
function step(op) {
|
|
782
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
783
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
784
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
785
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
786
|
+
switch (op[0]) {
|
|
787
|
+
case 0: case 1: t = op; break;
|
|
788
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
789
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
790
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
791
|
+
default:
|
|
792
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
793
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
794
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
795
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
796
|
+
if (t[2]) _.ops.pop();
|
|
797
|
+
_.trys.pop(); continue;
|
|
761
798
|
}
|
|
762
|
-
|
|
763
|
-
}),
|
|
764
|
-
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
subscription = this.events$.subscribe(function (e) { return subject.next(e); });
|
|
776
|
-
_d.label = 1;
|
|
777
|
-
case 1:
|
|
778
|
-
_d.trys.push([1, , 4, 5]);
|
|
779
|
-
return [4 /*yield*/, this.matrixWidgetApi.sendRoomEvent(eventType, content, roomId)];
|
|
780
|
-
case 2:
|
|
781
|
-
_c = _d.sent(), event_id_2 = _c.event_id, room_id_2 = _c.room_id;
|
|
782
|
-
return [4 /*yield*/, rxjs.firstValueFrom(subject.pipe(rxjs.filter(function (event) {
|
|
783
|
-
var matrixEvent = event.detail.data;
|
|
784
|
-
return (matrixEvent.event_id === event_id_2 &&
|
|
785
|
-
matrixEvent.room_id === room_id_2);
|
|
786
|
-
}), rxjs.map(function (event) { return event.detail.data; })))];
|
|
787
|
-
case 3:
|
|
788
|
-
event_2 = _d.sent();
|
|
789
|
-
return [2 /*return*/, event_2];
|
|
790
|
-
case 4:
|
|
791
|
-
subscription.unsubscribe();
|
|
792
|
-
return [7 /*endfinally*/];
|
|
793
|
-
case 5: return [2 /*return*/];
|
|
794
|
-
}
|
|
795
|
-
});
|
|
796
|
-
});
|
|
797
|
-
};
|
|
798
|
-
/** {@inheritDoc WidgetApi.readEventRelations} */
|
|
799
|
-
WidgetApiImpl.prototype.readEventRelations = function (eventId, options) {
|
|
800
|
-
return __awaiter$2(this, void 0, void 0, function () {
|
|
801
|
-
var _a, chunk, next_batch;
|
|
802
|
-
return __generator$2(this, function (_b) {
|
|
803
|
-
switch (_b.label) {
|
|
804
|
-
case 0: return [4 /*yield*/, this.matrixWidgetApi.readEventRelations(eventId, options === null || options === void 0 ? void 0 : options.roomId, options === null || options === void 0 ? void 0 : options.relationType, options === null || options === void 0 ? void 0 : options.eventType, options === null || options === void 0 ? void 0 : options.limit, options === null || options === void 0 ? void 0 : options.from, undefined, options === null || options === void 0 ? void 0 : options.direction)];
|
|
805
|
-
case 1:
|
|
806
|
-
_a = _b.sent(), chunk = _a.chunk, next_batch = _a.next_batch;
|
|
807
|
-
return [2 /*return*/, {
|
|
808
|
-
chunk: chunk,
|
|
809
|
-
nextToken: next_batch !== null && next_batch !== void 0 ? next_batch : undefined,
|
|
810
|
-
}];
|
|
811
|
-
}
|
|
812
|
-
});
|
|
813
|
-
});
|
|
814
|
-
};
|
|
815
|
-
/** {@inheritDoc WidgetApi.sendToDeviceMessage} */
|
|
816
|
-
WidgetApiImpl.prototype.sendToDeviceMessage = function (eventType, encrypted, content) {
|
|
817
|
-
return __awaiter$2(this, void 0, void 0, function () {
|
|
818
|
-
return __generator$2(this, function (_a) {
|
|
819
|
-
switch (_a.label) {
|
|
820
|
-
case 0: return [4 /*yield*/, this.matrixWidgetApi.sendToDevice(eventType, encrypted, content)];
|
|
821
|
-
case 1:
|
|
822
|
-
_a.sent();
|
|
823
|
-
return [2 /*return*/];
|
|
824
|
-
}
|
|
825
|
-
});
|
|
826
|
-
});
|
|
827
|
-
};
|
|
828
|
-
/** {@inheritDoc WidgetApi.observeToDeviceMessages} */
|
|
829
|
-
WidgetApiImpl.prototype.observeToDeviceMessages = function (eventType) {
|
|
830
|
-
return this.toDeviceMessages$.pipe(rxjs.map(function (e) { return e.detail.data; }), rxjs.filter(function (e) { return e.type === eventType; }));
|
|
831
|
-
};
|
|
832
|
-
/** {@inheritDoc WidgetApi.openModal} */
|
|
833
|
-
WidgetApiImpl.prototype.openModal = function (pathName, name, options) {
|
|
834
|
-
return __awaiter$2(this, void 0, void 0, function () {
|
|
835
|
-
var isModal, url, closeModalWidget$;
|
|
836
|
-
var _this = this;
|
|
837
|
-
return __generator$2(this, function (_a) {
|
|
838
|
-
switch (_a.label) {
|
|
839
|
-
case 0:
|
|
840
|
-
isModal = parseWidgetId(this.widgetId).isModal;
|
|
841
|
-
if (isModal) {
|
|
842
|
-
throw new Error("Modals can't be opened from another modal widget");
|
|
843
|
-
}
|
|
844
|
-
url = generateWidgetRegistrationUrl({
|
|
845
|
-
pathName: pathName,
|
|
846
|
-
widgetParameters: this.widgetParameters,
|
|
847
|
-
});
|
|
848
|
-
return [4 /*yield*/, this.matrixWidgetApi.openModalWidget(url, name, options === null || options === void 0 ? void 0 : options.buttons, options === null || options === void 0 ? void 0 : options.data)];
|
|
849
|
-
case 1:
|
|
850
|
-
_a.sent();
|
|
851
|
-
closeModalWidget$ = rxjs.fromEvent(this.matrixWidgetApi, "action:".concat(matrixWidgetApi.WidgetApiToWidgetAction.CloseModalWidget), function (event) {
|
|
852
|
-
var _a;
|
|
853
|
-
event.preventDefault();
|
|
854
|
-
_this.matrixWidgetApi.transport.reply(event.detail, {});
|
|
855
|
-
if (((_a = event.detail.data) === null || _a === void 0 ? void 0 : _a['m.exited']) === true) {
|
|
856
|
-
return undefined;
|
|
857
|
-
}
|
|
858
|
-
return event.detail.data;
|
|
859
|
-
});
|
|
860
|
-
return [2 /*return*/, rxjs.firstValueFrom(closeModalWidget$)];
|
|
861
|
-
}
|
|
862
|
-
});
|
|
863
|
-
});
|
|
864
|
-
};
|
|
865
|
-
/** {@inheritDoc WidgetApi.setModalButtonEnabled} */
|
|
866
|
-
WidgetApiImpl.prototype.setModalButtonEnabled = function (buttonId, isEnabled) {
|
|
867
|
-
return __awaiter$2(this, void 0, void 0, function () {
|
|
868
|
-
var isModal;
|
|
869
|
-
return __generator$2(this, function (_a) {
|
|
870
|
-
switch (_a.label) {
|
|
871
|
-
case 0:
|
|
872
|
-
isModal = parseWidgetId(this.widgetId).isModal;
|
|
873
|
-
if (!isModal) {
|
|
874
|
-
throw new Error('Modal buttons can only be enabled from a modal widget');
|
|
875
|
-
}
|
|
876
|
-
return [4 /*yield*/, this.matrixWidgetApi.setModalButtonEnabled(buttonId, isEnabled)];
|
|
877
|
-
case 1:
|
|
878
|
-
_a.sent();
|
|
879
|
-
return [2 /*return*/];
|
|
880
|
-
}
|
|
881
|
-
});
|
|
882
|
-
});
|
|
883
|
-
};
|
|
884
|
-
/** {@inheritDoc WidgetApi.observeModalButtons} */
|
|
885
|
-
WidgetApiImpl.prototype.observeModalButtons = function () {
|
|
886
|
-
var _this = this;
|
|
887
|
-
var isModal = parseWidgetId(this.widgetId).isModal;
|
|
888
|
-
if (!isModal) {
|
|
889
|
-
throw new Error('Modal buttons can only be observed from a modal widget');
|
|
799
|
+
op = body.call(thisArg, _);
|
|
800
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
801
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
var __rest = (undefined && undefined.__rest) || function (s, e) {
|
|
805
|
+
var t = {};
|
|
806
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
807
|
+
t[p] = s[p];
|
|
808
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
809
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
810
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
811
|
+
t[p[i]] = s[p[i]];
|
|
890
812
|
}
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
813
|
+
return t;
|
|
814
|
+
};
|
|
815
|
+
/**
|
|
816
|
+
* Checks whether all widget parameters were provided to the widget.
|
|
817
|
+
*
|
|
818
|
+
* @param widgetApi - The widget api to read the parameters from
|
|
819
|
+
* @returns True, if all parameters were provided.
|
|
820
|
+
*/
|
|
821
|
+
function hasRequiredWidgetParameters(widgetApi) {
|
|
822
|
+
return (typeof widgetApi.widgetParameters.userId === 'string' &&
|
|
823
|
+
typeof widgetApi.widgetParameters.displayName === 'string' &&
|
|
824
|
+
typeof widgetApi.widgetParameters.avatarUrl === 'string' &&
|
|
825
|
+
typeof widgetApi.widgetParameters.roomId === 'string' &&
|
|
826
|
+
typeof widgetApi.widgetParameters.theme === 'string' &&
|
|
827
|
+
typeof widgetApi.widgetParameters.clientId === 'string' &&
|
|
828
|
+
typeof widgetApi.widgetParameters.clientLanguage === 'string' &&
|
|
829
|
+
typeof widgetApi.widgetParameters.baseUrl === 'string');
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Generate a registration URL for the widget based on the current URL and
|
|
833
|
+
* include all widget parameters (and their placeholders).
|
|
834
|
+
* @param options - Options for generating the URL.
|
|
835
|
+
* Use `pathName` to include an optional sub path in the URL.
|
|
836
|
+
* Use `includeParameters` to append the widget parameters to
|
|
837
|
+
* the URL, defaults to `true`.
|
|
838
|
+
* @returns The generated URL.
|
|
839
|
+
*/
|
|
840
|
+
function generateWidgetRegistrationUrl(options) {
|
|
841
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
842
|
+
if (options === void 0) { options = {}; }
|
|
843
|
+
var pathName = options.pathName, _j = options.includeParameters, includeParameters = _j === void 0 ? true : _j, widgetParameters = options.widgetParameters;
|
|
844
|
+
// don't forward widgetId and parentUrl as they will be generated by the client
|
|
845
|
+
var _k = extractRawWidgetParameters(); _k.widgetId; _k.parentUrl; var rawWidgetParameters = __rest(_k, ["widgetId", "parentUrl"]);
|
|
846
|
+
var parameters = Object.entries(__assign(__assign({}, rawWidgetParameters), { theme: (_a = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.theme) !== null && _a !== void 0 ? _a : '$org.matrix.msc2873.client_theme', matrix_user_id: (_b = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.userId) !== null && _b !== void 0 ? _b : '$matrix_user_id', matrix_display_name: (_c = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.displayName) !== null && _c !== void 0 ? _c : '$matrix_display_name', matrix_avatar_url: (_d = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.avatarUrl) !== null && _d !== void 0 ? _d : '$matrix_avatar_url', matrix_room_id: (_e = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.roomId) !== null && _e !== void 0 ? _e : '$matrix_room_id', matrix_client_id: (_f = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.clientId) !== null && _f !== void 0 ? _f : '$org.matrix.msc2873.client_id', matrix_client_language: (_g = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.clientLanguage) !== null && _g !== void 0 ? _g : '$org.matrix.msc2873.client_language', matrix_base_url: (_h = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.baseUrl) !== null && _h !== void 0 ? _h : '$org.matrix.msc4039.matrix_base_url' }))
|
|
847
|
+
.map(function (_a) {
|
|
848
|
+
var k = _a[0], v = _a[1];
|
|
849
|
+
return "".concat(k, "=").concat(v);
|
|
850
|
+
})
|
|
851
|
+
.join('&');
|
|
852
|
+
var url = new URL(window.location.href);
|
|
853
|
+
if (pathName) {
|
|
854
|
+
url.pathname = pathName;
|
|
855
|
+
}
|
|
856
|
+
else {
|
|
857
|
+
// ensure trailing '/'
|
|
858
|
+
url.pathname = url.pathname.replace(/\/?$/, '/');
|
|
859
|
+
}
|
|
860
|
+
url.search = '';
|
|
861
|
+
url.hash = includeParameters ? "#/?".concat(parameters) : '';
|
|
862
|
+
return url.toString();
|
|
863
|
+
}
|
|
864
|
+
var STATE_EVENT_WIDGETS = 'im.vector.modular.widgets';
|
|
865
|
+
/**
|
|
866
|
+
* Repair/configure the registration of the current widget.
|
|
867
|
+
* This steps make sure to include all the required widget parameters in the
|
|
868
|
+
* URL. Support setting a widget name and additional parameters.
|
|
869
|
+
*
|
|
870
|
+
* @param widgetApi - The widget api of the current widget.
|
|
871
|
+
* @param registration - Optional configuration options for the widget
|
|
872
|
+
* registration, like the display name of the widget.
|
|
873
|
+
*/
|
|
874
|
+
function repairWidgetRegistration(widgetApi_1) {
|
|
875
|
+
return __awaiter$1(this, arguments, void 0, function (widgetApi, registration) {
|
|
876
|
+
var readResult, url, name, type, data;
|
|
877
|
+
if (registration === void 0) { registration = {}; }
|
|
878
|
+
return __generator$1(this, function (_a) {
|
|
879
|
+
switch (_a.label) {
|
|
880
|
+
case 0: return [4 /*yield*/, widgetApi.requestCapabilities([
|
|
881
|
+
matrixWidgetApi.WidgetEventCapability.forStateEvent(matrixWidgetApi.EventDirection.Send, STATE_EVENT_WIDGETS, widgetApi.widgetId),
|
|
882
|
+
matrixWidgetApi.WidgetEventCapability.forStateEvent(matrixWidgetApi.EventDirection.Receive, STATE_EVENT_WIDGETS, widgetApi.widgetId),
|
|
883
|
+
])];
|
|
884
|
+
case 1:
|
|
885
|
+
_a.sent();
|
|
886
|
+
return [4 /*yield*/, widgetApi.receiveSingleStateEvent(STATE_EVENT_WIDGETS, widgetApi.widgetId)];
|
|
887
|
+
case 2:
|
|
888
|
+
readResult = _a.sent();
|
|
889
|
+
if (!readResult) {
|
|
890
|
+
throw new Error("Error while repairing registration, can't find existing registration.");
|
|
891
|
+
}
|
|
892
|
+
url = generateWidgetRegistrationUrl();
|
|
893
|
+
name = registration.name &&
|
|
894
|
+
(!readResult.content.name ||
|
|
895
|
+
readResult.content.name === 'Custom Widget' ||
|
|
896
|
+
readResult.content.name === 'Custom')
|
|
897
|
+
? registration.name
|
|
898
|
+
: readResult.content.name;
|
|
899
|
+
type = registration.type &&
|
|
900
|
+
(!readResult.content.type || readResult.content.type === 'm.custom')
|
|
901
|
+
? registration.type
|
|
902
|
+
: readResult.content.type;
|
|
903
|
+
data = registration.data
|
|
904
|
+
? __assign(__assign({}, readResult.content.data), registration.data) : readResult.content.data;
|
|
905
|
+
// This is a workaround because changing the widget config is breaking the
|
|
906
|
+
// widget API communication. However we need to fail in case the power level
|
|
907
|
+
// for this change is missing. As the error happens quite fast, we just wait
|
|
908
|
+
// a moment and then consider the operation as succeeded.
|
|
909
|
+
return [4 /*yield*/, Promise.race([
|
|
910
|
+
widgetApi.sendStateEvent(STATE_EVENT_WIDGETS, __assign(__assign({}, readResult.content), { url: url.toString(), name: name, type: type, data: data }), { stateKey: widgetApi.widgetId }),
|
|
911
|
+
new Promise(function (resolve) { return setTimeout(resolve, 1000); }),
|
|
912
|
+
])];
|
|
913
|
+
case 3:
|
|
914
|
+
// This is a workaround because changing the widget config is breaking the
|
|
915
|
+
// widget API communication. However we need to fail in case the power level
|
|
916
|
+
// for this change is missing. As the error happens quite fast, we just wait
|
|
917
|
+
// a moment and then consider the operation as succeeded.
|
|
918
|
+
_a.sent();
|
|
919
|
+
return [2 /*return*/];
|
|
920
|
+
}
|
|
927
921
|
});
|
|
928
|
-
};
|
|
929
|
-
/** {@inheritdoc WidgetApi.requestOpenIDConnectToken} */
|
|
930
|
-
WidgetApiImpl.prototype.requestOpenIDConnectToken = function () {
|
|
931
|
-
return __awaiter$2(this, void 0, void 0, function () {
|
|
932
|
-
return __generator$2(this, function (_b) {
|
|
933
|
-
switch (_b.label) {
|
|
934
|
-
case 0:
|
|
935
|
-
if (!this.outstandingOpenIDConnectTokenRequest) return [3 /*break*/, 4];
|
|
936
|
-
_b.label = 1;
|
|
937
|
-
case 1:
|
|
938
|
-
_b.trys.push([1, 3, , 4]);
|
|
939
|
-
return [4 /*yield*/, this.outstandingOpenIDConnectTokenRequest];
|
|
940
|
-
case 2:
|
|
941
|
-
_b.sent();
|
|
942
|
-
return [3 /*break*/, 4];
|
|
943
|
-
case 3:
|
|
944
|
-
_b.sent();
|
|
945
|
-
return [3 /*break*/, 4];
|
|
946
|
-
case 4:
|
|
947
|
-
_b.trys.push([4, , 6, 7]);
|
|
948
|
-
this.outstandingOpenIDConnectTokenRequest =
|
|
949
|
-
this.requestOpenIDConnectTokenInternal();
|
|
950
|
-
return [4 /*yield*/, this.outstandingOpenIDConnectTokenRequest];
|
|
951
|
-
case 5: return [2 /*return*/, _b.sent()];
|
|
952
|
-
case 6:
|
|
953
|
-
this.outstandingOpenIDConnectTokenRequest = undefined;
|
|
954
|
-
return [7 /*endfinally*/];
|
|
955
|
-
case 7: return [2 /*return*/];
|
|
956
|
-
}
|
|
957
|
-
});
|
|
958
|
-
});
|
|
959
|
-
};
|
|
960
|
-
WidgetApiImpl.prototype.requestOpenIDConnectTokenInternal = function () {
|
|
961
|
-
var _a;
|
|
962
|
-
return __awaiter$2(this, void 0, void 0, function () {
|
|
963
|
-
var leywayMilliseconds, openIdToken, err_2;
|
|
964
|
-
return __generator$2(this, function (_b) {
|
|
965
|
-
switch (_b.label) {
|
|
966
|
-
case 0:
|
|
967
|
-
leywayMilliseconds = 30 * 1000;
|
|
968
|
-
if (this.cachedOpenIdToken &&
|
|
969
|
-
this.cachedOpenIdToken.expiresAt - leywayMilliseconds > Date.now()) {
|
|
970
|
-
return [2 /*return*/, this.cachedOpenIdToken.openIdToken];
|
|
971
|
-
}
|
|
972
|
-
_b.label = 1;
|
|
973
|
-
case 1:
|
|
974
|
-
_b.trys.push([1, 3, , 4]);
|
|
975
|
-
return [4 /*yield*/, this.matrixWidgetApi.requestOpenIDConnectToken()];
|
|
976
|
-
case 2:
|
|
977
|
-
openIdToken = _b.sent();
|
|
978
|
-
this.cachedOpenIdToken = {
|
|
979
|
-
openIdToken: openIdToken,
|
|
980
|
-
expiresAt: Date.now() + ((_a = openIdToken.expires_in) !== null && _a !== void 0 ? _a : 0) * 1000,
|
|
981
|
-
};
|
|
982
|
-
return [2 /*return*/, openIdToken];
|
|
983
|
-
case 3:
|
|
984
|
-
err_2 = _b.sent();
|
|
985
|
-
this.cachedOpenIdToken = undefined;
|
|
986
|
-
throw err_2;
|
|
987
|
-
case 4: return [2 /*return*/];
|
|
988
|
-
}
|
|
989
|
-
});
|
|
990
|
-
});
|
|
991
|
-
};
|
|
992
|
-
/** {@inheritdoc WidgetApi.observeTurnServers} */
|
|
993
|
-
WidgetApiImpl.prototype.observeTurnServers = function () {
|
|
994
|
-
return rxjs.from(this.matrixWidgetApi.getTurnServers()).pipe(
|
|
995
|
-
// For some reason a different naming was chosen for the API, but
|
|
996
|
-
// we already convert them to the right type for WebRTC consumers.
|
|
997
|
-
rxjs.map(function (_a) {
|
|
998
|
-
var uris = _a.uris, username = _a.username, password = _a.password;
|
|
999
|
-
return ({
|
|
1000
|
-
urls: uris,
|
|
1001
|
-
username: username,
|
|
1002
|
-
credential: password,
|
|
1003
|
-
});
|
|
1004
|
-
}));
|
|
1005
|
-
};
|
|
1006
|
-
/** {@inheritdoc WidgetApi.searchUserDirectory} */
|
|
1007
|
-
WidgetApiImpl.prototype.searchUserDirectory = function (searchTerm, options) {
|
|
1008
|
-
return __awaiter$2(this, void 0, void 0, function () {
|
|
1009
|
-
var results;
|
|
1010
|
-
return __generator$2(this, function (_a) {
|
|
1011
|
-
switch (_a.label) {
|
|
1012
|
-
case 0: return [4 /*yield*/, this.matrixWidgetApi.searchUserDirectory(searchTerm, options === null || options === void 0 ? void 0 : options.limit)];
|
|
1013
|
-
case 1:
|
|
1014
|
-
results = (_a.sent()).results;
|
|
1015
|
-
return [2 /*return*/, {
|
|
1016
|
-
results: results.map(function (_a) {
|
|
1017
|
-
var user_id = _a.user_id, display_name = _a.display_name, avatar_url = _a.avatar_url;
|
|
1018
|
-
return ({
|
|
1019
|
-
userId: user_id,
|
|
1020
|
-
displayName: display_name,
|
|
1021
|
-
avatarUrl: avatar_url,
|
|
1022
|
-
});
|
|
1023
|
-
}),
|
|
1024
|
-
}];
|
|
1025
|
-
}
|
|
1026
|
-
});
|
|
1027
|
-
});
|
|
1028
|
-
};
|
|
1029
|
-
/** {@inheritdoc WidgetApi.getMediaConfig} */
|
|
1030
|
-
WidgetApiImpl.prototype.getMediaConfig = function () {
|
|
1031
|
-
return __awaiter$2(this, void 0, void 0, function () {
|
|
1032
|
-
return __generator$2(this, function (_a) {
|
|
1033
|
-
switch (_a.label) {
|
|
1034
|
-
case 0: return [4 /*yield*/, this.matrixWidgetApi.getMediaConfig()];
|
|
1035
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
1036
|
-
}
|
|
1037
|
-
});
|
|
1038
|
-
});
|
|
1039
|
-
};
|
|
1040
|
-
/** {@inheritdoc WidgetApi.uploadFile} */
|
|
1041
|
-
WidgetApiImpl.prototype.uploadFile = function (file) {
|
|
1042
|
-
return __awaiter$2(this, void 0, void 0, function () {
|
|
1043
|
-
return __generator$2(this, function (_a) {
|
|
1044
|
-
switch (_a.label) {
|
|
1045
|
-
case 0: return [4 /*yield*/, this.matrixWidgetApi.uploadFile(file)];
|
|
1046
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
1047
|
-
}
|
|
1048
|
-
});
|
|
1049
|
-
});
|
|
1050
|
-
};
|
|
1051
|
-
return WidgetApiImpl;
|
|
1052
|
-
}());
|
|
1053
|
-
|
|
1054
|
-
/*
|
|
1055
|
-
* Copyright 2022 Nordeck IT + Consulting GmbH
|
|
1056
|
-
*
|
|
1057
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1058
|
-
* you may not use this file except in compliance with the License.
|
|
1059
|
-
* You may obtain a copy of the License at
|
|
1060
|
-
*
|
|
1061
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1062
|
-
*
|
|
1063
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1064
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1065
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1066
|
-
* See the License for the specific language governing permissions and
|
|
1067
|
-
* limitations under the License.
|
|
1068
|
-
*/
|
|
1069
|
-
/**
|
|
1070
|
-
* Generate a list of capabilities to access the timeline of other rooms.
|
|
1071
|
-
* If enabled, all previously or future capabilities will apply to _all_
|
|
1072
|
-
* selected rooms.
|
|
1073
|
-
* If `Symbols.AnyRoom` is passed, this is expanded to all joined
|
|
1074
|
-
* or invited rooms the client is able to see, current and future.
|
|
1075
|
-
*
|
|
1076
|
-
* @param roomIds - a list of room ids or `@link Symbols.AnyRoom`.
|
|
1077
|
-
* @returns the generated capabilities.
|
|
1078
|
-
*/
|
|
1079
|
-
function generateRoomTimelineCapabilities(roomIds) {
|
|
1080
|
-
if (roomIds === matrixWidgetApi.Symbols.AnyRoom) {
|
|
1081
|
-
return ['org.matrix.msc2762.timeline:*'];
|
|
1082
|
-
}
|
|
1083
|
-
if (Array.isArray(roomIds)) {
|
|
1084
|
-
return roomIds.map(function (id) { return "org.matrix.msc2762.timeline:".concat(id); });
|
|
1085
|
-
}
|
|
1086
|
-
return [];
|
|
1087
|
-
}
|
|
1088
|
-
|
|
1089
|
-
/*
|
|
1090
|
-
* Copyright 2022 Nordeck IT + Consulting GmbH
|
|
1091
|
-
*
|
|
1092
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1093
|
-
* you may not use this file except in compliance with the License.
|
|
1094
|
-
* You may obtain a copy of the License at
|
|
1095
|
-
*
|
|
1096
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1097
|
-
*
|
|
1098
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1099
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1100
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1101
|
-
* See the License for the specific language governing permissions and
|
|
1102
|
-
* limitations under the License.
|
|
1103
|
-
*/
|
|
1104
|
-
/**
|
|
1105
|
-
* Generate a unique displayname of a user that is consistent across Matrix clients.
|
|
1106
|
-
*
|
|
1107
|
-
* @remarks The algorithm is based on https://spec.matrix.org/v1.1/client-server-api/#calculating-the-display-name-for-a-user
|
|
1108
|
-
*
|
|
1109
|
-
* @param member - the member to generate a name for.
|
|
1110
|
-
* @param allRoomMembers - a list of all members of the same room.
|
|
1111
|
-
* @returns the displayname that is unique in given the set of all room members.
|
|
1112
|
-
*/
|
|
1113
|
-
function getRoomMemberDisplayName(member, allRoomMembers) {
|
|
1114
|
-
if (allRoomMembers === void 0) { allRoomMembers = []; }
|
|
1115
|
-
// If the m.room.member state event has no displayname field, or if that field
|
|
1116
|
-
// has a null value, use the raw user id as the display name.
|
|
1117
|
-
if (typeof member.content.displayname !== 'string') {
|
|
1118
|
-
return member.state_key;
|
|
1119
|
-
}
|
|
1120
|
-
// If the m.room.member event has a displayname which is unique among members of
|
|
1121
|
-
// the room with membership: join or membership: invite, ...
|
|
1122
|
-
var hasDuplicateDisplayName = allRoomMembers.some(function (m) {
|
|
1123
|
-
// same room
|
|
1124
|
-
return m.room_id === member.room_id &&
|
|
1125
|
-
// not the own event
|
|
1126
|
-
m.state_key !== member.state_key &&
|
|
1127
|
-
// only join or invite state
|
|
1128
|
-
['join', 'invite'].includes(m.content.membership) &&
|
|
1129
|
-
// same displayname
|
|
1130
|
-
m.content.displayname === member.content.displayname;
|
|
1131
922
|
});
|
|
1132
|
-
if (!hasDuplicateDisplayName) {
|
|
1133
|
-
// ... use the given displayname as the user-visible display name.
|
|
1134
|
-
return member.content.displayname;
|
|
1135
|
-
}
|
|
1136
|
-
else {
|
|
1137
|
-
// The m.room.member event has a non-unique displayname. This should be
|
|
1138
|
-
// disambiguated using the user id, for example “display name (@id:homeserver.org)”.
|
|
1139
|
-
return "".concat(member.content.displayname, " (").concat(member.state_key, ")");
|
|
1140
|
-
}
|
|
1141
923
|
}
|
|
1142
924
|
|
|
1143
925
|
/*
|
|
@@ -1155,23 +937,31 @@ function getRoomMemberDisplayName(member, allRoomMembers) {
|
|
|
1155
937
|
* See the License for the specific language governing permissions and
|
|
1156
938
|
* limitations under the License.
|
|
1157
939
|
*/
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
*
|
|
1161
|
-
* @param event - An event that is either a {@link RoomEvent} or a {@link StateEvent}.
|
|
1162
|
-
* @returns True, if the event is a {@link StateEvent}.
|
|
1163
|
-
*/
|
|
1164
|
-
function isStateEvent(event) {
|
|
1165
|
-
return 'state_key' in event && typeof event.state_key === 'string';
|
|
940
|
+
function convertToRawCapabilities(rawCapabilities) {
|
|
941
|
+
return rawCapabilities.map(function (c) { return (typeof c === 'string' ? c : c.raw); });
|
|
1166
942
|
}
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
function
|
|
1174
|
-
|
|
943
|
+
function isDefined(arg) {
|
|
944
|
+
return arg !== null && arg !== undefined;
|
|
945
|
+
}
|
|
946
|
+
function unique(items) {
|
|
947
|
+
return Array.from(new Set(items));
|
|
948
|
+
}
|
|
949
|
+
function subtractSet(as, bs) {
|
|
950
|
+
var result = new Set(as);
|
|
951
|
+
bs.forEach(function (v) { return result.delete(v); });
|
|
952
|
+
return result;
|
|
953
|
+
}
|
|
954
|
+
function isInRoom(matrixEvent, currentRoomId, roomIds) {
|
|
955
|
+
if (!roomIds) {
|
|
956
|
+
return matrixEvent.room_id === currentRoomId;
|
|
957
|
+
}
|
|
958
|
+
if (typeof roomIds === 'string') {
|
|
959
|
+
if (roomIds !== matrixWidgetApi.Symbols.AnyRoom) {
|
|
960
|
+
throw Error("Unknown room id symbol: ".concat(roomIds));
|
|
961
|
+
}
|
|
962
|
+
return true;
|
|
963
|
+
}
|
|
964
|
+
return roomIds.includes(matrixEvent.room_id);
|
|
1175
965
|
}
|
|
1176
966
|
|
|
1177
967
|
/*
|
|
@@ -1189,7 +979,7 @@ function isRoomEvent(event) {
|
|
|
1189
979
|
* See the License for the specific language governing permissions and
|
|
1190
980
|
* limitations under the License.
|
|
1191
981
|
*/
|
|
1192
|
-
var __awaiter
|
|
982
|
+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1193
983
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1194
984
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1195
985
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -1198,7 +988,7 @@ var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _argu
|
|
|
1198
988
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1199
989
|
});
|
|
1200
990
|
};
|
|
1201
|
-
var __generator
|
|
991
|
+
var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
|
|
1202
992
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
1203
993
|
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
1204
994
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
@@ -1225,462 +1015,672 @@ var __generator$1 = (undefined && undefined.__generator) || function (thisArg, b
|
|
|
1225
1015
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
1226
1016
|
}
|
|
1227
1017
|
};
|
|
1018
|
+
var __spreadArray = (undefined && undefined.__spreadArray) || function (to, from, pack) {
|
|
1019
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
1020
|
+
if (ar || !(i in from)) {
|
|
1021
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
1022
|
+
ar[i] = from[i];
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
1026
|
+
};
|
|
1228
1027
|
/**
|
|
1229
|
-
*
|
|
1230
|
-
*/
|
|
1231
|
-
var WIDGET_CAPABILITY_NAVIGATE = 'org.matrix.msc2931.navigate';
|
|
1232
|
-
/**
|
|
1233
|
-
* Navigate the client to another matrix room.
|
|
1234
|
-
*
|
|
1235
|
-
* @remarks This requires the {@link WIDGET_CAPABILITY_NAVIGATE} capability.
|
|
1028
|
+
* Implementation of the API from the widget to the client.
|
|
1236
1029
|
*
|
|
1237
|
-
* @
|
|
1238
|
-
*
|
|
1239
|
-
* @param opts - {@link NavigateToRoomOptions}
|
|
1030
|
+
* @remarks Widget API is specified here:
|
|
1031
|
+
* https://docs.google.com/document/d/1uPF7XWY_dXTKVKV7jZQ2KmsI19wn9-kFRgQ1tFQP7wQ/edit#heading=h.9rn9lt6ctkgi
|
|
1240
1032
|
*/
|
|
1241
|
-
function
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1033
|
+
var WidgetApiImpl = /** @class */ (function () {
|
|
1034
|
+
function WidgetApiImpl(
|
|
1035
|
+
/**
|
|
1036
|
+
* Provide access to the underlying widget API from `matrix-widget-sdk`.
|
|
1037
|
+
*
|
|
1038
|
+
* @remarks Normally there is no need to use it, however if features are
|
|
1039
|
+
* missing from `WidgetApi` it can be handy to work with the
|
|
1040
|
+
* original API.
|
|
1041
|
+
*/
|
|
1042
|
+
matrixWidgetApi$1,
|
|
1043
|
+
/** {@inheritDoc WidgetApi.widgetId} */
|
|
1044
|
+
widgetId,
|
|
1045
|
+
/** {@inheritDoc WidgetApi.widgetParameters} */
|
|
1046
|
+
widgetParameters, _a) {
|
|
1047
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.capabilities, capabilities = _c === void 0 ? [] : _c, _d = _b.supportStandalone, supportStandalone = _d === void 0 ? false : _d;
|
|
1048
|
+
var _this = this;
|
|
1049
|
+
this.matrixWidgetApi = matrixWidgetApi$1;
|
|
1050
|
+
this.widgetId = widgetId;
|
|
1051
|
+
this.widgetParameters = widgetParameters;
|
|
1052
|
+
this.events$ = rxjs.fromEvent(this.matrixWidgetApi, "action:".concat(matrixWidgetApi.WidgetApiToWidgetAction.SendEvent), function (event) {
|
|
1053
|
+
event.preventDefault();
|
|
1054
|
+
try {
|
|
1055
|
+
_this.matrixWidgetApi.transport.reply(event.detail, {});
|
|
1255
1056
|
}
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
* See the License for the specific language governing permissions and
|
|
1273
|
-
* limitations under the License.
|
|
1274
|
-
*/
|
|
1275
|
-
/**
|
|
1276
|
-
* Compares two room events by their origin server timestamp.
|
|
1277
|
-
*
|
|
1278
|
-
* @param a - A room event
|
|
1279
|
-
* @param b - A room event
|
|
1280
|
-
* @returns Either zero if the timestamp is equal, \>0 if a is newer, or \<0 if
|
|
1281
|
-
* b is newer.
|
|
1282
|
-
*/
|
|
1283
|
-
function compareOriginServerTS(a, b) {
|
|
1284
|
-
return a.origin_server_ts - b.origin_server_ts;
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
/*
|
|
1288
|
-
* Copyright 2022 Nordeck IT + Consulting GmbH
|
|
1289
|
-
*
|
|
1290
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1291
|
-
* you may not use this file except in compliance with the License.
|
|
1292
|
-
* You may obtain a copy of the License at
|
|
1293
|
-
*
|
|
1294
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1295
|
-
*
|
|
1296
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1297
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1298
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1299
|
-
* See the License for the specific language governing permissions and
|
|
1300
|
-
* limitations under the License.
|
|
1301
|
-
*/
|
|
1302
|
-
/**
|
|
1303
|
-
* The name of the power levels state event.
|
|
1304
|
-
*/
|
|
1305
|
-
var STATE_EVENT_POWER_LEVELS = 'm.room.power_levels';
|
|
1306
|
-
function isNumberOrUndefined(value) {
|
|
1307
|
-
return value === undefined || typeof value === 'number';
|
|
1308
|
-
}
|
|
1309
|
-
function isStringToNumberMapOrUndefined(value) {
|
|
1310
|
-
return (value === undefined ||
|
|
1311
|
-
(value !== null &&
|
|
1312
|
-
typeof value === 'object' &&
|
|
1313
|
-
Object.entries(value).every(function (_a) {
|
|
1314
|
-
var k = _a[0], v = _a[1];
|
|
1315
|
-
return typeof k === 'string' && typeof v === 'number';
|
|
1316
|
-
})));
|
|
1317
|
-
}
|
|
1318
|
-
/**
|
|
1319
|
-
* Validates that `event` is has a valid structure for a
|
|
1320
|
-
* {@link PowerLevelsStateEvent}.
|
|
1321
|
-
* @param event - The event to validate.
|
|
1322
|
-
* @returns True, if the event is valid.
|
|
1323
|
-
*/
|
|
1324
|
-
function isValidPowerLevelStateEvent(event) {
|
|
1325
|
-
if (event.type !== STATE_EVENT_POWER_LEVELS ||
|
|
1326
|
-
typeof event.content !== 'object') {
|
|
1327
|
-
return false;
|
|
1328
|
-
}
|
|
1329
|
-
var content = event.content;
|
|
1330
|
-
if (!isStringToNumberMapOrUndefined(content.events)) {
|
|
1331
|
-
return false;
|
|
1332
|
-
}
|
|
1333
|
-
if (!isNumberOrUndefined(content.state_default)) {
|
|
1334
|
-
return false;
|
|
1335
|
-
}
|
|
1336
|
-
if (!isNumberOrUndefined(content.events_default)) {
|
|
1337
|
-
return false;
|
|
1338
|
-
}
|
|
1339
|
-
if (!isStringToNumberMapOrUndefined(content.users)) {
|
|
1340
|
-
return false;
|
|
1341
|
-
}
|
|
1342
|
-
if (!isNumberOrUndefined(content.users_default)) {
|
|
1343
|
-
return false;
|
|
1344
|
-
}
|
|
1345
|
-
if (!isNumberOrUndefined(content.ban)) {
|
|
1346
|
-
return false;
|
|
1347
|
-
}
|
|
1348
|
-
if (!isNumberOrUndefined(content.invite)) {
|
|
1349
|
-
return false;
|
|
1350
|
-
}
|
|
1351
|
-
if (!isNumberOrUndefined(content.kick)) {
|
|
1352
|
-
return false;
|
|
1353
|
-
}
|
|
1354
|
-
if (!isNumberOrUndefined(content.redact)) {
|
|
1355
|
-
return false;
|
|
1356
|
-
}
|
|
1357
|
-
return true;
|
|
1358
|
-
}
|
|
1359
|
-
/**
|
|
1360
|
-
* Check if a user has the power to send a specific room event.
|
|
1361
|
-
*
|
|
1362
|
-
* @param powerLevelStateEvent - the content of the `m.room.power_levels` event
|
|
1363
|
-
* @param userId - the id of the user
|
|
1364
|
-
* @param eventType - the type of room event
|
|
1365
|
-
* @returns if true, the user has the power
|
|
1366
|
-
*/
|
|
1367
|
-
function hasRoomEventPower(powerLevelStateEvent, userId, eventType) {
|
|
1368
|
-
if (!powerLevelStateEvent) {
|
|
1369
|
-
// See https://github.com/matrix-org/matrix-spec/blob/203b9756f52adfc2a3b63d664f18cdbf9f8bf126/data/event-schemas/schema/m.room.power_levels.yaml#L36-L43
|
|
1370
|
-
return true;
|
|
1371
|
-
}
|
|
1372
|
-
var userLevel = calculateUserPowerLevel(powerLevelStateEvent, userId);
|
|
1373
|
-
var eventLevel = calculateRoomEventPowerLevel(powerLevelStateEvent, eventType);
|
|
1374
|
-
return userLevel >= eventLevel;
|
|
1375
|
-
}
|
|
1376
|
-
/**
|
|
1377
|
-
* Check if a user has the power to send a specific state event.
|
|
1378
|
-
*
|
|
1379
|
-
* @param powerLevelStateEvent - the content of the `m.room.power_levels` event
|
|
1380
|
-
* @param userId - the id of the user
|
|
1381
|
-
* @param eventType - the type of state event
|
|
1382
|
-
* @returns if true, the user has the power
|
|
1383
|
-
*/
|
|
1384
|
-
function hasStateEventPower(powerLevelStateEvent, userId, eventType) {
|
|
1385
|
-
if (!powerLevelStateEvent) {
|
|
1386
|
-
// See https://github.com/matrix-org/matrix-spec/blob/203b9756f52adfc2a3b63d664f18cdbf9f8bf126/data/event-schemas/schema/m.room.power_levels.yaml#L36-L43
|
|
1387
|
-
return true;
|
|
1388
|
-
}
|
|
1389
|
-
var userLevel = calculateUserPowerLevel(powerLevelStateEvent, userId);
|
|
1390
|
-
var eventLevel = calculateStateEventPowerLevel(powerLevelStateEvent, eventType);
|
|
1391
|
-
return userLevel >= eventLevel;
|
|
1392
|
-
}
|
|
1393
|
-
/**
|
|
1394
|
-
* Check if a user has the power to perform a specific action.
|
|
1395
|
-
*
|
|
1396
|
-
* Supported actions:
|
|
1397
|
-
* * invite: Invite a new user into the room
|
|
1398
|
-
* * kick: Kick a user from the room
|
|
1399
|
-
* * ban: Ban a user from the room
|
|
1400
|
-
* * redact: Redact a message from another user
|
|
1401
|
-
*
|
|
1402
|
-
* @param powerLevelStateEvent - the content of the `m.room.power_levels` event
|
|
1403
|
-
* @param userId - the id of the user
|
|
1404
|
-
* @param action - the action
|
|
1405
|
-
* @returns if true, the user has the power
|
|
1406
|
-
*/
|
|
1407
|
-
function hasActionPower(powerLevelStateEvent, userId, action) {
|
|
1408
|
-
if (!powerLevelStateEvent) {
|
|
1409
|
-
// See https://github.com/matrix-org/matrix-spec/blob/203b9756f52adfc2a3b63d664f18cdbf9f8bf126/data/event-schemas/schema/m.room.power_levels.yaml#L36-L43
|
|
1410
|
-
return true;
|
|
1057
|
+
catch (_) {
|
|
1058
|
+
// Ignore errors while replying
|
|
1059
|
+
}
|
|
1060
|
+
return event;
|
|
1061
|
+
}).pipe(rxjs.share());
|
|
1062
|
+
this.toDeviceMessages$ = rxjs.fromEvent(this.matrixWidgetApi, 'action:send_to_device', function (event) {
|
|
1063
|
+
event.preventDefault();
|
|
1064
|
+
try {
|
|
1065
|
+
matrixWidgetApi$1.transport.reply(event.detail, {});
|
|
1066
|
+
}
|
|
1067
|
+
catch (_) {
|
|
1068
|
+
// Ignore errors while replying
|
|
1069
|
+
}
|
|
1070
|
+
return event;
|
|
1071
|
+
}).pipe(rxjs.share());
|
|
1072
|
+
this.initialCapabilities = __spreadArray(__spreadArray([], capabilities, true), (supportStandalone ? [] : [matrixWidgetApi.MatrixCapabilities.RequiresClient]), true);
|
|
1411
1073
|
}
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
}
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1074
|
+
/**
|
|
1075
|
+
* Initialize a new widget API instance and wait till it is ready.
|
|
1076
|
+
* There should only be one instance of the widget API. The widget API should
|
|
1077
|
+
* be created as early as possible when starting the application. This is
|
|
1078
|
+
* required to match the timing of the API connection establishment with the
|
|
1079
|
+
* client, especially in Safari. Therefore it is recommended to create it
|
|
1080
|
+
* inside the entrypoint, before initializing rendering engines like react.
|
|
1081
|
+
*
|
|
1082
|
+
* @param param0 - {@link WidgetApiOptions}
|
|
1083
|
+
*
|
|
1084
|
+
* @returns A widget API instance ready to use.
|
|
1085
|
+
*/
|
|
1086
|
+
WidgetApiImpl.create = function () {
|
|
1087
|
+
return __awaiter(this, arguments, void 0, function (_a) {
|
|
1088
|
+
var _b, clientOrigin, widgetId, widgetParameters, matrixWidgetApi$1, widgetApi;
|
|
1089
|
+
var _c = _a === void 0 ? {} : _a, _d = _c.capabilities, capabilities = _d === void 0 ? [] : _d, _e = _c.supportStandalone, supportStandalone = _e === void 0 ? false : _e;
|
|
1090
|
+
return __generator(this, function (_f) {
|
|
1091
|
+
switch (_f.label) {
|
|
1092
|
+
case 0:
|
|
1093
|
+
_b = extractWidgetApiParameters(), clientOrigin = _b.clientOrigin, widgetId = _b.widgetId;
|
|
1094
|
+
widgetParameters = extractWidgetParameters();
|
|
1095
|
+
matrixWidgetApi$1 = new matrixWidgetApi.WidgetApi(widgetId, clientOrigin);
|
|
1096
|
+
widgetApi = new WidgetApiImpl(matrixWidgetApi$1, widgetId, widgetParameters, { capabilities: capabilities, supportStandalone: supportStandalone });
|
|
1097
|
+
return [4 /*yield*/, widgetApi.initialize()];
|
|
1098
|
+
case 1:
|
|
1099
|
+
_f.sent();
|
|
1100
|
+
return [2 /*return*/, widgetApi];
|
|
1101
|
+
}
|
|
1102
|
+
});
|
|
1103
|
+
});
|
|
1104
|
+
};
|
|
1105
|
+
/**
|
|
1106
|
+
* Initialize the widget API and wait till a connection with the client is
|
|
1107
|
+
* fully established.
|
|
1108
|
+
*
|
|
1109
|
+
* Waits till the user has approved the initial set of capabilities. The
|
|
1110
|
+
* method doesn't fail if the user doesn't approve all of them. It is
|
|
1111
|
+
* required to check manually afterwards.
|
|
1112
|
+
* In case of modal widgets it waits till the `widgetConfig` is received.
|
|
1113
|
+
*
|
|
1114
|
+
* @remarks Should only be called once during startup.
|
|
1115
|
+
*/
|
|
1116
|
+
WidgetApiImpl.prototype.initialize = function () {
|
|
1117
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1118
|
+
var ready, isModal, configReady, rawCapabilities;
|
|
1119
|
+
var _this = this;
|
|
1120
|
+
return __generator(this, function (_a) {
|
|
1121
|
+
switch (_a.label) {
|
|
1122
|
+
case 0:
|
|
1123
|
+
ready = new Promise(function (resolve) {
|
|
1124
|
+
_this.matrixWidgetApi.once('ready', function () { return resolve(); });
|
|
1125
|
+
});
|
|
1126
|
+
isModal = parseWidgetId(this.widgetId).isModal;
|
|
1127
|
+
configReady = isModal
|
|
1128
|
+
? (function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1129
|
+
var widgetConfig$, _a;
|
|
1130
|
+
var _this = this;
|
|
1131
|
+
return __generator(this, function (_b) {
|
|
1132
|
+
switch (_b.label) {
|
|
1133
|
+
case 0:
|
|
1134
|
+
widgetConfig$ = rxjs.fromEvent(this.matrixWidgetApi, "action:".concat(matrixWidgetApi.WidgetApiToWidgetAction.WidgetConfig), function (ev) {
|
|
1135
|
+
ev.preventDefault();
|
|
1136
|
+
_this.matrixWidgetApi.transport.reply(ev.detail, {});
|
|
1137
|
+
return ev.detail.data;
|
|
1138
|
+
});
|
|
1139
|
+
_a = this;
|
|
1140
|
+
return [4 /*yield*/, rxjs.firstValueFrom(widgetConfig$)];
|
|
1141
|
+
case 1:
|
|
1142
|
+
_a.widgetConfig = _b.sent();
|
|
1143
|
+
return [2 /*return*/];
|
|
1144
|
+
}
|
|
1145
|
+
});
|
|
1146
|
+
}); })()
|
|
1147
|
+
: undefined;
|
|
1148
|
+
rawCapabilities = unique(convertToRawCapabilities(this.initialCapabilities));
|
|
1149
|
+
this.matrixWidgetApi.requestCapabilities(rawCapabilities);
|
|
1150
|
+
this.matrixWidgetApi.start();
|
|
1151
|
+
return [4 /*yield*/, ready];
|
|
1152
|
+
case 1:
|
|
1153
|
+
_a.sent();
|
|
1154
|
+
if (!configReady) return [3 /*break*/, 3];
|
|
1155
|
+
return [4 /*yield*/, configReady];
|
|
1156
|
+
case 2:
|
|
1157
|
+
_a.sent();
|
|
1158
|
+
_a.label = 3;
|
|
1159
|
+
case 3: return [2 /*return*/];
|
|
1160
|
+
}
|
|
1161
|
+
});
|
|
1162
|
+
});
|
|
1163
|
+
};
|
|
1164
|
+
/** {@inheritDoc WidgetApi.getWidgetConfig} */
|
|
1165
|
+
WidgetApiImpl.prototype.getWidgetConfig = function () {
|
|
1166
|
+
return this.widgetConfig;
|
|
1167
|
+
};
|
|
1168
|
+
/** {@inheritDoc WidgetApi.rerequestInitialCapabilities} */
|
|
1169
|
+
WidgetApiImpl.prototype.rerequestInitialCapabilities = function () {
|
|
1170
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1171
|
+
return __generator(this, function (_a) {
|
|
1172
|
+
switch (_a.label) {
|
|
1173
|
+
case 0: return [4 /*yield*/, this.requestCapabilities(this.initialCapabilities)];
|
|
1174
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1175
|
+
}
|
|
1176
|
+
});
|
|
1177
|
+
});
|
|
1178
|
+
};
|
|
1179
|
+
/** {@inheritDoc WidgetApi.hasInitialCapabilities} */
|
|
1180
|
+
WidgetApiImpl.prototype.hasInitialCapabilities = function () {
|
|
1181
|
+
return this.hasCapabilities(this.initialCapabilities);
|
|
1182
|
+
};
|
|
1183
|
+
/** {@inheritDoc WidgetApi.requestCapabilities} */
|
|
1184
|
+
WidgetApiImpl.prototype.requestCapabilities = function (capabilities) {
|
|
1185
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1186
|
+
return __generator(this, function (_b) {
|
|
1187
|
+
switch (_b.label) {
|
|
1188
|
+
case 0:
|
|
1189
|
+
if (!this.outstandingCapabilitiesRequest) return [3 /*break*/, 4];
|
|
1190
|
+
_b.label = 1;
|
|
1191
|
+
case 1:
|
|
1192
|
+
_b.trys.push([1, 3, , 4]);
|
|
1193
|
+
return [4 /*yield*/, this.outstandingCapabilitiesRequest];
|
|
1194
|
+
case 2:
|
|
1195
|
+
_b.sent();
|
|
1196
|
+
return [3 /*break*/, 4];
|
|
1197
|
+
case 3:
|
|
1198
|
+
_b.sent();
|
|
1199
|
+
return [3 /*break*/, 4];
|
|
1200
|
+
case 4:
|
|
1201
|
+
_b.trys.push([4, , 6, 7]);
|
|
1202
|
+
this.outstandingCapabilitiesRequest =
|
|
1203
|
+
this.requestCapabilitiesInternal(capabilities);
|
|
1204
|
+
return [4 /*yield*/, this.outstandingCapabilitiesRequest];
|
|
1205
|
+
case 5:
|
|
1206
|
+
_b.sent();
|
|
1207
|
+
return [3 /*break*/, 7];
|
|
1208
|
+
case 6:
|
|
1209
|
+
this.outstandingCapabilitiesRequest = undefined;
|
|
1210
|
+
return [7 /*endfinally*/];
|
|
1211
|
+
case 7: return [2 /*return*/];
|
|
1212
|
+
}
|
|
1213
|
+
});
|
|
1214
|
+
});
|
|
1215
|
+
};
|
|
1216
|
+
WidgetApiImpl.prototype.requestCapabilitiesInternal = function (capabilities) {
|
|
1217
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1218
|
+
var rawCapabilities, requestedSet, capabilities$;
|
|
1219
|
+
var _this = this;
|
|
1220
|
+
return __generator(this, function (_a) {
|
|
1221
|
+
switch (_a.label) {
|
|
1222
|
+
case 0:
|
|
1223
|
+
rawCapabilities = unique(convertToRawCapabilities(capabilities));
|
|
1224
|
+
// Take shortcut if possible, that avoid extra roundtrips over the API.
|
|
1225
|
+
if (this.hasCapabilities(rawCapabilities)) {
|
|
1226
|
+
return [2 /*return*/];
|
|
1227
|
+
}
|
|
1228
|
+
requestedSet = new Set(rawCapabilities);
|
|
1229
|
+
capabilities$ = rxjs.fromEvent(this.matrixWidgetApi, "action:".concat(matrixWidgetApi.WidgetApiToWidgetAction.NotifyCapabilities), function (ev) { return ev; }).pipe(
|
|
1230
|
+
// TODO: `hasCapability` in the matrix-widget-api isn't consistent when capability
|
|
1231
|
+
// upgrades happened. But `updateRequestedCapabilities` will deduplicate already
|
|
1232
|
+
// approved capabilities, so the the `requested` field will be inconsistent.
|
|
1233
|
+
// If we would enable this check, the function will never resolve. This should
|
|
1234
|
+
// be reactivated once the capability upgrade is working correctly. See also:
|
|
1235
|
+
// https://github.com/matrix-org/matrix-widget-api/issues/52
|
|
1236
|
+
// Ignore events from other parallel capability requests
|
|
1237
|
+
//filter((ev) =>
|
|
1238
|
+
// equalsSet(new Set(ev.detail.data.requested), requestedSet)
|
|
1239
|
+
//),
|
|
1240
|
+
rxjs.map(function (ev) {
|
|
1241
|
+
var approvedSet = new Set(ev.detail.data.approved);
|
|
1242
|
+
var missingSet = subtractSet(requestedSet, approvedSet);
|
|
1243
|
+
if (missingSet.size > 0) {
|
|
1244
|
+
throw new Error("Capabilities rejected: ".concat(Array.from(missingSet).join(', ')));
|
|
1245
|
+
}
|
|
1246
|
+
}), rxjs.first());
|
|
1247
|
+
return [4 /*yield*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
1248
|
+
var subscription, err_1;
|
|
1249
|
+
return __generator(this, function (_a) {
|
|
1250
|
+
switch (_a.label) {
|
|
1251
|
+
case 0:
|
|
1252
|
+
subscription = capabilities$.subscribe({
|
|
1253
|
+
next: resolve,
|
|
1254
|
+
error: reject,
|
|
1255
|
+
});
|
|
1256
|
+
_a.label = 1;
|
|
1257
|
+
case 1:
|
|
1258
|
+
_a.trys.push([1, 3, , 4]);
|
|
1259
|
+
this.matrixWidgetApi.requestCapabilities(rawCapabilities);
|
|
1260
|
+
return [4 /*yield*/, this.matrixWidgetApi.updateRequestedCapabilities()];
|
|
1261
|
+
case 2:
|
|
1262
|
+
_a.sent();
|
|
1263
|
+
return [3 /*break*/, 4];
|
|
1264
|
+
case 3:
|
|
1265
|
+
err_1 = _a.sent();
|
|
1266
|
+
subscription.unsubscribe();
|
|
1267
|
+
reject(err_1);
|
|
1268
|
+
return [3 /*break*/, 4];
|
|
1269
|
+
case 4: return [2 /*return*/];
|
|
1270
|
+
}
|
|
1271
|
+
});
|
|
1272
|
+
}); })];
|
|
1273
|
+
case 1:
|
|
1274
|
+
_a.sent();
|
|
1275
|
+
return [2 /*return*/];
|
|
1276
|
+
}
|
|
1277
|
+
});
|
|
1278
|
+
});
|
|
1279
|
+
};
|
|
1280
|
+
/** {@inheritDoc WidgetApi.hasCapabilities} */
|
|
1281
|
+
WidgetApiImpl.prototype.hasCapabilities = function (capabilities) {
|
|
1282
|
+
var _this = this;
|
|
1283
|
+
var rawCapabilities = convertToRawCapabilities(capabilities);
|
|
1284
|
+
return rawCapabilities.every(function (c) { return _this.matrixWidgetApi.hasCapability(c); });
|
|
1285
|
+
};
|
|
1286
|
+
/** {@inheritDoc WidgetApi.receiveSingleStateEvent} */
|
|
1287
|
+
WidgetApiImpl.prototype.receiveSingleStateEvent = function (eventType_1) {
|
|
1288
|
+
return __awaiter(this, arguments, void 0, function (eventType, stateKey) {
|
|
1289
|
+
var events;
|
|
1290
|
+
if (stateKey === void 0) { stateKey = ''; }
|
|
1291
|
+
return __generator(this, function (_a) {
|
|
1292
|
+
switch (_a.label) {
|
|
1293
|
+
case 0: return [4 /*yield*/, this.receiveStateEvents(eventType, { stateKey: stateKey })];
|
|
1294
|
+
case 1:
|
|
1295
|
+
events = _a.sent();
|
|
1296
|
+
return [2 /*return*/, events && events[0]];
|
|
1297
|
+
}
|
|
1298
|
+
});
|
|
1299
|
+
});
|
|
1300
|
+
};
|
|
1301
|
+
/** {@inheritDoc WidgetApi.receiveStateEvents} */
|
|
1302
|
+
WidgetApiImpl.prototype.receiveStateEvents = function (eventType_1) {
|
|
1303
|
+
return __awaiter(this, arguments, void 0, function (eventType, _a) {
|
|
1304
|
+
var _b = _a === void 0 ? {} : _a, stateKey = _b.stateKey, roomIds = _b.roomIds;
|
|
1305
|
+
return __generator(this, function (_c) {
|
|
1306
|
+
switch (_c.label) {
|
|
1307
|
+
case 0: return [4 /*yield*/, this.matrixWidgetApi.readStateEvents(eventType, Number.MAX_SAFE_INTEGER, stateKey, typeof roomIds === 'string' ? [matrixWidgetApi.Symbols.AnyRoom] : roomIds)];
|
|
1308
|
+
case 1: return [2 /*return*/, (_c.sent())];
|
|
1309
|
+
}
|
|
1310
|
+
});
|
|
1311
|
+
});
|
|
1312
|
+
};
|
|
1313
|
+
/** {@inheritDoc WidgetApi.observeStateEvents} */
|
|
1314
|
+
WidgetApiImpl.prototype.observeStateEvents = function (eventType, _a) {
|
|
1315
|
+
var _b = _a === void 0 ? {} : _a, stateKey = _b.stateKey, roomIds = _b.roomIds;
|
|
1316
|
+
var currentRoomId = this.widgetParameters.roomId;
|
|
1317
|
+
if (!currentRoomId) {
|
|
1318
|
+
return rxjs.throwError(function () { return new Error('Current room id is unknown'); });
|
|
1319
|
+
}
|
|
1320
|
+
var historyEvent$ = rxjs.from(this.receiveStateEvents(eventType, { stateKey: stateKey, roomIds: roomIds })).pipe(rxjs.mergeAll());
|
|
1321
|
+
var futureEvent$ = this.events$.pipe(rxjs.map(function (event) {
|
|
1322
|
+
var matrixEvent = event.detail.data;
|
|
1323
|
+
if (matrixEvent.type === eventType &&
|
|
1324
|
+
matrixEvent.state_key !== undefined &&
|
|
1325
|
+
(stateKey === undefined || matrixEvent.state_key === stateKey) &&
|
|
1326
|
+
isInRoom(matrixEvent, currentRoomId, roomIds)) {
|
|
1327
|
+
return event.detail.data;
|
|
1519
1328
|
}
|
|
1520
|
-
|
|
1521
|
-
}
|
|
1522
|
-
|
|
1523
|
-
}
|
|
1524
|
-
}
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
var
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1329
|
+
return undefined;
|
|
1330
|
+
}), rxjs.filter(isDefined));
|
|
1331
|
+
return rxjs.concat(historyEvent$, futureEvent$);
|
|
1332
|
+
};
|
|
1333
|
+
/** {@inheritDoc WidgetApi.sendStateEvent} */
|
|
1334
|
+
WidgetApiImpl.prototype.sendStateEvent = function (eventType_1, content_1) {
|
|
1335
|
+
return __awaiter(this, arguments, void 0, function (eventType, content, _a) {
|
|
1336
|
+
var subject, subscription, _b, event_id_1, room_id_1, event_1;
|
|
1337
|
+
var _c = _a === void 0 ? {} : _a, roomId = _c.roomId, _d = _c.stateKey, stateKey = _d === void 0 ? '' : _d;
|
|
1338
|
+
return __generator(this, function (_e) {
|
|
1339
|
+
switch (_e.label) {
|
|
1340
|
+
case 0:
|
|
1341
|
+
subject = new rxjs.ReplaySubject();
|
|
1342
|
+
subscription = this.events$.subscribe(function (e) { return subject.next(e); });
|
|
1343
|
+
_e.label = 1;
|
|
1344
|
+
case 1:
|
|
1345
|
+
_e.trys.push([1, , 4, 5]);
|
|
1346
|
+
return [4 /*yield*/, this.matrixWidgetApi.sendStateEvent(eventType, stateKey, content, roomId)];
|
|
1347
|
+
case 2:
|
|
1348
|
+
_b = _e.sent(), event_id_1 = _b.event_id, room_id_1 = _b.room_id;
|
|
1349
|
+
return [4 /*yield*/, rxjs.firstValueFrom(subject.pipe(rxjs.filter(function (event) {
|
|
1350
|
+
var matrixEvent = event.detail.data;
|
|
1351
|
+
return (matrixEvent.event_id === event_id_1 &&
|
|
1352
|
+
matrixEvent.room_id === room_id_1);
|
|
1353
|
+
}), rxjs.map(function (event) { return event.detail.data; })))];
|
|
1354
|
+
case 3:
|
|
1355
|
+
event_1 = _e.sent();
|
|
1356
|
+
return [2 /*return*/, event_1];
|
|
1357
|
+
case 4:
|
|
1358
|
+
subscription.unsubscribe();
|
|
1359
|
+
return [7 /*endfinally*/];
|
|
1360
|
+
case 5: return [2 /*return*/];
|
|
1361
|
+
}
|
|
1362
|
+
});
|
|
1363
|
+
});
|
|
1364
|
+
};
|
|
1365
|
+
/** {@inheritDoc WidgetApi.receiveRoomEvents} */
|
|
1366
|
+
WidgetApiImpl.prototype.receiveRoomEvents = function (eventType_1) {
|
|
1367
|
+
return __awaiter(this, arguments, void 0, function (eventType, _a) {
|
|
1368
|
+
var _b = _a === void 0 ? {} : _a, messageType = _b.messageType, roomIds = _b.roomIds;
|
|
1369
|
+
return __generator(this, function (_c) {
|
|
1370
|
+
switch (_c.label) {
|
|
1371
|
+
case 0: return [4 /*yield*/, this.matrixWidgetApi.readRoomEvents(eventType, Number.MAX_SAFE_INTEGER, messageType, typeof roomIds === 'string' ? [matrixWidgetApi.Symbols.AnyRoom] : roomIds)];
|
|
1372
|
+
case 1: return [2 /*return*/, (_c.sent())];
|
|
1373
|
+
}
|
|
1374
|
+
});
|
|
1375
|
+
});
|
|
1376
|
+
};
|
|
1377
|
+
/** {@inheritDoc WidgetApi.observeRoomEvents} */
|
|
1378
|
+
WidgetApiImpl.prototype.observeRoomEvents = function (eventType, _a) {
|
|
1379
|
+
var _b = _a === void 0 ? {} : _a, messageType = _b.messageType, roomIds = _b.roomIds;
|
|
1380
|
+
var currentRoomId = this.widgetParameters.roomId;
|
|
1381
|
+
if (!currentRoomId) {
|
|
1382
|
+
return rxjs.throwError(function () { return new Error('Current room id is unknown'); });
|
|
1383
|
+
}
|
|
1384
|
+
var historyEvent$ = rxjs.from(this.receiveRoomEvents(eventType, { messageType: messageType, roomIds: roomIds })).pipe(rxjs.mergeAll());
|
|
1385
|
+
var futureEvent$ = this.events$.pipe(rxjs.map(function (event) {
|
|
1386
|
+
var matrixEvent = event.detail.data;
|
|
1387
|
+
if (matrixEvent.type === eventType &&
|
|
1388
|
+
matrixEvent.state_key === undefined &&
|
|
1389
|
+
(!messageType || matrixEvent.content.msgtype === messageType) &&
|
|
1390
|
+
isInRoom(matrixEvent, currentRoomId, roomIds)) {
|
|
1391
|
+
return event.detail.data;
|
|
1560
1392
|
}
|
|
1393
|
+
return undefined;
|
|
1394
|
+
}), rxjs.filter(isDefined));
|
|
1395
|
+
return rxjs.concat(historyEvent$, futureEvent$);
|
|
1396
|
+
};
|
|
1397
|
+
/** {@inheritDoc WidgetApi.sendRoomEvent} */
|
|
1398
|
+
WidgetApiImpl.prototype.sendRoomEvent = function (eventType_1, content_1) {
|
|
1399
|
+
return __awaiter(this, arguments, void 0, function (eventType, content, _a) {
|
|
1400
|
+
var subject, subscription, _b, event_id_2, room_id_2, event_2;
|
|
1401
|
+
var _c = _a === void 0 ? {} : _a, roomId = _c.roomId;
|
|
1402
|
+
return __generator(this, function (_d) {
|
|
1403
|
+
switch (_d.label) {
|
|
1404
|
+
case 0:
|
|
1405
|
+
subject = new rxjs.ReplaySubject();
|
|
1406
|
+
subscription = this.events$.subscribe(function (e) { return subject.next(e); });
|
|
1407
|
+
_d.label = 1;
|
|
1408
|
+
case 1:
|
|
1409
|
+
_d.trys.push([1, , 4, 5]);
|
|
1410
|
+
return [4 /*yield*/, this.matrixWidgetApi.sendRoomEvent(eventType, content, roomId)];
|
|
1411
|
+
case 2:
|
|
1412
|
+
_b = _d.sent(), event_id_2 = _b.event_id, room_id_2 = _b.room_id;
|
|
1413
|
+
return [4 /*yield*/, rxjs.firstValueFrom(subject.pipe(rxjs.filter(function (event) {
|
|
1414
|
+
var matrixEvent = event.detail.data;
|
|
1415
|
+
return (matrixEvent.event_id === event_id_2 &&
|
|
1416
|
+
matrixEvent.room_id === room_id_2);
|
|
1417
|
+
}), rxjs.map(function (event) { return event.detail.data; })))];
|
|
1418
|
+
case 3:
|
|
1419
|
+
event_2 = _d.sent();
|
|
1420
|
+
return [2 /*return*/, event_2];
|
|
1421
|
+
case 4:
|
|
1422
|
+
subscription.unsubscribe();
|
|
1423
|
+
return [7 /*endfinally*/];
|
|
1424
|
+
case 5: return [2 /*return*/];
|
|
1425
|
+
}
|
|
1426
|
+
});
|
|
1427
|
+
});
|
|
1428
|
+
};
|
|
1429
|
+
/** {@inheritDoc WidgetApi.readEventRelations} */
|
|
1430
|
+
WidgetApiImpl.prototype.readEventRelations = function (eventId, options) {
|
|
1431
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1432
|
+
var _a, chunk, next_batch;
|
|
1433
|
+
return __generator(this, function (_b) {
|
|
1434
|
+
switch (_b.label) {
|
|
1435
|
+
case 0: return [4 /*yield*/, this.matrixWidgetApi.readEventRelations(eventId, options === null || options === void 0 ? void 0 : options.roomId, options === null || options === void 0 ? void 0 : options.relationType, options === null || options === void 0 ? void 0 : options.eventType, options === null || options === void 0 ? void 0 : options.limit, options === null || options === void 0 ? void 0 : options.from, undefined, options === null || options === void 0 ? void 0 : options.direction)];
|
|
1436
|
+
case 1:
|
|
1437
|
+
_a = _b.sent(), chunk = _a.chunk, next_batch = _a.next_batch;
|
|
1438
|
+
return [2 /*return*/, {
|
|
1439
|
+
chunk: chunk,
|
|
1440
|
+
nextToken: next_batch !== null && next_batch !== void 0 ? next_batch : undefined,
|
|
1441
|
+
}];
|
|
1442
|
+
}
|
|
1443
|
+
});
|
|
1444
|
+
});
|
|
1445
|
+
};
|
|
1446
|
+
/** {@inheritDoc WidgetApi.sendToDeviceMessage} */
|
|
1447
|
+
WidgetApiImpl.prototype.sendToDeviceMessage = function (eventType, encrypted, content) {
|
|
1448
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1449
|
+
return __generator(this, function (_a) {
|
|
1450
|
+
switch (_a.label) {
|
|
1451
|
+
case 0: return [4 /*yield*/, this.matrixWidgetApi.sendToDevice(eventType, encrypted, content)];
|
|
1452
|
+
case 1:
|
|
1453
|
+
_a.sent();
|
|
1454
|
+
return [2 /*return*/];
|
|
1455
|
+
}
|
|
1456
|
+
});
|
|
1457
|
+
});
|
|
1458
|
+
};
|
|
1459
|
+
/** {@inheritDoc WidgetApi.observeToDeviceMessages} */
|
|
1460
|
+
WidgetApiImpl.prototype.observeToDeviceMessages = function (eventType) {
|
|
1461
|
+
return this.toDeviceMessages$.pipe(rxjs.map(function (e) { return e.detail.data; }), rxjs.filter(function (e) { return e.type === eventType; }));
|
|
1462
|
+
};
|
|
1463
|
+
/** {@inheritDoc WidgetApi.openModal} */
|
|
1464
|
+
WidgetApiImpl.prototype.openModal = function (pathName, name, options) {
|
|
1465
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1466
|
+
var isModal, url, closeModalWidget$;
|
|
1467
|
+
var _this = this;
|
|
1468
|
+
return __generator(this, function (_a) {
|
|
1469
|
+
switch (_a.label) {
|
|
1470
|
+
case 0:
|
|
1471
|
+
isModal = parseWidgetId(this.widgetId).isModal;
|
|
1472
|
+
if (isModal) {
|
|
1473
|
+
throw new Error("Modals can't be opened from another modal widget");
|
|
1474
|
+
}
|
|
1475
|
+
url = generateWidgetRegistrationUrl({
|
|
1476
|
+
pathName: pathName,
|
|
1477
|
+
widgetParameters: this.widgetParameters,
|
|
1478
|
+
});
|
|
1479
|
+
return [4 /*yield*/, this.matrixWidgetApi.openModalWidget(url, name, options === null || options === void 0 ? void 0 : options.buttons, options === null || options === void 0 ? void 0 : options.data)];
|
|
1480
|
+
case 1:
|
|
1481
|
+
_a.sent();
|
|
1482
|
+
closeModalWidget$ = rxjs.fromEvent(this.matrixWidgetApi, "action:".concat(matrixWidgetApi.WidgetApiToWidgetAction.CloseModalWidget), function (event) {
|
|
1483
|
+
var _a;
|
|
1484
|
+
event.preventDefault();
|
|
1485
|
+
_this.matrixWidgetApi.transport.reply(event.detail, {});
|
|
1486
|
+
if (((_a = event.detail.data) === null || _a === void 0 ? void 0 : _a['m.exited']) === true) {
|
|
1487
|
+
return undefined;
|
|
1488
|
+
}
|
|
1489
|
+
return event.detail.data;
|
|
1490
|
+
});
|
|
1491
|
+
return [2 /*return*/, rxjs.firstValueFrom(closeModalWidget$)];
|
|
1492
|
+
}
|
|
1493
|
+
});
|
|
1494
|
+
});
|
|
1495
|
+
};
|
|
1496
|
+
/** {@inheritDoc WidgetApi.setModalButtonEnabled} */
|
|
1497
|
+
WidgetApiImpl.prototype.setModalButtonEnabled = function (buttonId, isEnabled) {
|
|
1498
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1499
|
+
var isModal;
|
|
1500
|
+
return __generator(this, function (_a) {
|
|
1501
|
+
switch (_a.label) {
|
|
1502
|
+
case 0:
|
|
1503
|
+
isModal = parseWidgetId(this.widgetId).isModal;
|
|
1504
|
+
if (!isModal) {
|
|
1505
|
+
throw new Error('Modal buttons can only be enabled from a modal widget');
|
|
1506
|
+
}
|
|
1507
|
+
return [4 /*yield*/, this.matrixWidgetApi.setModalButtonEnabled(buttonId, isEnabled)];
|
|
1508
|
+
case 1:
|
|
1509
|
+
_a.sent();
|
|
1510
|
+
return [2 /*return*/];
|
|
1511
|
+
}
|
|
1512
|
+
});
|
|
1513
|
+
});
|
|
1514
|
+
};
|
|
1515
|
+
/** {@inheritDoc WidgetApi.observeModalButtons} */
|
|
1516
|
+
WidgetApiImpl.prototype.observeModalButtons = function () {
|
|
1517
|
+
var _this = this;
|
|
1518
|
+
var isModal = parseWidgetId(this.widgetId).isModal;
|
|
1519
|
+
if (!isModal) {
|
|
1520
|
+
throw new Error('Modal buttons can only be observed from a modal widget');
|
|
1521
|
+
}
|
|
1522
|
+
return rxjs.fromEvent(this.matrixWidgetApi, "action:".concat(matrixWidgetApi.WidgetApiToWidgetAction.ButtonClicked), function (event) {
|
|
1523
|
+
event.preventDefault();
|
|
1524
|
+
_this.matrixWidgetApi.transport.reply(event.detail, {});
|
|
1525
|
+
return event.detail.data.id;
|
|
1526
|
+
});
|
|
1527
|
+
};
|
|
1528
|
+
/** {@inheritDoc WidgetApi.closeModal} */
|
|
1529
|
+
WidgetApiImpl.prototype.closeModal = function (data) {
|
|
1530
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1531
|
+
var isModal;
|
|
1532
|
+
return __generator(this, function (_a) {
|
|
1533
|
+
switch (_a.label) {
|
|
1534
|
+
case 0:
|
|
1535
|
+
isModal = parseWidgetId(this.widgetId).isModal;
|
|
1536
|
+
if (!isModal) {
|
|
1537
|
+
throw new Error('Modals can only be closed from a modal widget');
|
|
1538
|
+
}
|
|
1539
|
+
return [4 /*yield*/, this.matrixWidgetApi.closeModalWidget(data ? data : { 'm.exited': true })];
|
|
1540
|
+
case 1:
|
|
1541
|
+
_a.sent();
|
|
1542
|
+
return [2 /*return*/];
|
|
1543
|
+
}
|
|
1544
|
+
});
|
|
1561
1545
|
});
|
|
1562
|
-
}
|
|
1563
|
-
}
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
}
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
}
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
}
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
}
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
}
|
|
1546
|
+
};
|
|
1547
|
+
/** {@inheritdoc WidgetApi.navigateTo} */
|
|
1548
|
+
WidgetApiImpl.prototype.navigateTo = function (uri) {
|
|
1549
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1550
|
+
return __generator(this, function (_a) {
|
|
1551
|
+
switch (_a.label) {
|
|
1552
|
+
case 0: return [4 /*yield*/, this.matrixWidgetApi.navigateTo(uri)];
|
|
1553
|
+
case 1:
|
|
1554
|
+
_a.sent();
|
|
1555
|
+
return [2 /*return*/];
|
|
1556
|
+
}
|
|
1557
|
+
});
|
|
1558
|
+
});
|
|
1559
|
+
};
|
|
1560
|
+
/** {@inheritdoc WidgetApi.requestOpenIDConnectToken} */
|
|
1561
|
+
WidgetApiImpl.prototype.requestOpenIDConnectToken = function () {
|
|
1562
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1563
|
+
return __generator(this, function (_b) {
|
|
1564
|
+
switch (_b.label) {
|
|
1565
|
+
case 0:
|
|
1566
|
+
if (!this.outstandingOpenIDConnectTokenRequest) return [3 /*break*/, 4];
|
|
1567
|
+
_b.label = 1;
|
|
1568
|
+
case 1:
|
|
1569
|
+
_b.trys.push([1, 3, , 4]);
|
|
1570
|
+
return [4 /*yield*/, this.outstandingOpenIDConnectTokenRequest];
|
|
1571
|
+
case 2:
|
|
1572
|
+
_b.sent();
|
|
1573
|
+
return [3 /*break*/, 4];
|
|
1574
|
+
case 3:
|
|
1575
|
+
_b.sent();
|
|
1576
|
+
return [3 /*break*/, 4];
|
|
1577
|
+
case 4:
|
|
1578
|
+
_b.trys.push([4, , 6, 7]);
|
|
1579
|
+
this.outstandingOpenIDConnectTokenRequest =
|
|
1580
|
+
this.requestOpenIDConnectTokenInternal();
|
|
1581
|
+
return [4 /*yield*/, this.outstandingOpenIDConnectTokenRequest];
|
|
1582
|
+
case 5: return [2 /*return*/, _b.sent()];
|
|
1583
|
+
case 6:
|
|
1584
|
+
this.outstandingOpenIDConnectTokenRequest = undefined;
|
|
1585
|
+
return [7 /*endfinally*/];
|
|
1586
|
+
case 7: return [2 /*return*/];
|
|
1587
|
+
}
|
|
1588
|
+
});
|
|
1589
|
+
});
|
|
1590
|
+
};
|
|
1591
|
+
WidgetApiImpl.prototype.requestOpenIDConnectTokenInternal = function () {
|
|
1592
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1593
|
+
var leywayMilliseconds, openIdToken, err_2;
|
|
1594
|
+
var _a;
|
|
1595
|
+
return __generator(this, function (_b) {
|
|
1596
|
+
switch (_b.label) {
|
|
1597
|
+
case 0:
|
|
1598
|
+
leywayMilliseconds = 30 * 1000;
|
|
1599
|
+
if (this.cachedOpenIdToken &&
|
|
1600
|
+
this.cachedOpenIdToken.expiresAt - leywayMilliseconds > Date.now()) {
|
|
1601
|
+
return [2 /*return*/, this.cachedOpenIdToken.openIdToken];
|
|
1602
|
+
}
|
|
1603
|
+
_b.label = 1;
|
|
1604
|
+
case 1:
|
|
1605
|
+
_b.trys.push([1, 3, , 4]);
|
|
1606
|
+
return [4 /*yield*/, this.matrixWidgetApi.requestOpenIDConnectToken()];
|
|
1607
|
+
case 2:
|
|
1608
|
+
openIdToken = _b.sent();
|
|
1609
|
+
this.cachedOpenIdToken = {
|
|
1610
|
+
openIdToken: openIdToken,
|
|
1611
|
+
expiresAt: Date.now() + ((_a = openIdToken.expires_in) !== null && _a !== void 0 ? _a : 0) * 1000,
|
|
1612
|
+
};
|
|
1613
|
+
return [2 /*return*/, openIdToken];
|
|
1614
|
+
case 3:
|
|
1615
|
+
err_2 = _b.sent();
|
|
1616
|
+
this.cachedOpenIdToken = undefined;
|
|
1617
|
+
throw err_2;
|
|
1618
|
+
case 4: return [2 /*return*/];
|
|
1619
|
+
}
|
|
1620
|
+
});
|
|
1621
|
+
});
|
|
1622
|
+
};
|
|
1623
|
+
/** {@inheritdoc WidgetApi.observeTurnServers} */
|
|
1624
|
+
WidgetApiImpl.prototype.observeTurnServers = function () {
|
|
1625
|
+
return rxjs.from(this.matrixWidgetApi.getTurnServers()).pipe(
|
|
1626
|
+
// For some reason a different naming was chosen for the API, but
|
|
1627
|
+
// we already convert them to the right type for WebRTC consumers.
|
|
1628
|
+
rxjs.map(function (_a) {
|
|
1629
|
+
var uris = _a.uris, username = _a.username, password = _a.password;
|
|
1630
|
+
return ({
|
|
1631
|
+
urls: uris,
|
|
1632
|
+
username: username,
|
|
1633
|
+
credential: password,
|
|
1634
|
+
});
|
|
1635
|
+
}));
|
|
1636
|
+
};
|
|
1637
|
+
/** {@inheritdoc WidgetApi.searchUserDirectory} */
|
|
1638
|
+
WidgetApiImpl.prototype.searchUserDirectory = function (searchTerm, options) {
|
|
1639
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1640
|
+
var results;
|
|
1641
|
+
return __generator(this, function (_a) {
|
|
1642
|
+
switch (_a.label) {
|
|
1643
|
+
case 0: return [4 /*yield*/, this.matrixWidgetApi.searchUserDirectory(searchTerm, options === null || options === void 0 ? void 0 : options.limit)];
|
|
1644
|
+
case 1:
|
|
1645
|
+
results = (_a.sent()).results;
|
|
1646
|
+
return [2 /*return*/, {
|
|
1647
|
+
results: results.map(function (_a) {
|
|
1648
|
+
var user_id = _a.user_id, display_name = _a.display_name, avatar_url = _a.avatar_url;
|
|
1649
|
+
return ({
|
|
1650
|
+
userId: user_id,
|
|
1651
|
+
displayName: display_name,
|
|
1652
|
+
avatarUrl: avatar_url,
|
|
1653
|
+
});
|
|
1654
|
+
}),
|
|
1655
|
+
}];
|
|
1656
|
+
}
|
|
1657
|
+
});
|
|
1658
|
+
});
|
|
1659
|
+
};
|
|
1660
|
+
/** {@inheritdoc WidgetApi.getMediaConfig} */
|
|
1661
|
+
WidgetApiImpl.prototype.getMediaConfig = function () {
|
|
1662
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1663
|
+
return __generator(this, function (_a) {
|
|
1664
|
+
switch (_a.label) {
|
|
1665
|
+
case 0: return [4 /*yield*/, this.matrixWidgetApi.getMediaConfig()];
|
|
1666
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1667
|
+
}
|
|
1668
|
+
});
|
|
1669
|
+
});
|
|
1670
|
+
};
|
|
1671
|
+
/** {@inheritdoc WidgetApi.uploadFile} */
|
|
1672
|
+
WidgetApiImpl.prototype.uploadFile = function (file) {
|
|
1673
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1674
|
+
return __generator(this, function (_a) {
|
|
1675
|
+
switch (_a.label) {
|
|
1676
|
+
case 0: return [4 /*yield*/, this.matrixWidgetApi.uploadFile(file)];
|
|
1677
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1678
|
+
}
|
|
1679
|
+
});
|
|
1680
|
+
});
|
|
1681
|
+
};
|
|
1682
|
+
return WidgetApiImpl;
|
|
1683
|
+
}());
|
|
1684
1684
|
|
|
1685
1685
|
exports.ROOM_EVENT_REDACTION = ROOM_EVENT_REDACTION;
|
|
1686
1686
|
exports.STATE_EVENT_POWER_LEVELS = STATE_EVENT_POWER_LEVELS;
|