Apply prettier formatting

This commit is contained in:
Michael Weimann 2022-12-12 12:24:14 +01:00
parent 1cac306093
commit 526645c791
No known key found for this signature in database
GPG key ID: 53F535A266BB9584
1576 changed files with 65385 additions and 62478 deletions

View file

@ -25,11 +25,11 @@ import { ClientEvent, RoomStateEvent } from "matrix-js-sdk/src/matrix";
import { CallType } from "matrix-js-sdk/src/webrtc/call";
import { randomString, randomLowercaseString, randomUppercaseString } from "matrix-js-sdk/src/randomstring";
import { MatrixClientPeg } from '../MatrixClientPeg';
import PlatformPeg from '../PlatformPeg';
import { MatrixClientPeg } from "../MatrixClientPeg";
import PlatformPeg from "../PlatformPeg";
import SdkConfig from "../SdkConfig";
import dis from '../dispatcher/dispatcher';
import WidgetEchoStore from '../stores/WidgetEchoStore';
import dis from "../dispatcher/dispatcher";
import WidgetEchoStore from "../stores/WidgetEchoStore";
import { IntegrationManagers } from "../integrations/IntegrationManagers";
import { WidgetType } from "../widgets/WidgetType";
import { Jitsi } from "../widgets/Jitsi";
@ -59,13 +59,13 @@ export default class WidgetUtils {
*/
static canUserModifyWidgets(roomId: string): boolean {
if (!roomId) {
logger.warn('No room ID specified');
logger.warn("No room ID specified");
return false;
}
const client = MatrixClientPeg.get();
if (!client) {
logger.warn('User must be be logged in');
logger.warn("User must be be logged in");
return false;
}
@ -77,7 +77,7 @@ export default class WidgetUtils {
const me = client.credentials.userId;
if (!me) {
logger.warn('Failed to get user ID');
logger.warn("Failed to get user ID");
return false;
}
@ -87,7 +87,7 @@ export default class WidgetUtils {
}
// TODO: Enable support for m.widget event type (https://github.com/vector-im/element-web/issues/13111)
return room.currentState.maySendStateEvent('im.vector.modular.widgets', me);
return room.currentState.maySendStateEvent("im.vector.modular.widgets", me);
}
// TODO: Generify the name of this function. It's not just scalar.
@ -98,7 +98,7 @@ export default class WidgetUtils {
*/
static isScalarUrl(testUrlString: string): boolean {
if (!testUrlString) {
logger.error('Scalar URL check failed. No URL specified');
logger.error("Scalar URL check failed. No URL specified");
return false;
}
@ -152,14 +152,14 @@ export default class WidgetUtils {
}
}
const startingAccountDataEvent = MatrixClientPeg.get().getAccountData('m.widgets');
const startingAccountDataEvent = MatrixClientPeg.get().getAccountData("m.widgets");
if (eventInIntendedState(startingAccountDataEvent)) {
resolve();
return;
}
function onAccountData(ev) {
const currentAccountDataEvent = MatrixClientPeg.get().getAccountData('m.widgets');
const currentAccountDataEvent = MatrixClientPeg.get().getAccountData("m.widgets");
if (eventInIntendedState(currentAccountDataEvent)) {
MatrixClientPeg.get().removeListener(ClientEvent.AccountData, onAccountData);
clearTimeout(timerId);
@ -192,7 +192,7 @@ export default class WidgetUtils {
// we're waiting for it to be in
function eventsInIntendedState(evList) {
const widgetPresent = evList.some((ev) => {
return ev.getContent() && ev.getContent()['id'] === widgetId;
return ev.getContent() && ev.getContent()["id"] === widgetId;
});
if (add) {
return widgetPresent;
@ -203,7 +203,7 @@ export default class WidgetUtils {
const room = MatrixClientPeg.get().getRoom(roomId);
// TODO: Enable support for m.widget event type (https://github.com/vector-im/element-web/issues/13111)
const startingWidgetEvents = room.currentState.getStateEvents('im.vector.modular.widgets');
const startingWidgetEvents = room.currentState.getStateEvents("im.vector.modular.widgets");
if (eventsInIntendedState(startingWidgetEvents)) {
resolve();
return;
@ -213,7 +213,7 @@ export default class WidgetUtils {
if (ev.getRoomId() !== roomId || ev.getType() !== "im.vector.modular.widgets") return;
// TODO: Enable support for m.widget event type (https://github.com/vector-im/element-web/issues/13111)
const currentWidgetEvents = room.currentState.getStateEvents('im.vector.modular.widgets');
const currentWidgetEvents = room.currentState.getStateEvents("im.vector.modular.widgets");
if (eventsInIntendedState(currentWidgetEvents)) {
MatrixClientPeg.get().removeListener(RoomStateEvent.Events, onRoomStateEvents);
@ -263,7 +263,7 @@ export default class WidgetUtils {
content: content,
sender: client.getUserId(),
state_key: widgetId,
type: 'm.widget',
type: "m.widget",
id: widgetId,
};
}
@ -272,11 +272,14 @@ export default class WidgetUtils {
// since the widget won't appear added until this happens. If we don't
// wait for this, the action will complete but if the user is fast enough,
// the widget still won't actually be there.
return client.setAccountData('m.widgets', userWidgets).then(() => {
return WidgetUtils.waitForUserWidget(widgetId, addingWidget);
}).then(() => {
dis.dispatch({ action: "user_widget_updated" });
});
return client
.setAccountData("m.widgets", userWidgets)
.then(() => {
return WidgetUtils.waitForUserWidget(widgetId, addingWidget);
})
.then(() => {
dis.dispatch({ action: "user_widget_updated" });
});
}
static setRoomWidget(
@ -309,22 +312,21 @@ export default class WidgetUtils {
return WidgetUtils.setRoomWidgetContent(roomId, widgetId, content);
}
static setRoomWidgetContent(
roomId: string,
widgetId: string,
content: IWidget,
) {
static setRoomWidgetContent(roomId: string, widgetId: string, content: IWidget) {
const addingWidget = !!content.url;
WidgetEchoStore.setRoomWidgetEcho(roomId, widgetId, content);
const client = MatrixClientPeg.get();
// TODO: Enable support for m.widget event type (https://github.com/vector-im/element-web/issues/13111)
return client.sendStateEvent(roomId, "im.vector.modular.widgets", content, widgetId).then(() => {
return WidgetUtils.waitForRoomWidget(widgetId, roomId, addingWidget);
}).finally(() => {
WidgetEchoStore.removeRoomWidgetEcho(roomId, widgetId);
});
return client
.sendStateEvent(roomId, "im.vector.modular.widgets", content, widgetId)
.then(() => {
return WidgetUtils.waitForRoomWidget(widgetId, roomId, addingWidget);
})
.finally(() => {
WidgetEchoStore.removeRoomWidgetEcho(roomId, widgetId);
});
}
/**
@ -334,7 +336,7 @@ export default class WidgetUtils {
*/
static getRoomWidgets(room: Room) {
// TODO: Enable support for m.widget event type (https://github.com/vector-im/element-web/issues/13111)
const appsStateEvents = room.currentState.getStateEvents('im.vector.modular.widgets');
const appsStateEvents = room.currentState.getStateEvents("im.vector.modular.widgets");
if (!appsStateEvents) {
return [];
}
@ -351,9 +353,9 @@ export default class WidgetUtils {
static getUserWidgets(): Record<string, IWidgetEvent> {
const client = MatrixClientPeg.get();
if (!client) {
throw new Error('User not logged in');
throw new Error("User not logged in");
}
const userWidgets = client.getAccountData('m.widgets');
const userWidgets = client.getAccountData("m.widgets");
if (userWidgets && userWidgets.getContent()) {
return userWidgets.getContent();
}
@ -383,12 +385,12 @@ export default class WidgetUtils {
*/
static getIntegrationManagerWidgets(): IWidgetEvent[] {
const widgets = WidgetUtils.getUserWidgetsArray();
return widgets.filter(w => w.content && w.content.type === "m.integration_manager");
return widgets.filter((w) => w.content && w.content.type === "m.integration_manager");
}
static getRoomWidgetsOfType(room: Room, type: WidgetType): MatrixEvent[] {
const widgets = WidgetUtils.getRoomWidgets(room) || [];
return widgets.filter(w => {
return widgets.filter((w) => {
const content = w.getContent();
return content.url && type.matches(content.type);
});
@ -397,9 +399,9 @@ export default class WidgetUtils {
static async removeIntegrationManagerWidgets(): Promise<void> {
const client = MatrixClientPeg.get();
if (!client) {
throw new Error('User not logged in');
throw new Error("User not logged in");
}
const widgets = client.getAccountData('m.widgets');
const widgets = client.getAccountData("m.widgets");
if (!widgets) return;
const userWidgets: Record<string, IWidgetEvent> = widgets.getContent() || {};
Object.entries(userWidgets).forEach(([key, widget]) => {
@ -407,16 +409,16 @@ export default class WidgetUtils {
delete userWidgets[key];
}
});
await client.setAccountData('m.widgets', userWidgets);
await client.setAccountData("m.widgets", userWidgets);
}
static addIntegrationManagerWidget(name: string, uiUrl: string, apiUrl: string): Promise<void> {
return WidgetUtils.setUserWidget(
"integration_manager_" + (new Date().getTime()),
"integration_manager_" + new Date().getTime(),
WidgetType.INTEGRATION_MANAGER,
uiUrl,
"Integration manager: " + name,
{ "api_url": apiUrl },
{ api_url: apiUrl },
);
}
@ -427,17 +429,17 @@ export default class WidgetUtils {
static async removeStickerpickerWidgets(): Promise<void> {
const client = MatrixClientPeg.get();
if (!client) {
throw new Error('User not logged in');
throw new Error("User not logged in");
}
const widgets = client.getAccountData('m.widgets');
const widgets = client.getAccountData("m.widgets");
if (!widgets) return;
const userWidgets: Record<string, IWidgetEvent> = widgets.getContent() || {};
Object.entries(userWidgets).forEach(([key, widget]) => {
if (widget.content && widget.content.type === 'm.stickerpicker') {
if (widget.content && widget.content.type === "m.stickerpicker") {
delete userWidgets[key];
}
});
await client.setAccountData('m.widgets', userWidgets);
await client.setAccountData("m.widgets", userWidgets);
}
static async addJitsiWidget(
@ -452,7 +454,7 @@ export default class WidgetUtils {
const widgetId = randomString(24); // Must be globally unique
let confId;
if (auth === 'openidtoken-jwt') {
if (auth === "openidtoken-jwt") {
// Create conference ID from room ID
// For compatibility with Jitsi, use base32 without padding.
// More details here:
@ -465,8 +467,8 @@ export default class WidgetUtils {
// TODO: Remove URL hacks when the mobile clients eventually support v2 widgets
const widgetUrl = new URL(WidgetUtils.getLocalJitsiWrapperUrl({ auth }));
widgetUrl.search = ''; // Causes the URL class use searchParams instead
widgetUrl.searchParams.set('confId', confId);
widgetUrl.search = ""; // Causes the URL class use searchParams instead
widgetUrl.searchParams.set("confId", confId);
await WidgetUtils.setRoomWidget(roomId, widgetId, WidgetType.JITSI, widgetUrl.toString(), name, {
conferenceId: confId,
@ -498,26 +500,26 @@ export default class WidgetUtils {
return app as IApp;
}
static getLocalJitsiWrapperUrl(opts: {forLocalRender?: boolean, auth?: string} = {}) {
static getLocalJitsiWrapperUrl(opts: { forLocalRender?: boolean; auth?: string } = {}) {
// NB. we can't just encodeURIComponent all of these because the $ signs need to be there
const queryStringParts = [
'conferenceDomain=$domain',
'conferenceId=$conferenceId',
'isAudioOnly=$isAudioOnly',
'isVideoChannel=$isVideoChannel',
'displayName=$matrix_display_name',
'avatarUrl=$matrix_avatar_url',
'userId=$matrix_user_id',
'roomId=$matrix_room_id',
'theme=$theme',
'roomName=$roomName',
"conferenceDomain=$domain",
"conferenceId=$conferenceId",
"isAudioOnly=$isAudioOnly",
"isVideoChannel=$isVideoChannel",
"displayName=$matrix_display_name",
"avatarUrl=$matrix_avatar_url",
"userId=$matrix_user_id",
"roomId=$matrix_room_id",
"theme=$theme",
"roomName=$roomName",
`supportsScreensharing=${PlatformPeg.get().supportsJitsiScreensharing()}`,
'language=$org.matrix.msc2873.client_language',
"language=$org.matrix.msc2873.client_language",
];
if (opts.auth) {
queryStringParts.push(`auth=${opts.auth}`);
}
const queryString = queryStringParts.join('&');
const queryString = queryStringParts.join("&");
let baseUrl = window.location.href;
if (window.location.protocol !== "https:" && !opts.forLocalRender) {
@ -550,7 +552,9 @@ export default class WidgetUtils {
static editWidget(room: Room, app: IApp): void {
// noinspection JSIgnoredPromiseFromCall
IntegrationManagers.sharedInstance().getPrimaryManager().open(room, 'type_' + app.type, app.id);
IntegrationManagers.sharedInstance()
.getPrimaryManager()
.open(room, "type_" + app.type, app.id);
}
static isManagedByManager(app) {