Module: ActsAsMessageable::Model::InstanceMethods
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/acts_as_messageable/model.rb
Instance Method Summary collapse
- #delete_message(message) ⇒ Object
- #deleted_messages ⇒ Object
- #messages(trash = false) ⇒ Object
- #received_messages ⇒ Object
-
#reply_to(message, *args) ⇒ Object
rubocop:disable Style/ArgumentsForwarding.
- #restore_message(message) ⇒ Object
- #send_message(to, *args) ⇒ Object
- #send_message!(to, *args) ⇒ Object
- #sent_messages ⇒ Object
Instance Method Details
#delete_message(message) ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/acts_as_messageable/model.rb', line 194 def () current_user = self case current_user when .to attribute = .recipient_delete ? :recipient_permanent_delete : :recipient_delete when .from attribute = .sender_delete ? :sender_permanent_delete : :sender_delete else raise "#{current_user} can't delete this message" end .update!(attribute => true) end |
#deleted_messages ⇒ Object
116 117 118 |
# File 'lib/acts_as_messageable/model.rb', line 116 def (true) end |
#messages(trash = false) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/acts_as_messageable/model.rb', line 89 def (trash = false) result = self.class..connected_with(self, trash) result.relation_context = self result end |
#received_messages ⇒ Object
98 99 100 101 102 103 |
# File 'lib/acts_as_messageable/model.rb', line 98 def result = .scope.where(recipient_delete: false) result.relation_context = self result end |
#reply_to(message, *args) ⇒ Object
rubocop:disable Style/ArgumentsForwarding
178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/acts_as_messageable/model.rb', line 178 def reply_to(, *args) # rubocop:disable Style/ArgumentsForwarding current_user = T.cast(self, ActiveRecord::Base) return unless .participant?(current_user) = T.unsafe(self).(.real_receiver(current_user), *args) # rubocop:disable Style/ArgumentsForwarding .parent = .save end |
#restore_message(message) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/acts_as_messageable/model.rb', line 213 def () current_user = self case current_user when .to attribute = :recipient_delete when .from attribute = :sender_delete else raise "#{current_user} can't restore this message" end .update!(attribute => false) end |
#send_message(to, *args) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/acts_as_messageable/model.rb', line 130 def (to, *args) = {} case args.first when String self.class..required.each_with_index do |attribute, index| [attribute] = args[index] end when Hash = args.first end = self.class..new . = to . = self .save! end |
#send_message!(to, *args) ⇒ Object
162 163 164 |
# File 'lib/acts_as_messageable/model.rb', line 162 def (to, *args) T.unsafe(self).(to, *T.unsafe(args)).tap(&:save!) end |
#sent_messages ⇒ Object
107 108 109 110 111 112 |
# File 'lib/acts_as_messageable/model.rb', line 107 def result = .scope.where(sender_delete: false) result.relation_context = self result end |