2018-09-16 04:26:10 -04:00
|
|
|
import { Component } from "@angular/core";
|
2021-08-16 18:00:59 -04:00
|
|
|
import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
|
2018-09-16 04:26:10 -04:00
|
|
|
import { ToasterService } from "angular2-toaster";
|
|
|
|
import { AdminTelegramApiService } from "../../../../shared/services/admin/admin-telegram-api.service";
|
2020-10-23 07:30:20 -04:00
|
|
|
import { TranslateService } from "@ngx-translate/core";
|
2018-09-16 04:26:10 -04:00
|
|
|
|
2021-08-16 18:00:59 -04:00
|
|
|
export interface ManageSelfhostedTelegramBridgeDialogContext {
|
|
|
|
provisionUrl: string;
|
|
|
|
sharedSecret: string;
|
|
|
|
allowTgPuppets: boolean;
|
|
|
|
allowMxPuppets: boolean;
|
|
|
|
bridgeId: number;
|
|
|
|
isAdding: boolean;
|
2018-09-16 04:26:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
templateUrl: "./manage-selfhosted.component.html",
|
|
|
|
styleUrls: ["./manage-selfhosted.component.scss"],
|
|
|
|
})
|
2021-08-16 18:00:59 -04:00
|
|
|
export class AdminTelegramBridgeManageSelfhostedComponent {
|
2018-09-16 04:26:10 -04:00
|
|
|
|
2021-08-16 18:00:59 -04:00
|
|
|
isSaving = false;
|
|
|
|
provisionUrl: string;
|
|
|
|
sharedSecret: string;
|
|
|
|
allowTgPuppets = false;
|
|
|
|
allowMxPuppets = false;
|
|
|
|
bridgeId: number;
|
|
|
|
isAdding = true;
|
2018-09-16 04:26:10 -04:00
|
|
|
|
2021-08-16 18:00:59 -04:00
|
|
|
constructor(public modal: NgbActiveModal,
|
2021-09-01 19:01:01 -04:00
|
|
|
private telegramApi: AdminTelegramApiService,
|
|
|
|
private toaster: ToasterService,
|
|
|
|
public translate: TranslateService) {
|
2020-10-23 07:30:20 -04:00
|
|
|
this.translate = translate;
|
2018-09-16 04:26:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public add() {
|
|
|
|
this.isSaving = true;
|
2018-10-17 23:09:19 -04:00
|
|
|
const options = {
|
|
|
|
allowTgPuppets: this.allowTgPuppets,
|
|
|
|
allowMxPuppets: this.allowMxPuppets,
|
|
|
|
};
|
2018-09-16 04:26:10 -04:00
|
|
|
if (this.isAdding) {
|
2018-10-17 23:09:19 -04:00
|
|
|
this.telegramApi.newSelfhosted(this.provisionUrl, this.sharedSecret, options).then(() => {
|
2021-09-01 19:01:01 -04:00
|
|
|
this.translate.get('Telegram bridge added').subscribe((res: string) => {
|
|
|
|
this.toaster.pop("success", res);
|
|
|
|
});
|
2021-08-16 18:00:59 -04:00
|
|
|
this.modal.close();
|
2018-09-16 04:26:10 -04:00
|
|
|
}).catch(err => {
|
|
|
|
console.error(err);
|
|
|
|
this.isSaving = false;
|
2021-09-01 19:01:01 -04:00
|
|
|
this.translate.get('Failed to create Telegram bridge').subscribe((res: string) => {
|
|
|
|
this.toaster.pop("error", res);
|
|
|
|
});
|
2018-09-16 04:26:10 -04:00
|
|
|
});
|
|
|
|
} else {
|
2018-10-17 23:09:19 -04:00
|
|
|
this.telegramApi.updateSelfhosted(this.bridgeId, this.provisionUrl, this.sharedSecret, options).then(() => {
|
2021-09-01 19:01:01 -04:00
|
|
|
this.translate.get('Telegram bridge updated').subscribe((res: string) => {
|
|
|
|
this.toaster.pop("success", res);
|
|
|
|
});
|
2021-08-16 18:00:59 -04:00
|
|
|
this.modal.close();
|
2018-09-16 04:26:10 -04:00
|
|
|
}).catch(err => {
|
|
|
|
console.error(err);
|
|
|
|
this.isSaving = false;
|
2021-09-01 19:01:01 -04:00
|
|
|
this.translate.get('Failed to update Telegram bridge').subscribe((res: string) => {
|
|
|
|
this.toaster.pop("error", res);
|
|
|
|
});
|
2018-09-16 04:26:10 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|