2018-09-16 04:26:10 -04:00
|
|
|
import { Component } from "@angular/core";
|
|
|
|
import { ToasterService } from "angular2-toaster";
|
|
|
|
import { DialogRef, ModalComponent } from "ngx-modialog";
|
|
|
|
import { BSModalContext } from "ngx-modialog/plugins/bootstrap";
|
|
|
|
import { AdminTelegramApiService } from "../../../../shared/services/admin/admin-telegram-api.service";
|
|
|
|
|
|
|
|
export class ManageSelfhostedTelegramBridgeDialogContext extends BSModalContext {
|
|
|
|
public provisionUrl: string;
|
|
|
|
public sharedSecret: string;
|
2018-10-17 23:09:19 -04:00
|
|
|
public allowTgPuppets = false;
|
|
|
|
public allowMxPuppets = false;
|
2018-09-16 04:26:10 -04:00
|
|
|
public bridgeId: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
templateUrl: "./manage-selfhosted.component.html",
|
|
|
|
styleUrls: ["./manage-selfhosted.component.scss"],
|
|
|
|
})
|
|
|
|
export class AdminTelegramBridgeManageSelfhostedComponent implements ModalComponent<ManageSelfhostedTelegramBridgeDialogContext> {
|
|
|
|
|
|
|
|
public isSaving = false;
|
|
|
|
public provisionUrl: string;
|
|
|
|
public sharedSecret: string;
|
2018-10-17 23:09:19 -04:00
|
|
|
public allowTgPuppets = false;
|
|
|
|
public allowMxPuppets = false;
|
2018-09-16 04:26:10 -04:00
|
|
|
public bridgeId: number;
|
|
|
|
public isAdding = false;
|
|
|
|
|
|
|
|
constructor(public dialog: DialogRef<ManageSelfhostedTelegramBridgeDialogContext>,
|
|
|
|
private telegramApi: AdminTelegramApiService,
|
|
|
|
private toaster: ToasterService) {
|
|
|
|
this.provisionUrl = dialog.context.provisionUrl;
|
|
|
|
this.sharedSecret = dialog.context.sharedSecret;
|
2018-10-17 23:09:19 -04:00
|
|
|
this.allowTgPuppets = dialog.context.allowTgPuppets;
|
|
|
|
this.allowMxPuppets = dialog.context.allowMxPuppets;
|
2018-09-16 04:26:10 -04:00
|
|
|
this.bridgeId = dialog.context.bridgeId;
|
|
|
|
this.isAdding = !this.bridgeId;
|
|
|
|
}
|
|
|
|
|
|
|
|
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(() => {
|
2018-09-16 04:26:10 -04:00
|
|
|
this.toaster.pop("success", "Telegram bridge added");
|
|
|
|
this.dialog.close();
|
|
|
|
}).catch(err => {
|
|
|
|
console.error(err);
|
|
|
|
this.isSaving = false;
|
|
|
|
this.toaster.pop("error", "Failed to create Telegram bridge");
|
|
|
|
});
|
|
|
|
} else {
|
2018-10-17 23:09:19 -04:00
|
|
|
this.telegramApi.updateSelfhosted(this.bridgeId, this.provisionUrl, this.sharedSecret, options).then(() => {
|
2018-09-16 04:26:10 -04:00
|
|
|
this.toaster.pop("success", "Telegram bridge updated");
|
|
|
|
this.dialog.close();
|
|
|
|
}).catch(err => {
|
|
|
|
console.error(err);
|
|
|
|
this.isSaving = false;
|
|
|
|
this.toaster.pop("error", "Failed to update Telegram bridge");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|