]> Untitled Git - lemmy.git/commitdiff
Fixing unread indicator on link click. Fixes #527
authorDessalines <tyhou13@gmx.com>
Tue, 11 Feb 2020 15:14:09 +0000 (10:14 -0500)
committerDessalines <tyhou13@gmx.com>
Tue, 11 Feb 2020 15:14:09 +0000 (10:14 -0500)
ui/src/components/inbox.tsx
ui/src/components/navbar.tsx
ui/src/components/post.tsx
ui/src/interfaces.ts
ui/src/services/UserService.ts

index 027a1db0498f95a97785d36f1caefd881440ef83..56bf15785b93838f63ebcab7fb5dbab9bc781aef 100644 (file)
@@ -443,9 +443,9 @@ export class Inbox extends Component<any, InboxState> {
       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,
     });
   }
 }
index c675cfe7b57f46193f49a52b3e4730103a960bb3..75cdd55498e850fabbe10251634abcef028f091e 100644 (file)
@@ -60,8 +60,10 @@ export class Navbar extends Component<any, NavbarState> {
     // 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<any, NavbarState> {
   }
 
   sendUnreadCount() {
+    UserService.Instance.user.unreadCount = this.state.unreadCount;
     UserService.Instance.sub.next({
       user: UserService.Instance.user,
-      unreadCount: this.state.unreadCount,
     });
   }
 
index b5b1fce364f2198f76f3275621d779fb83bcc2b3..d8f662cf72cae09370cef0d5736c9ed98cb8f0a9 100644 (file)
@@ -156,6 +156,10 @@ export class Post extends Component<any, PostState> {
         auth: null,
       };
       WebSocketService.Instance.editComment(form);
+      UserService.Instance.user.unreadCount--;
+      UserService.Instance.sub.next({
+        user: UserService.Instance.user,
+      });
     }
   }
 
index 23551b595264d945ab43c54db32a71f1357f0261..5846b548cdabe40493d88aba848dfb9ecf2aedc8 100644 (file)
@@ -93,6 +93,7 @@ export interface User {
   lang: string;
   avatar?: string;
   show_avatars: boolean;
+  unreadCount?: number;
 }
 
 export interface UserView {
index 03380e593021373bbd5a5d3cf0e2016f1acb0438..47e28c73e8db37617a7e7f8fb585f3a5fd440195 100644 (file)
@@ -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);
   }