Sengi-Windows-MacOS-Linux/src/app/components/floating-column/manage-account/notifications/notification/notification.component.ts

86 lines
2.8 KiB
TypeScript
Raw Normal View History

2020-06-14 09:07:44 +02:00
import { Component, Input } from '@angular/core';
2020-10-03 05:58:43 +02:00
import { faUserPlus, faUserClock, faCheck, faTimes } from "@fortawesome/free-solid-svg-icons";
2019-11-19 05:54:11 +01:00
import { NotificationWrapper } from '../notifications.component';
2020-06-14 09:07:44 +02:00
import { ToolsService } from '../../../../../services/tools.service';
2019-11-19 05:54:11 +01:00
import { Account } from '../../../../../services/models/mastodon.interfaces';
2020-06-14 09:07:44 +02:00
import { BrowseBase } from '../../../../../components/common/browse-base';
2020-10-03 06:40:43 +02:00
import { MastodonWrapperService } from '../../../../../services/mastodon-wrapper.service';
import { NotificationService } from '../../../../../services/notification.service';
2019-11-19 05:54:11 +01:00
@Component({
selector: 'app-notification',
templateUrl: './notification.component.html',
styleUrls: ['./notification.component.scss']
})
2020-10-03 06:40:43 +02:00
export class NotificationComponent extends BrowseBase {
2019-11-19 05:54:11 +01:00
faUserPlus = faUserPlus;
2020-10-03 05:58:43 +02:00
faUserClock = faUserClock;
faCheck = faCheck;
faTimes = faTimes;
2019-11-19 05:54:11 +01:00
@Input() notification: NotificationWrapper;
2020-10-03 06:40:43 +02:00
constructor(
private readonly notificationsService: NotificationService,
private readonly mastodonService: MastodonWrapperService,
private readonly toolsService: ToolsService) {
2020-06-14 09:07:44 +02:00
super();
2019-11-19 05:54:11 +01:00
}
2020-06-14 09:07:44 +02:00
ngOnInit() {
2019-11-19 05:54:11 +01:00
}
2020-06-14 09:07:44 +02:00
ngOnDestroy() {
2019-11-19 05:54:11 +01:00
}
openAccount(account: Account): boolean {
let accountName = this.toolsService.getAccountFullHandle(account);
this.browseAccountEvent.next(accountName);
return false;
}
2020-10-03 06:40:43 +02:00
2019-11-19 05:54:11 +01:00
openUrl(url: string): boolean {
window.open(url, '_blank');
return false;
}
2020-10-03 05:58:43 +02:00
2020-10-03 06:40:43 +02:00
followRequestWorking: boolean;
followRequestProcessed: boolean;
acceptFollowRequest(): boolean {
if(this.followRequestWorking) return false;
this.followRequestWorking = true;
this.mastodonService.authorizeFollowRequest(this.notification.provider, this.notification.notification.account.id)
.then(res => {
this.followRequestProcessed = true;
})
.catch(err => {
this.notificationsService.notifyHttpError(err, this.notification.provider);
})
.then(res => {
this.followRequestWorking = false;
});
2020-10-03 05:58:43 +02:00
return false;
}
2020-10-03 06:40:43 +02:00
refuseFollowRequest(): boolean {
if(this.followRequestWorking) return false;
this.followRequestWorking = true;
this.mastodonService.rejectFollowRequest(this.notification.provider, this.notification.notification.account.id)
.then(res => {
this.followRequestProcessed = true;
})
.catch(err => {
this.notificationsService.notifyHttpError(err, this.notification.provider);
})
.then(res => {
this.followRequestWorking = false;
});
2020-10-03 05:58:43 +02:00
return false;
}
2019-11-19 05:54:11 +01:00
}