fix: Unread notification count in multiple accounts (#4373)

Fixes: #4367
This commit is contained in:
Muhsin Keloth 2022-04-04 14:34:01 +05:30 committed by GitHub
parent 3509692055
commit 1dd0c7249c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View file

@ -8,8 +8,9 @@ class BaseListener
def extract_notification_and_account(event) def extract_notification_and_account(event)
notification = event.data[:notification] notification = event.data[:notification]
unread_count = notification.user.notifications_meta[:unread_count] notifications_meta = notification.user.notifications_meta(notification.account_id)
count = notification.user.notifications_meta[:count] unread_count = notifications_meta[:unread_count]
count = notifications_meta[:count]
[notification, notification.account, unread_count, count] [notification, notification.account, unread_count, count]
end end

View file

@ -188,10 +188,10 @@ class User < ApplicationRecord
mutations_from_database.changed?('email') mutations_from_database.changed?('email')
end end
def notifications_meta def notifications_meta(account_id)
{ {
unread_count: notifications.where(read_at: nil).count, unread_count: notifications.where(account_id: account_id, read_at: nil).count,
count: notifications.count count: notifications.where(account_id: account_id).count
} }
end end
end end