Class: Smalltalk::Message
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Smalltalk::Message
- Includes:
- Workflow
- Defined in:
- lib/smalltalk/message.rb
Class Method Summary collapse
- .created_between(time_range) ⇒ Object
- .delivered ⇒ Object
- .for(messenger) ⇒ Object
- .hidden ⇒ Object
- .queued ⇒ Object
- .received_by(recipient) ⇒ Object
- .search(term) ⇒ Object
- .sent_by(sender) ⇒ Object
- .unsent ⇒ Object
- .unviewed ⇒ Object
- .viewed ⇒ Object
- .visible ⇒ Object
Instance Method Summary collapse
- #hide! ⇒ Object
- #received_by?(recipient) ⇒ Boolean
- #recipient ⇒ Object
- #recipient=(recipient) ⇒ Object
- #reply(params = {}) ⇒ Object
- #sender ⇒ Object
- #sender=(sender) ⇒ Object
- #sent_by?(sender) ⇒ Boolean
- #view! ⇒ Object
Class Method Details
.created_between(time_range) ⇒ Object
36 37 38 |
# File 'lib/smalltalk/message.rb', line 36 def self.created_between(time_range) where(created_at: time_range) end |
.delivered ⇒ Object
16 17 18 |
# File 'lib/smalltalk/message.rb', line 16 def self.delivered where(workflow_state: 'delivered') end |
.for(messenger) ⇒ Object
59 60 61 |
# File 'lib/smalltalk/message.rb', line 59 def self.for(messenger) where("(sender_type = ? AND sender_id = ?) OR (recipient_type = ? AND recipient_id = ?)", messenger.class.name, messenger.id, messenger.class.name, messenger.id) end |
.hidden ⇒ Object
20 21 22 |
# File 'lib/smalltalk/message.rb', line 20 def self.hidden where(hidden: true) end |
.queued ⇒ Object
12 13 14 |
# File 'lib/smalltalk/message.rb', line 12 def self.queued where(workflow_state: 'queued') end |
.received_by(recipient) ⇒ Object
67 68 69 |
# File 'lib/smalltalk/message.rb', line 67 def self.received_by(recipient) where(recipient_type: recipient.class.name, recipient_id: recipient.id) end |
.search(term) ⇒ Object
40 41 42 43 44 |
# File 'lib/smalltalk/message.rb', line 40 def self.search(term) unless term.blank? where("content LIKE :q", q: "%#{term}%") end end |
.sent_by(sender) ⇒ Object
63 64 65 |
# File 'lib/smalltalk/message.rb', line 63 def self.sent_by(sender) where(sender_type: sender.class.name, sender_id: sender.id) end |
.unsent ⇒ Object
8 9 10 |
# File 'lib/smalltalk/message.rb', line 8 def self.unsent where(workflow_state: 'unsent') end |
.unviewed ⇒ Object
32 33 34 |
# File 'lib/smalltalk/message.rb', line 32 def self.unviewed where(viewed: false) end |
.viewed ⇒ Object
28 29 30 |
# File 'lib/smalltalk/message.rb', line 28 def self.viewed where(viewed: true) end |
.visible ⇒ Object
24 25 26 |
# File 'lib/smalltalk/message.rb', line 24 def self.visible where(hidden: false) end |
Instance Method Details
#hide! ⇒ Object
101 102 103 104 |
# File 'lib/smalltalk/message.rb', line 101 def hide! self.hidden = true self.save! end |
#received_by?(recipient) ⇒ Boolean
75 76 77 |
# File 'lib/smalltalk/message.rb', line 75 def received_by?(recipient) (recipient_type == recipient.class.name) && (recipient_id == recipient.id) end |
#recipient ⇒ Object
88 89 90 |
# File 'lib/smalltalk/message.rb', line 88 def recipient self.recipient_type.constantize.find(recipient_id) end |
#recipient=(recipient) ⇒ Object
92 93 94 95 |
# File 'lib/smalltalk/message.rb', line 92 def recipient=(recipient) self.recipient_type = recipient.class.name self.recipient_id = recipient.id end |
#reply(params = {}) ⇒ Object
97 98 99 |
# File 'lib/smalltalk/message.rb', line 97 def reply(params = {}) Smalltalk::Reply.new(params.merge(message: self)).build! end |
#sender ⇒ Object
79 80 81 |
# File 'lib/smalltalk/message.rb', line 79 def sender self.sender_type.constantize.find(sender_id) end |
#sender=(sender) ⇒ Object
83 84 85 86 |
# File 'lib/smalltalk/message.rb', line 83 def sender=(sender) self.sender_type = sender.class.name self.sender_id = sender.id end |
#sent_by?(sender) ⇒ Boolean
71 72 73 |
# File 'lib/smalltalk/message.rb', line 71 def sent_by?(sender) (sender_type == sender.class.name) && (sender.id == sender.id) end |
#view! ⇒ Object
106 107 108 109 |
# File 'lib/smalltalk/message.rb', line 106 def view! self.viewed = true self.save! end |