diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index d1b752a9..f4fd1e8f 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -56,8 +56,7 @@ class NotificationsController < ApplicationController private def set_receipts - @receipts = current_user.mailbox.receipts - .includes(:notification).where(mailbox_type: nil) + @receipts = current_user.mailboxer_notification_receipts end def set_notification diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3221aa34..37e0007a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -37,4 +37,12 @@ module ApplicationHelper def invite_link "#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : '') end + + def user_has_unread_notifications? + return false if current_user.nil? + current_user.mailboxer_notification_receipts.each do |receipt| + return true if receipt.is_read == false + end + false + end end diff --git a/app/models/user.rb b/app/models/user.rb index e70114d5..f3169d1d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -114,4 +114,12 @@ class User < ApplicationRecord def mailboxer_email(object) nil # email end + + def mailboxer_notifications + mailbox.notifications + end + + def mailboxer_notification_receipts + mailbox.receipts.includes(:notification).where(mailbox_type: nil) + end end diff --git a/app/views/layouts/_account.html.erb b/app/views/layouts/_account.html.erb index 748e5f1b..ebb8658c 100644 --- a/app/views/layouts/_account.html.erb +++ b/app/views/layouts/_account.html.erb @@ -18,14 +18,20 @@ <%= link_to "Admin", metacodes_path %> <% end %> -