Class: ActsAsMessageable::Message

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
T::Sig
Includes:
Scopes, Ancestry::InstanceMethods
Defined in:
lib/acts_as_messageable/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#removedObject

Returns the value of attribute removed.



17
18
19
# File 'lib/acts_as_messageable/message.rb', line 17

def removed
  @removed
end

#restoredObject

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

#closeObject 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

#conversationObject



96
97
98
# File 'lib/acts_as_messageable/message.rb', line 96

def conversation
  root.subtree
end

#deleteObject



103
104
105
# File 'lib/acts_as_messageable/message.rb', line 103

def delete
  self.removed = true
end

#fromObject



71
72
73
# File 'lib/acts_as_messageable/message.rb', line 71

def from
  sent_messageable
end

#openObject 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

Returns:

  • (Boolean)


37
38
39
# File 'lib/acts_as_messageable/message.rb', line 37

def open?
  opened?
end

#opened?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/acts_as_messageable/message.rb', line 44

def opened?
  opened_at.present? || super
end

#participant?(user) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/acts_as_messageable/message.rb', line 90

def participant?(user)
  user.class.group_messages || (to == user) || (from == user)
end

#peopleObject



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

#restoreObject



110
111
112
# File 'lib/acts_as_messageable/message.rb', line 110

def restore
  self.restored = true
end

#toObject



76
77
78
# File 'lib/acts_as_messageable/message.rb', line 76

def to
  received_messageable
end