Class: Notification

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Notifications::Model
Defined in:
app/models/notification.rb

Overview

Auto generate with notifications gem.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.notify_follow(user_id, follower_id) ⇒ Object


44
45
46
47
48
49
50
51
52
# File 'app/models/notification.rb', line 44

def self.notify_follow(user_id, follower_id)
  opts = {
    notify_type: 'follow',
    user_id: user_id,
    actor_id: follower_id
  }
  return if Notification.where(opts).count > 0
  Notification.create opts
end

.realtime_push_to_client(user) ⇒ Object


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

def self.realtime_push_to_client(user)
  ActionCable.server.broadcast "notifications_count/#{user.id}", { count: Notification.unread_count(user) }
end

Instance Method Details

#apns_noteObject


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

def apns_note
  @note ||= { alert: notify_title, badge: Notification.unread_count(user) }
end

#notify_titleObject


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/notification.rb', line 27

def notify_title
  return "" if self.actor.blank?
  if notify_type == 'topic'
    "#{self.actor.} 创建了话题 《#{self.target.title}"
  elsif notify_type == "topic_reply"
    "#{self.actor.} 回复了话题 《#{self.second_target.title}"
  elsif notify_type == "follow"
    "#{self.actor.} 开始关注你了"
  elsif notify_type == "mention"
    "#{self.actor.} 提及了你"
  elsif notify_type == "node_changed"
    "你的话题被移动了节点到 #{self.second_target.name}"
  else
    ""
  end
end

#realtime_push_to_clientObject


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

def realtime_push_to_client
  if user
    self.class.realtime_push_to_client(user)
    PushJob.perform_later(user_id, apns_note)
  end
end