import { Component, OnInit, Input } from '@angular/core'; import { HttpErrorResponse } from '@angular/common/http'; import { Store } from '@ngxs/store'; import { RegisteredAppsStateModel, AppInfo, AddRegisteredApp } from '../../../states/registered-apps.state'; import { AuthService, CurrentAuthProcess } from '../../../services/auth.service'; import { AppData } from '../../../services/models/mastodon.interfaces'; import { NotificationService } from '../../../services/notification.service'; @Component({ selector: 'app-add-new-account', templateUrl: './add-new-account.component.html', styleUrls: ['./add-new-account.component.scss'] }) export class AddNewAccountComponent implements OnInit { private blockList = ['gab.com', 'gab.ai', 'cyzed.com']; private comradeList = ['juche.town']; private username: string; private instance: string; isComrade: boolean; private _mastodonFullHandle: string; @Input() set mastodonFullHandle(value: string) { this._mastodonFullHandle = value; this.checkComrad(); } get mastodonFullHandle(): string { return this._mastodonFullHandle; } constructor( private readonly notificationService: NotificationService, private readonly authService: AuthService, private readonly store: Store) { } ngOnInit() { } checkComrad(): any { let fullHandle = this.mastodonFullHandle.split('@').filter(x => x != null && x !== ''); this.username = fullHandle[0]; this.instance = fullHandle[1]; if (this.username && this.instance) { let cleanInstance = this.instance.replace('http://', '').replace('https://', '').toLowerCase(); for (let b of this.comradeList) { if (cleanInstance == b || cleanInstance.includes(`.${b}`)) { this.isComrade = true; return; } } } this.isComrade = false; } onSubmit(): boolean { // let fullHandle = this.mastodonFullHandle.split('@').filter(x => x != null && x !== ''); // const username = fullHandle[0]; // const instance = fullHandle[1]; this.checkBlockList(this.instance); this.checkAndCreateApplication(this.instance) .then((appData: AppData) => { this.redirectToInstanceAuthPage(this.username, this.instance, appData); }) .catch((err: HttpErrorResponse) => { if (err instanceof HttpErrorResponse) { this.notificationService.notifyHttpError(err, null); } else if ((err).message === 'CORS') { this.notificationService.notify(null, null, 'Connection Error. It\'s usually a CORS issue with the server you\'re connecting to. Please check in the console and if so, contact your administrator with those informations.', true); } else { this.notificationService.notify(null, null, 'Unkown error', true); } }); return false; } private checkBlockList(instance: string) { let cleanInstance = instance.replace('http://', '').replace('https://', '').toLowerCase(); for (let b of this.blockList) { if (cleanInstance == b || cleanInstance.includes(`.${b}`)) { let content = '