Module: WithNotifications

Extended by:
ActiveSupport::Concern
Included in:
User
Defined in:
app/models/concerns/with_notifications.rb

Instance Method Summary collapse

Instance Method Details

#read_notification!(target) ⇒ Object



14
15
16
# File 'app/models/concerns/with_notifications.rb', line 14

def read_notification!(target)
  notifications.find_by(target: target)&.mark_as_read!
end

#unread_messagesObject



4
5
6
# File 'app/models/concerns/with_notifications.rb', line 4

def unread_messages
  messages_in_organization.where read: false
end

#unread_notificationsObject



8
9
10
11
12
# File 'app/models/concerns/with_notifications.rb', line 8

def unread_notifications
  # TODO: message and discussion should trigger a notification instead of being one
  all = notifications_in_organization.where(read: false) + unread_messages + unread_discussions
  all.sort_by(&:created_at).reverse
end