Remove dead & duplicated code (#11405)

* Remove dead code

* Make dead code happier

* DRY pickle additional data calculation

* Iterate
This commit is contained in:
Michael Telatynski 2023-08-15 09:43:15 +01:00 committed by GitHub
parent 672ad98ec7
commit 27d79458da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 50 additions and 201 deletions

View file

@ -411,45 +411,6 @@ export default class WidgetUtils {
return widgets.filter((w) => w.content?.type === "m.integration_manager");
}
public static getRoomWidgetsOfType(room: Room, type: WidgetType): MatrixEvent[] {
const widgets = WidgetUtils.getRoomWidgets(room) || [];
return widgets.filter((w) => {
const content = w.getContent();
return content.url && type.matches(content.type);
});
}
public static async removeIntegrationManagerWidgets(client: MatrixClient | undefined): Promise<void> {
if (!client) {
throw new Error("User not logged in");
}
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.integration_manager") {
delete userWidgets[key];
}
});
await client.setAccountData("m.widgets", userWidgets);
}
public static addIntegrationManagerWidget(
client: MatrixClient,
name: string,
uiUrl: string,
apiUrl: string,
): Promise<void> {
return WidgetUtils.setUserWidget(
client,
"integration_manager_" + new Date().getTime(),
WidgetType.INTEGRATION_MANAGER,
uiUrl,
"Integration manager: " + name,
{ api_url: apiUrl },
);
}
/**
* Remove all stickerpicker widgets (stickerpickers are user widgets by nature)
* @param client The matrix client of the logged-in user