Class: ActsAsMessageable::Message
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ActsAsMessageable::Message
- Extended by:
- T::Sig
- Includes:
- Scopes, Ancestry::InstanceMethods
- Defined in:
- lib/acts_as_messageable/message.rb
Instance Attribute Summary collapse
-
#removed ⇒ Object
Returns the value of attribute removed.
-
#restored ⇒ Object
Returns the value of attribute restored.
Instance Method Summary collapse
- #close ⇒ Object (also: #mark_as_unread, #unread)
- #conversation ⇒ Object
- #delete ⇒ Object
- #from ⇒ Object
-
#initialize(*args, **kwargs) ⇒ Message
constructor
A new instance of Message.
- #open ⇒ Object (also: #mark_as_read, #read)
- #open? ⇒ Boolean
- #opened? ⇒ Boolean
- #participant?(user) ⇒ Boolean
- #people ⇒ Object
- #real_receiver(user) ⇒ Object
- #reply(*args) ⇒ Object
- #restore ⇒ Object
- #to ⇒ Object
Constructor Details
#initialize(*args, **kwargs) ⇒ Message
Returns a new instance of Message.
22 23 24 25 26 27 |
# File 'lib/acts_as_messageable/message.rb', line 22 def initialize(*args, **kwargs) @removed = T.let(false, T.nilable(T::Boolean)) @restored = T.let(false, T.nilable(T::Boolean)) super end |
Instance Attribute Details
#removed ⇒ Object
Returns the value of attribute removed.
17 18 19 |
# File 'lib/acts_as_messageable/message.rb', line 17 def removed @removed end |
#restored ⇒ Object
Returns the value of attribute restored.
17 18 19 |
# File 'lib/acts_as_messageable/message.rb', line 17 def restored @restored end |
Instance Method Details
#close ⇒ Object Also known as: mark_as_unread, unread
62 63 64 65 |
# File 'lib/acts_as_messageable/message.rb', line 62 def close ActsAsMessageable.rails_api.new(self).update_attributes!(opened_at: nil) ActsAsMessageable.rails_api.new(self).update_attributes!(opened: false) end |
#conversation ⇒ Object
96 97 98 |
# File 'lib/acts_as_messageable/message.rb', line 96 def conversation root.subtree end |
#delete ⇒ Object
103 104 105 |
# File 'lib/acts_as_messageable/message.rb', line 103 def delete self.removed = true end |
#from ⇒ Object
71 72 73 |
# File 'lib/acts_as_messageable/message.rb', line 71 def from end |
#open ⇒ Object Also known as: mark_as_read, read
51 52 53 54 |
# File 'lib/acts_as_messageable/message.rb', line 51 def open ActsAsMessageable.rails_api.new(self).update_attributes!(opened_at: DateTime.now) ActsAsMessageable.rails_api.new(self).update_attributes!(opened: true) end |
#open? ⇒ Boolean
37 38 39 |
# File 'lib/acts_as_messageable/message.rb', line 37 def open? opened? end |
#opened? ⇒ Boolean
44 45 46 |
# File 'lib/acts_as_messageable/message.rb', line 44 def opened? opened_at.present? || super end |
#participant?(user) ⇒ Boolean
90 91 92 |
# File 'lib/acts_as_messageable/message.rb', line 90 def participant?(user) user.class. || (to == user) || (from == user) end |
#people ⇒ Object
132 133 134 |
# File 'lib/acts_as_messageable/message.rb', line 132 def people conversation.map(&:from).uniq! end |
#real_receiver(user) ⇒ Object
83 84 85 |
# File 'lib/acts_as_messageable/message.rb', line 83 def real_receiver(user) user == from ? to : from end |
#reply(*args) ⇒ Object
125 126 127 |
# File 'lib/acts_as_messageable/message.rb', line 125 def reply(*args) T.unsafe(to).reply_to(self, *args) end |
#restore ⇒ Object
110 111 112 |
# File 'lib/acts_as_messageable/message.rb', line 110 def restore self.restored = true end |
#to ⇒ Object
76 77 78 |
# File 'lib/acts_as_messageable/message.rb', line 76 def to end |