Class: Gaggle::Notification

Inherits:
ApplicationRecord show all
Defined in:
app/models/gaggle/notification.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for_messageable(messageable) ⇒ Object



42
43
44
# File 'app/models/gaggle/notification.rb', line 42

def for_messageable(messageable)
  where(messageable_id: messageable.id, messageable_type: messageable.class.name)
end

.messageablesObject



34
35
36
# File 'app/models/gaggle/notification.rb', line 34

def messageables
  preload(:messageable).map(&:messageable)
end

.unreadObject



38
39
40
# File 'app/models/gaggle/notification.rb', line 38

def unread
  where(read_at: nil)
end

Instance Method Details

#mark_read!Object



18
19
20
# File 'app/models/gaggle/notification.rb', line 18

def mark_read!
  update(read_at: Time.current)
end

#notify_gooseObject



13
14
15
16
# File 'app/models/gaggle/notification.rb', line 13

def notify_goose
  update(delivered_at: Time.current)
  goose.notify_of_message(notification: self)
end

#unread_messageableObject



22
23
24
25
26
27
28
29
30
31
# File 'app/models/gaggle/notification.rb', line 22

def unread_messageable
  messages = case messageable
  when Gaggle::Channel
      messageable.messages.where(created_at: created_at..)
  when Gaggle::Goose
      messageable.messages.where(created_at: created_at..)
  end
  mark_read!
  messages
end