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.



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

def recipient
  @recipient
end

Instance Method Details

#readObject



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

def read
  transition_to!(:read)
end

#read?Boolean

Returns:

  • (Boolean)


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

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

#send_notificationObject



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

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

#set_receiverObject



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

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

#state_machineObject



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

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