2018-03-24 14:18:38 -04:00
|
|
|
import { Component } from "@angular/core";
|
|
|
|
import { ToasterService } from "angular2-toaster";
|
2018-03-24 19:16:52 -04:00
|
|
|
import { FE_Appservice, FE_NebConfiguration } from "../../../shared/models/admin-responses";
|
2018-03-24 14:18:38 -04:00
|
|
|
import { AdminAppserviceApiService } from "../../../shared/services/admin/admin-appservice-api.service";
|
2020-10-23 07:30:20 -04:00
|
|
|
import { TranslateService } from "@ngx-translate/core";
|
2021-08-16 18:00:59 -04:00
|
|
|
import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
|
2018-03-24 14:18:38 -04:00
|
|
|
|
2021-08-16 18:00:59 -04:00
|
|
|
export interface AppserviceConfigDialogContext {
|
|
|
|
neb: FE_NebConfiguration;
|
2018-03-24 14:18:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
templateUrl: "./appservice-config.component.html",
|
|
|
|
styleUrls: ["./appservice-config.component.scss"],
|
|
|
|
})
|
2021-08-16 18:00:59 -04:00
|
|
|
export class AdminNebAppserviceConfigComponent {
|
2018-03-24 14:18:38 -04:00
|
|
|
|
|
|
|
public isLoading = true;
|
|
|
|
public neb: FE_NebConfiguration;
|
|
|
|
public appservice: FE_Appservice;
|
|
|
|
|
2021-08-16 18:00:59 -04:00
|
|
|
constructor(public modal: NgbActiveModal,
|
2021-09-01 19:01:01 -04:00
|
|
|
private adminAppserviceApi: AdminAppserviceApiService,
|
|
|
|
private toaster: ToasterService,
|
|
|
|
public translate: TranslateService) {
|
2020-10-23 07:30:20 -04:00
|
|
|
this.translate = translate;
|
2018-03-24 14:18:38 -04:00
|
|
|
this.adminAppserviceApi.getAppservice(this.neb.appserviceId).then(appservice => {
|
|
|
|
this.appservice = appservice;
|
|
|
|
this.isLoading = false;
|
|
|
|
}).catch(err => {
|
|
|
|
console.error(err);
|
2021-09-01 19:01:01 -04:00
|
|
|
this.translate.get('Could not load appservice configuration').subscribe((res: string) => {
|
|
|
|
this.toaster.pop("error", res);
|
|
|
|
});
|
2018-03-24 14:18:38 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public get appserviceConfig(): string {
|
|
|
|
return `` +
|
|
|
|
`id: ${this.appservice.id}\n` +
|
|
|
|
`url: ${window.location.origin}/_matrix/appservice/r0\n` +
|
|
|
|
`as_token: ${this.appservice.asToken}\n` +
|
|
|
|
`hs_token: ${this.appservice.hsToken}\n` +
|
|
|
|
`sender_localpart: ${this.appservice.userPrefix}\n` +
|
|
|
|
`namespaces:\n` +
|
|
|
|
` users:\n` +
|
|
|
|
` - exclusive: true\n` +
|
|
|
|
` regex: '@${this.appservice.userPrefix}.*'\n` +
|
|
|
|
` aliases: []\n` +
|
|
|
|
` rooms: []`;
|
|
|
|
}
|
|
|
|
|
|
|
|
public test() {
|
|
|
|
this.adminAppserviceApi.test(this.neb.appserviceId).then(() => {
|
2021-09-01 19:01:01 -04:00
|
|
|
this.translate.get('The appservice appears to be correctly set up').subscribe((res: string) => {
|
|
|
|
this.toaster.pop("success", res);
|
|
|
|
});
|
2018-03-24 14:18:38 -04:00
|
|
|
}).catch(err => {
|
|
|
|
console.error(err);
|
2021-09-01 19:01:01 -04:00
|
|
|
this.translate.get('The appservice is not correctly set up').subscribe((res: string) => {
|
|
|
|
this.toaster.pop("error", res);
|
|
|
|
});
|
2018-03-24 14:18:38 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|