2019-04-01 02:24:07 +02:00
|
|
|
import { Component, OnInit, OnDestroy, Input, Output, EventEmitter } from '@angular/core';
|
2019-03-20 03:07:42 +01:00
|
|
|
import { faAt, faUserPlus } from "@fortawesome/free-solid-svg-icons";
|
|
|
|
import { faBell, faEnvelope, faUser, faStar } from "@fortawesome/free-regular-svg-icons";
|
2019-03-25 02:11:23 +01:00
|
|
|
import { Subscription } from 'rxjs';
|
2019-03-19 05:21:00 +01:00
|
|
|
|
2018-09-11 07:54:23 +02:00
|
|
|
import { AccountWrapper } from '../../../models/account.models';
|
2019-03-25 06:09:53 +01:00
|
|
|
import { UserNotificationService, UserNotification } from '../../../services/user-notification.service';
|
2019-04-01 02:24:07 +02:00
|
|
|
import { OpenThreadEvent } from '../../../services/tools.service';
|
2019-03-25 02:11:23 +01:00
|
|
|
|
2018-09-10 03:55:16 +02:00
|
|
|
|
|
|
|
@Component({
|
2019-01-28 06:46:37 +01:00
|
|
|
selector: 'app-manage-account',
|
|
|
|
templateUrl: './manage-account.component.html',
|
|
|
|
styleUrls: ['./manage-account.component.scss']
|
2018-09-10 03:55:16 +02:00
|
|
|
})
|
2019-03-25 02:11:23 +01:00
|
|
|
export class ManageAccountComponent implements OnInit, OnDestroy {
|
2019-03-19 05:21:00 +01:00
|
|
|
faAt = faAt;
|
|
|
|
faBell = faBell;
|
|
|
|
faEnvelope = faEnvelope;
|
|
|
|
faUser = faUser;
|
2019-03-20 03:07:42 +01:00
|
|
|
faStar = faStar;
|
|
|
|
faUserPlus = faUserPlus;
|
2019-03-19 05:21:00 +01:00
|
|
|
|
2019-03-20 03:25:04 +01:00
|
|
|
subPanel = 'account';
|
|
|
|
hasNotifications = false;
|
|
|
|
hasMentions = false;
|
2018-09-10 03:55:16 +02:00
|
|
|
|
2019-04-01 02:24:07 +02:00
|
|
|
@Output() browseAccountEvent = new EventEmitter<string>();
|
|
|
|
@Output() browseHashtagEvent = new EventEmitter<string>();
|
|
|
|
@Output() browseThreadEvent = new EventEmitter<OpenThreadEvent>();
|
|
|
|
|
2019-03-25 02:11:23 +01:00
|
|
|
@Input('account')
|
|
|
|
set account(acc: AccountWrapper) {
|
|
|
|
this._account = acc;
|
|
|
|
this.checkNotifications();
|
|
|
|
}
|
|
|
|
get account(): AccountWrapper {
|
|
|
|
return this._account;
|
|
|
|
}
|
|
|
|
|
|
|
|
private userNotificationServiceSub: Subscription;
|
|
|
|
private _account: AccountWrapper;
|
|
|
|
|
|
|
|
constructor(
|
2019-03-25 06:09:53 +01:00
|
|
|
private readonly userNotificationService: UserNotificationService) { }
|
2019-03-25 02:11:23 +01:00
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
this.userNotificationServiceSub.unsubscribe();
|
|
|
|
}
|
2019-01-30 04:33:49 +01:00
|
|
|
|
2019-03-25 02:11:23 +01:00
|
|
|
private checkNotifications(){
|
2019-03-25 05:52:30 +01:00
|
|
|
if(this.userNotificationServiceSub){
|
|
|
|
this.userNotificationServiceSub.unsubscribe();
|
|
|
|
}
|
|
|
|
|
2019-03-25 02:11:23 +01:00
|
|
|
this.userNotificationServiceSub = this.userNotificationService.userNotifications.subscribe((userNotifications: UserNotification[]) => {
|
|
|
|
const userNotification = userNotifications.find(x => x.account.id === this.account.info.id);
|
|
|
|
if(userNotification){
|
|
|
|
this.hasNotifications = userNotification.hasNewNotifications;
|
|
|
|
this.hasMentions = userNotification.hasNewMentions;
|
|
|
|
}
|
|
|
|
});
|
2019-01-30 04:33:49 +01:00
|
|
|
}
|
2019-03-20 03:25:04 +01:00
|
|
|
|
|
|
|
loadSubPanel(subpanel: string): boolean {
|
|
|
|
this.subPanel = subpanel;
|
|
|
|
return false;
|
|
|
|
}
|
2019-04-01 02:24:07 +02:00
|
|
|
|
|
|
|
browseAccount(accountName: string): void {
|
|
|
|
this.browseAccountEvent.next(accountName);
|
|
|
|
}
|
|
|
|
|
|
|
|
browseHashtag(hashtag: string): void {
|
|
|
|
this.browseHashtagEvent.next(hashtag);
|
|
|
|
}
|
|
|
|
|
|
|
|
browseThread(openThreadEvent: OpenThreadEvent): void {
|
|
|
|
this.browseThreadEvent.next(openThreadEvent);
|
|
|
|
}
|
2018-09-10 03:55:16 +02:00
|
|
|
}
|