Class: Message

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Statesman::Adapters::ActiveRecordQueries
Defined in:
app/models/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#recipientObject

Returns the value of attribute recipient.



15
16
17
# File 'app/models/message.rb', line 15

def recipient
  @recipient
end

Instance Method Details

#readObject



53
54
55
# File 'app/models/message.rb', line 53

def read
  transition_to!(:read)
end

#read?Boolean

Returns:

  • (Boolean)


57
58
59
60
# File 'app/models/message.rb', line 57

def read?
  return true if current_state == 'read'
  false
end

#send_notificationObject



49
50
51
# File 'app/models/message.rb', line 49

def send_notification
  Notifier.message_notification(id).deliver_later if receiver.try(:email).present?
end

#set_receiverObject



43
44
45
46
47
# File 'app/models/message.rb', line 43

def set_receiver
  if recipient
    self.receiver = User.where(username: recipient).first
  end
end

#state_machineObject



36
37
38
# File 'app/models/message.rb', line 36

def state_machine
  @state_machine ||= MessageStateMachine.new(self, transition_class: MessageTransition)
end