Class: Notification

Inherits:
ActiveRecord::Base
  • Object
show all
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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#note_htmlObject

Returns the value of attribute note_html


11
12
13
# File 'app/models/notification.rb', line 11

def note_html
  @note_html
end

Class Method Details

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


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

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

.notify(recipient, target, actor) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/notification.rb', line 17

def self.notify(recipient, target, actor)
  return nil unless target.respond_to? :notification_type

  note_type = target.notification_type(recipient, actor)
  return nil unless note_type

  return_note = if [Comment, Like, Reshare].any? { |klass| target.is_a?(klass) }
    s_target = target.is_a?(Reshare) ? target.root : target.parent
    note_type.concatenate_or_create(recipient, s_target,
                                        actor, note_type)
  else
    note_type.make_notification(recipient, target,
                                    actor, note_type)
  end
  return_note.email_the_user(target, actor) if return_note
  return_note 
end

Instance Method Details

#as_json(opts = {}) ⇒ Object


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

def as_json(opts={})
  super(opts.merge(:methods => :note_html))
end

#effective_targetObject


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

def effective_target
  self.popup_translation_key == "notifications.mentioned" ? self.target.post : self.target
end

#email_the_user(target, actor) ⇒ Object


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

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

#mail_jobObject

Raises:

  • (NotImplementedError)

47
48
49
# File 'app/models/notification.rb', line 47

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

#set_read_state(read_state) ⇒ Object


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

def set_read_state( read_state )
  self.update_attributes( :unread => !read_state )
end