Remove dead & duplicated code (#11405)
* Remove dead code * Make dead code happier * DRY pickle additional data calculation * Iterate
This commit is contained in:
parent
672ad98ec7
commit
27d79458da
25 changed files with 50 additions and 201 deletions
|
@ -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
|
||||
|
|
|
@ -69,8 +69,4 @@ export class PermalinkParts {
|
|||
public get primaryEntityId(): string | null {
|
||||
return this.roomIdOrAlias || this.userId;
|
||||
}
|
||||
|
||||
public get sigil(): string {
|
||||
return this.primaryEntityId?.[0] || "?";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,6 +114,7 @@ export class RoomPermalinkCreator {
|
|||
}
|
||||
|
||||
public start(): void {
|
||||
if (this.started) return;
|
||||
this.load();
|
||||
this.room?.currentState.on(RoomStateEvent.Update, this.onRoomStateUpdate);
|
||||
this.started = true;
|
||||
|
@ -128,10 +129,6 @@ export class RoomPermalinkCreator {
|
|||
return this._serverCandidates;
|
||||
}
|
||||
|
||||
public isStarted(): boolean {
|
||||
return this.started;
|
||||
}
|
||||
|
||||
public forEvent(eventId: string): string {
|
||||
return getPermalinkConstructor().forEvent(this.roomId, eventId, this._serverCandidates);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue