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
rubocop:disable Style/ArgumentsForwarding.
- #restore ⇒ Object
- #to ⇒ Object
Constructor Details
#initialize(*args, **kwargs) ⇒ Message
Returns a new instance of Message.
24 25 26 27 28 29 |
# File 'lib/acts_as_messageable/message.rb', line 24 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.
19 20 21 |
# File 'lib/acts_as_messageable/message.rb', line 19 def removed @removed end |
#restored ⇒ Object
Returns the value of attribute restored.
19 20 21 |
# File 'lib/acts_as_messageable/message.rb', line 19 def restored @restored end |
Instance Method Details
#close ⇒ Object Also known as: mark_as_unread, unread
59 60 61 |
# File 'lib/acts_as_messageable/message.rb', line 59 def close update!(opened_at: nil, opened: false) end |
#conversation ⇒ Object
92 93 94 |
# File 'lib/acts_as_messageable/message.rb', line 92 def conversation root.subtree end |
#delete ⇒ Object
99 100 101 |
# File 'lib/acts_as_messageable/message.rb', line 99 def delete self.removed = true end |
#from ⇒ Object
67 68 69 |
# File 'lib/acts_as_messageable/message.rb', line 67 def from end |
#open ⇒ Object Also known as: mark_as_read, read
49 50 51 |
# File 'lib/acts_as_messageable/message.rb', line 49 def open update!(opened_at: Time.current, opened: true) end |
#open? ⇒ Boolean
35 36 37 |
# File 'lib/acts_as_messageable/message.rb', line 35 def open? opened? end |
#opened? ⇒ Boolean
42 43 44 |
# File 'lib/acts_as_messageable/message.rb', line 42 def opened? opened_at.present? || super end |
#participant?(user) ⇒ Boolean
86 87 88 |
# File 'lib/acts_as_messageable/message.rb', line 86 def participant?(user) user.class. || (to == user) || (from == user) end |
#people ⇒ Object
128 129 130 |
# File 'lib/acts_as_messageable/message.rb', line 128 def people conversation.map(&:from).uniq end |
#real_receiver(user) ⇒ Object
79 80 81 |
# File 'lib/acts_as_messageable/message.rb', line 79 def real_receiver(user) user == from ? to : from end |
#reply(*args) ⇒ Object
rubocop:disable Style/ArgumentsForwarding
121 122 123 |
# File 'lib/acts_as_messageable/message.rb', line 121 def reply(*args) # rubocop:disable Style/ArgumentsForwarding T.unsafe(to).reply_to(self, *args) # rubocop:disable Style/ArgumentsForwarding end |
#restore ⇒ Object
106 107 108 |
# File 'lib/acts_as_messageable/message.rb', line 106 def restore self.restored = true end |
#to ⇒ Object
72 73 74 |
# File 'lib/acts_as_messageable/message.rb', line 72 def to end |