diff options
Diffstat (limited to 'client/src/app/menu/avatar-notification.component.ts')
-rw-r--r-- | client/src/app/menu/avatar-notification.component.ts | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/client/src/app/menu/avatar-notification.component.ts b/client/src/app/menu/avatar-notification.component.ts index f1af08096..a77a001ca 100644 --- a/client/src/app/menu/avatar-notification.component.ts +++ b/client/src/app/menu/avatar-notification.component.ts | |||
@@ -17,6 +17,7 @@ export class AvatarNotificationComponent implements OnInit, OnDestroy { | |||
17 | @Input() user: User | 17 | @Input() user: User |
18 | 18 | ||
19 | unreadNotifications = 0 | 19 | unreadNotifications = 0 |
20 | loaded = false | ||
20 | 21 | ||
21 | private notificationSub: Subscription | 22 | private notificationSub: Subscription |
22 | private routeSub: Subscription | 23 | private routeSub: Subscription |
@@ -26,18 +27,19 @@ export class AvatarNotificationComponent implements OnInit, OnDestroy { | |||
26 | private userNotificationSocket: UserNotificationSocket, | 27 | private userNotificationSocket: UserNotificationSocket, |
27 | private notifier: Notifier, | 28 | private notifier: Notifier, |
28 | private router: Router | 29 | private router: Router |
29 | ) {} | 30 | ) { |
31 | } | ||
30 | 32 | ||
31 | ngOnInit () { | 33 | ngOnInit () { |
32 | this.userNotificationService.countUnreadNotifications() | 34 | this.userNotificationService.countUnreadNotifications() |
33 | .subscribe( | 35 | .subscribe( |
34 | result => { | 36 | result => { |
35 | this.unreadNotifications = Math.min(result, 99) // Limit number to 99 | 37 | this.unreadNotifications = Math.min(result, 99) // Limit number to 99 |
36 | this.subscribeToNotifications() | 38 | this.subscribeToNotifications() |
37 | }, | 39 | }, |
38 | 40 | ||
39 | err => this.notifier.error(err.message) | 41 | err => this.notifier.error(err.message) |
40 | ) | 42 | ) |
41 | 43 | ||
42 | this.routeSub = this.router.events | 44 | this.routeSub = this.router.events |
43 | .pipe(filter(event => event instanceof NavigationEnd)) | 45 | .pipe(filter(event => event instanceof NavigationEnd)) |
@@ -53,13 +55,22 @@ export class AvatarNotificationComponent implements OnInit, OnDestroy { | |||
53 | this.popover.close() | 55 | this.popover.close() |
54 | } | 56 | } |
55 | 57 | ||
56 | private subscribeToNotifications () { | 58 | onPopoverHidden () { |
57 | this.notificationSub = this.userNotificationSocket.getMyNotificationsSocket() | 59 | this.loaded = false |
58 | .subscribe(data => { | 60 | } |
59 | if (data.type === 'new') return this.unreadNotifications++ | 61 | |
60 | if (data.type === 'read') return this.unreadNotifications-- | 62 | onNotificationLoaded () { |
61 | if (data.type === 'read-all') return this.unreadNotifications = 0 | 63 | this.loaded = true |
62 | }) | 64 | } |
65 | |||
66 | private async subscribeToNotifications () { | ||
67 | const obs = await this.userNotificationSocket.getMyNotificationsSocket() | ||
68 | |||
69 | this.notificationSub = obs.subscribe(data => { | ||
70 | if (data.type === 'new') return this.unreadNotifications++ | ||
71 | if (data.type === 'read') return this.unreadNotifications-- | ||
72 | if (data.type === 'read-all') return this.unreadNotifications = 0 | ||
73 | }) | ||
63 | } | 74 | } |
64 | 75 | ||
65 | } | 76 | } |