mirror of
https://github.com/turt2live/matrix-dimension.git
synced 2024-10-01 01:05:53 -04:00
100 lines
3.3 KiB
TypeScript
100 lines
3.3 KiB
TypeScript
import { Component, OnInit } from "@angular/core";
|
|
import { BridgeComponent } from "../bridge.component";
|
|
import { ScalarClientApiService } from "../../../shared/services/scalar/scalar-client-api.service";
|
|
import { SafeUrl } from "@angular/platform-browser";
|
|
import { TranslateService } from "@ngx-translate/core";
|
|
import { HookshotJiraApiService } from "../../../shared/services/integrations/hookshot-jira-api.service";
|
|
import { FE_HookshotJiraConnection } from "../../../shared/models/hookshot_jira";
|
|
|
|
interface HookshotConfig {
|
|
botUserId: string;
|
|
connections: FE_HookshotJiraConnection[];
|
|
}
|
|
|
|
@Component({
|
|
templateUrl: "hookshot-jira.bridge.component.html",
|
|
styleUrls: ["hookshot-jira.bridge.component.scss"],
|
|
})
|
|
export class HookshotJiraBridgeConfigComponent extends BridgeComponent<HookshotConfig> implements OnInit {
|
|
|
|
public isBusy: boolean;
|
|
public needsAuth = false;
|
|
public authUrl: SafeUrl;
|
|
public loadingConnections = false;
|
|
public orgs: string[] = [];
|
|
public repos: string[] = []; // for org
|
|
public orgId: string;
|
|
public repoId: string;
|
|
|
|
constructor(private hookshot: HookshotJiraApiService, private scalar: ScalarClientApiService, public translate: TranslateService) {
|
|
super("hookshot_jira", translate);
|
|
this.translate = translate;
|
|
}
|
|
|
|
public ngOnInit() {
|
|
super.ngOnInit();
|
|
|
|
this.prepare();
|
|
}
|
|
|
|
private prepare() {
|
|
|
|
}
|
|
|
|
public loadRepos() {
|
|
// TODO
|
|
}
|
|
|
|
public get isBridged(): boolean {
|
|
return this.bridge.config.connections.length > 0;
|
|
}
|
|
|
|
public async bridgeRoom(): Promise<any> {
|
|
this.isBusy = true;
|
|
|
|
try {
|
|
await this.scalar.inviteUser(this.roomId, this.bridge.config.botUserId);
|
|
} catch (e) {
|
|
if (!e.response || !e.response.error || !e.response.error._error ||
|
|
e.response.error._error.message.indexOf("already in the room") === -1) {
|
|
this.isBusy = false;
|
|
this.translate.get('Error inviting bridge').subscribe((res: string) => {
|
|
this.toaster.pop("error", res);
|
|
});
|
|
return;
|
|
}
|
|
}
|
|
|
|
this.hookshot.bridgeRoom(this.roomId).then(conn => {
|
|
this.bridge.config.connections.push(conn);
|
|
this.isBusy = false;
|
|
this.translate.get('Bridge requested').subscribe((res: string) => {
|
|
this.toaster.pop("success", res);
|
|
});
|
|
}).catch(error => {
|
|
this.isBusy = false;
|
|
console.error(error);
|
|
this.translate.get('Error requesting bridge').subscribe((res: string) => {
|
|
this.toaster.pop("error", res);
|
|
});
|
|
});
|
|
}
|
|
|
|
public unbridgeRoom(): void {
|
|
this.isBusy = true;
|
|
this.hookshot.unbridgeRoom(this.roomId).then(() => {
|
|
this.bridge.config.connections = [];
|
|
this.isBusy = false;
|
|
this.translate.get('Bridge removed').subscribe((res: string) => {
|
|
this.toaster.pop("success", res);
|
|
});
|
|
}).catch(error => {
|
|
this.isBusy = false;
|
|
console.error(error);
|
|
this.translate.get('Error removing bridge').subscribe((res: string) => {
|
|
this.toaster.pop("error", res);
|
|
});
|
|
});
|
|
}
|
|
}
|