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,
});
}
}
// 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);
});
}
sendUnreadCount() {
+ UserService.Instance.user.unreadCount = this.state.unreadCount;
UserService.Instance.sub.next({
user: UserService.Instance.user,
- unreadCount: this.state.unreadCount,
});
}
auth: null,
};
WebSocketService.Instance.editComment(form);
+ UserService.Instance.user.unreadCount--;
+ UserService.Instance.sub.next({
+ user: UserService.Instance.user,
+ });
}
}
lang: string;
avatar?: string;
show_avatars: boolean;
+ unreadCount?: number;
}
export interface UserView {
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() {
this.user = undefined;
Cookies.remove('jwt');
setTheme();
- this.sub.next({ user: undefined, unreadCount: 0 });
+ this.sub.next({ user: undefined });
console.log('Logged out.');
}
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);
}