Class: Libertree::Model::Notification
- Inherits:
-
Object
- Object
- Libertree::Model::Notification
- Defined in:
- lib/libertree/model/notification.rb
Class Method Summary collapse
- .mark_seen_for_account(account, notification_ids) ⇒ Object
- .mark_seen_for_account_and_comment_id(account, comment_ids) ⇒ Object
- .mark_seen_for_account_and_message(account, message) ⇒ Object
- .mark_seen_for_account_and_post(account, post) ⇒ Object
- .mark_unseen_for_account(account, notification_ids) ⇒ Object
Instance Method Summary collapse
Class Method Details
.mark_seen_for_account(account, notification_ids) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/libertree/model/notification.rb', line 60 def self.mark_seen_for_account(account, notification_ids) if notification_ids[0] == 'all' self.where(account_id: account.id).update(seen: true) else self.where(account_id: account.id, id: notification_ids). update(seen: true) end account.dirty end |
.mark_seen_for_account_and_comment_id(account, comment_ids) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/libertree/model/notification.rb', line 33 def self.mark_seen_for_account_and_comment_id(account, comment_ids) data = comment_ids.map {|id| %|{"type":"comment","comment_id":#{id.to_i}}| } data += CommentLike.where(comment_id: comment_ids). map {|like| %|{"type":"comment-like","comment_like_id":#{like.id}}| } self.where(account_id: account.id, data: data).update(seen: true) account.dirty end |
.mark_seen_for_account_and_message(account, message) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/libertree/model/notification.rb', line 48 def self.(account, ) self.where( Sequel.lit( "account_id = ? AND data = ?", account.id, %|{"type":"message","message_id":#{message.id}}| ) ).update(seen: true) account.dirty end |
.mark_seen_for_account_and_post(account, post) ⇒ Object
42 43 44 45 46 |
# File 'lib/libertree/model/notification.rb', line 42 def self.mark_seen_for_account_and_post(account, post) data = post.likes.map {|like| %|{"type":"post-like","post_like_id":#{like.id.to_i}}| } self.where(account_id: account.id, data: data).update(seen: true) account.dirty end |
.mark_unseen_for_account(account, notification_ids) ⇒ Object
70 71 72 73 74 |
# File 'lib/libertree/model/notification.rb', line 70 def self.mark_unseen_for_account(account, notification_ids) self.where(account_id: account.id, id: notification_ids). update(seen: false) account.dirty end |
Instance Method Details
#account ⇒ Object
6 7 8 |
# File 'lib/libertree/model/notification.rb', line 6 def account @account ||= Account[self.account_id] end |
#data ⇒ Object
10 11 12 13 14 |
# File 'lib/libertree/model/notification.rb', line 10 def data if val = super JSON.parse val end end |
#subject ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/libertree/model/notification.rb', line 16 def subject @subject ||= case self.data['type'] when 'comment' Libertree::Model::Comment[ self.data['comment_id'] ] when 'comment-like' Libertree::Model::CommentLike[ self.data['comment_like_id'] ] when 'message' Libertree::Model::Message[ self.data['message_id'] ] when 'post-like' Libertree::Model::PostLike[ self.data['post_like_id'] ] when 'springing' Libertree::Model::PoolPost[ self.data['pool_post_id'] ] when 'mention', 'group-post' Libertree::Model::Post[ self.data['post_id'] ] end end |