Class: Smalltalk::Message
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Smalltalk::Message
- Includes:
- SearchCop, 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
- .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
39 40 41 |
# File 'lib/smalltalk/message.rb', line 39 def self.created_between(time_range) where(created_at: time_range) end |
.delivered ⇒ Object
19 20 21 |
# File 'lib/smalltalk/message.rb', line 19 def self.delivered where(workflow_state: 'delivered') end |
.for(messenger) ⇒ Object
60 61 62 |
# File 'lib/smalltalk/message.rb', line 60 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
23 24 25 |
# File 'lib/smalltalk/message.rb', line 23 def self.hidden where(hidden: true) end |
.queued ⇒ Object
15 16 17 |
# File 'lib/smalltalk/message.rb', line 15 def self.queued where(workflow_state: 'queued') end |
.received_by(recipient) ⇒ Object
68 69 70 |
# File 'lib/smalltalk/message.rb', line 68 def self.received_by(recipient) where(recipient_type: recipient.class.name, recipient_id: recipient.id) end |
.sent_by(sender) ⇒ Object
64 65 66 |
# File 'lib/smalltalk/message.rb', line 64 def self.sent_by(sender) where(sender_type: sender.class.name, sender_id: sender.id) end |
.unsent ⇒ Object
11 12 13 |
# File 'lib/smalltalk/message.rb', line 11 def self.unsent where(workflow_state: 'unsent') end |
.unviewed ⇒ Object
35 36 37 |
# File 'lib/smalltalk/message.rb', line 35 def self.unviewed where(viewed: false) end |
.viewed ⇒ Object
31 32 33 |
# File 'lib/smalltalk/message.rb', line 31 def self.viewed where(viewed: true) end |
.visible ⇒ Object
27 28 29 |
# File 'lib/smalltalk/message.rb', line 27 def self.visible where(hidden: false) end |
Instance Method Details
#hide! ⇒ Object
102 103 104 105 |
# File 'lib/smalltalk/message.rb', line 102 def hide! self.hidden = true self.save! end |
#received_by?(recipient) ⇒ Boolean
76 77 78 |
# File 'lib/smalltalk/message.rb', line 76 def received_by?(recipient) (recipient_type == recipient.class.name) && (recipient_id == recipient.id) end |
#recipient ⇒ Object
89 90 91 |
# File 'lib/smalltalk/message.rb', line 89 def recipient self.recipient_type.constantize.find(recipient_id) end |
#recipient=(recipient) ⇒ Object
93 94 95 96 |
# File 'lib/smalltalk/message.rb', line 93 def recipient=(recipient) self.recipient_type = recipient.class.name self.recipient_id = recipient.id end |
#reply(params = {}) ⇒ Object
98 99 100 |
# File 'lib/smalltalk/message.rb', line 98 def reply(params = {}) Smalltalk::Reply.new(params.merge(message: self)).build! end |
#sender ⇒ Object
80 81 82 |
# File 'lib/smalltalk/message.rb', line 80 def sender self.sender_type.constantize.find(sender_id) end |
#sender=(sender) ⇒ Object
84 85 86 87 |
# File 'lib/smalltalk/message.rb', line 84 def sender=(sender) self.sender_type = sender.class.name self.sender_id = sender.id end |
#sent_by?(sender) ⇒ Boolean
72 73 74 |
# File 'lib/smalltalk/message.rb', line 72 def sent_by?(sender) (sender_type == sender.class.name) && (sender.id == sender.id) end |
#view! ⇒ Object
107 108 109 110 |
# File 'lib/smalltalk/message.rb', line 107 def view! self.viewed = true self.save! end |