diff --git a/src/app/components/floating-column/manage-account/manage-account.component.ts b/src/app/components/floating-column/manage-account/manage-account.component.ts index feee4a35..b8640e1d 100644 --- a/src/app/components/floating-column/manage-account/manage-account.component.ts +++ b/src/app/components/floating-column/manage-account/manage-account.component.ts @@ -1,15 +1,18 @@ -import { Component, OnInit, Input } from '@angular/core'; +import { Component, OnInit, OnDestroy, Input } from '@angular/core'; import { faAt, faUserPlus } from "@fortawesome/free-solid-svg-icons"; import { faBell, faEnvelope, faUser, faStar } from "@fortawesome/free-regular-svg-icons"; +import { Subscription } from 'rxjs'; import { AccountWrapper } from '../../../models/account.models'; +import { UserNotificationServiceService, UserNotification } from '../../../services/user-notification-service.service'; + @Component({ selector: 'app-manage-account', templateUrl: './manage-account.component.html', styleUrls: ['./manage-account.component.scss'] }) -export class ManageAccountComponent implements OnInit { +export class ManageAccountComponent implements OnInit, OnDestroy { faAt = faAt; faBell = faBell; faEnvelope = faEnvelope; @@ -20,12 +23,39 @@ export class ManageAccountComponent implements OnInit { subPanel = 'account'; hasNotifications = false; hasMentions = false; - - @Input() account: AccountWrapper; - constructor() { } + @Input('account') + set account(acc: AccountWrapper) { + console.warn('account'); + this._account = acc; + this.checkNotifications(); + } + get account(): AccountWrapper { + return this._account; + } - ngOnInit() { + private userNotificationServiceSub: Subscription; + private _account: AccountWrapper; + + constructor( + private readonly userNotificationService: UserNotificationServiceService) { } + + ngOnInit() { + + } + + ngOnDestroy(): void { + this.userNotificationServiceSub.unsubscribe(); + } + + private checkNotifications(){ + 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; + } + }); } loadSubPanel(subpanel: string): boolean { diff --git a/src/app/services/user-notification-service.service.ts b/src/app/services/user-notification-service.service.ts index 36578ef0..d58e5465 100644 --- a/src/app/services/user-notification-service.service.ts +++ b/src/app/services/user-notification-service.service.ts @@ -27,7 +27,7 @@ export class UserNotificationServiceService { let promises: Promise[] = []; accounts.forEach(account => { - let getNotificationPromise = this.mastodonService.getNotifications(account) + let getNotificationPromise = this.mastodonService.getNotifications(account, null, null, null, 30) .then((notifications: Notification[]) => { this.processNotifications(account, notifications); })