From: Dessalines Date: Tue, 11 Feb 2020 15:14:09 +0000 (-0500) Subject: Fixing unread indicator on link click. Fixes #527 X-Git-Url: http://these/git/%7B%60https:/%7B%60css/themes/%22https:/nerdica.net/%7Bthis.props.site.site.icon%7D?a=commitdiff_plain;h=774518e4fe336ac60c6e8ccdbc9a98e0cb8b9310;p=lemmy.git Fixing unread indicator on link click. Fixes #527 --- diff --git a/ui/src/components/inbox.tsx b/ui/src/components/inbox.tsx index 027a1db0..56bf1578 100644 --- a/ui/src/components/inbox.tsx +++ b/ui/src/components/inbox.tsx @@ -443,9 +443,9 @@ export class Inbox extends Component { this.state.messages.filter( r => !r.read && r.creator_id !== UserService.Instance.user.id ).length; + UserService.Instance.user.unreadCount = count; UserService.Instance.sub.next({ user: UserService.Instance.user, - unreadCount: count, }); } } diff --git a/ui/src/components/navbar.tsx b/ui/src/components/navbar.tsx index c675cfe7..75cdd554 100644 --- a/ui/src/components/navbar.tsx +++ b/ui/src/components/navbar.tsx @@ -60,8 +60,10 @@ export class Navbar extends Component { // Subscribe to user changes this.userSub = UserService.Instance.sub.subscribe(user => { this.state.isLoggedIn = user.user !== undefined; - this.state.unreadCount = user.unreadCount; - this.requestNotificationPermission(); + if (this.state.isLoggedIn) { + this.state.unreadCount = user.user.unreadCount; + this.requestNotificationPermission(); + } this.setState(this.state); }); @@ -304,9 +306,9 @@ export class Navbar extends Component { } sendUnreadCount() { + UserService.Instance.user.unreadCount = this.state.unreadCount; UserService.Instance.sub.next({ user: UserService.Instance.user, - unreadCount: this.state.unreadCount, }); } diff --git a/ui/src/components/post.tsx b/ui/src/components/post.tsx index b5b1fce3..d8f662cf 100644 --- a/ui/src/components/post.tsx +++ b/ui/src/components/post.tsx @@ -156,6 +156,10 @@ export class Post extends Component { auth: null, }; WebSocketService.Instance.editComment(form); + UserService.Instance.user.unreadCount--; + UserService.Instance.sub.next({ + user: UserService.Instance.user, + }); } } diff --git a/ui/src/interfaces.ts b/ui/src/interfaces.ts index 23551b59..5846b548 100644 --- a/ui/src/interfaces.ts +++ b/ui/src/interfaces.ts @@ -93,6 +93,7 @@ export interface User { lang: string; avatar?: string; show_avatars: boolean; + unreadCount?: number; } export interface UserView { diff --git a/ui/src/services/UserService.ts b/ui/src/services/UserService.ts index 03380e59..47e28c73 100644 --- a/ui/src/services/UserService.ts +++ b/ui/src/services/UserService.ts @@ -7,9 +7,8 @@ import { Subject } from 'rxjs'; export class UserService { private static _instance: UserService; public user: User; - public sub: Subject<{ user: User; unreadCount: number }> = new Subject<{ + public sub: Subject<{ user: User }> = new Subject<{ user: User; - unreadCount: number; }>(); private constructor() { @@ -32,7 +31,7 @@ export class UserService { this.user = undefined; Cookies.remove('jwt'); setTheme(); - this.sub.next({ user: undefined, unreadCount: 0 }); + this.sub.next({ user: undefined }); console.log('Logged out.'); } @@ -45,7 +44,7 @@ export class UserService { if (this.user.theme != 'darkly') { setTheme(this.user.theme); } - this.sub.next({ user: this.user, unreadCount: 0 }); + this.sub.next({ user: this.user }); console.log(this.user); }