From 1dd0c7249c21a5482f08cfc7fe3546003238aea4 Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Mon, 4 Apr 2022 14:34:01 +0530 Subject: [PATCH] fix: Unread notification count in multiple accounts (#4373) Fixes: #4367 --- app/listeners/base_listener.rb | 5 +++-- app/models/user.rb | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/listeners/base_listener.rb b/app/listeners/base_listener.rb index 397ec62ed..ffd57d2a3 100644 --- a/app/listeners/base_listener.rb +++ b/app/listeners/base_listener.rb @@ -8,8 +8,9 @@ class BaseListener def extract_notification_and_account(event) notification = event.data[:notification] - unread_count = notification.user.notifications_meta[:unread_count] - count = notification.user.notifications_meta[:count] + notifications_meta = notification.user.notifications_meta(notification.account_id) + unread_count = notifications_meta[:unread_count] + count = notifications_meta[:count] [notification, notification.account, unread_count, count] end diff --git a/app/models/user.rb b/app/models/user.rb index 8c4b3ce2f..3b7a74672 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -188,10 +188,10 @@ class User < ApplicationRecord mutations_from_database.changed?('email') end - def notifications_meta + def notifications_meta(account_id) { - unread_count: notifications.where(read_at: nil).count, - count: notifications.count + unread_count: notifications.where(account_id: account_id, read_at: nil).count, + count: notifications.where(account_id: account_id).count } end end