Class: Notification

Inherits:
ApplicationRecord show all
Includes:
Diaspora::Fields::Guid
Defined in:
app/models/notification.rb

Overview

Copyright © 2010-2011, Diaspora Inc. This file is

licensed under the Affero General Public License version 3 or later.  See
the COPYRIGHT file.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Diaspora::Fields::Guid

included, #set_guid

Class Method Details

.concatenate_or_create(recipient, target, actor) ⇒ Object


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/notification.rb', line 35

def self.concatenate_or_create(recipient, target, actor)
  return nil if suppress_notification?(recipient, actor)

  find_or_initialize_by(recipient: recipient, target: target, unread: true).tap do |notification|
    notification.actors |= [actor]
    # Explicitly touch the notification to update updated_at whenever new actor is inserted in notification.
    if notification.new_record? || notification.changed?
      notification.save!
    else
      notification.touch
    end
  end
end

.create_notification(recipient, target, actor) ⇒ Object


49
50
51
52
53
# File 'app/models/notification.rb', line 49

def self.create_notification(recipient, target, actor)
  return nil if suppress_notification?(recipient, actor)

  create(recipient: recipient, target: target, actors: [actor])
end

.for(recipient, opts = {}) ⇒ Object


15
16
17
# File 'app/models/notification.rb', line 15

def self.for(recipient, opts={})
  where(opts.merge!(recipient_id: recipient.id)).order("updated_at DESC")
end

Instance Method Details

#email_the_user(target, actor) ⇒ Object


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

def email_the_user(target, actor)
  recipient.mail(mail_job, recipient_id, actor.id, target.id)
end

#linked_objectObject


31
32
33
# File 'app/models/notification.rb', line 31

def linked_object
  target
end

#mail_jobObject

Raises:

  • (NotImplementedError)

27
28
29
# File 'app/models/notification.rb', line 27

def mail_job
  raise NotImplementedError.new("Subclass this.")
end

#set_read_state(read_state) ⇒ Object


23
24
25
# File 'app/models/notification.rb', line 23

def set_read_state( read_state )
  update_column(:unread, !read_state)
end