Class: Message

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

Overview

Represents a message sent from one user to one or more others.

States

Messages can be in 1 of 3 states:

  • unsent - The message has not yet been sent. This is the initial state.

  • queued - The message has been queued for future delivery.

  • sent - The message has been sent.

Interacting with the message

In order to perform actions on the message, such as queueing or delivering, you should always use the associated event action:

  • queue - Queues the message so that you can send it in a separate process

  • deliver - Sends the message to all of the recipients

Message visibility

Although you can delete a message, it will also delete it from the inbox of all the message's recipients. Instead, you can change the visibility of the message. Messages have 1 of 2 states that define its visibility:

  • visible - The message is visible to the sender

  • hidden - The message is hidden from the sender

The visibility of a message can be changed by running the associated action:

  • hide -Hides the message from the sender

  • unhide - Makes the message visible again

Instance Method Summary (collapse)

Instance Method Details

- (Object) bcc(*receivers) Also known as: bcc=

Blind carbon copies the receivers on the message



83
84
85
# File 'app/models/message.rb', line 83

def bcc(*receivers)
  receivers(receivers, 'bcc')
end

- (Object) cc(*receivers) Also known as: cc=

Carbon copies the receivers on the message



77
78
79
# File 'app/models/message.rb', line 77

def cc(*receivers)
  receivers(receivers, 'cc')
end

- (Object) forward

Forwards this message, including the original subject and body in the new message



90
91
92
93
94
# File 'app/models/message.rb', line 90

def forward
  message = self.class.new(:subject => subject, :body => body)
  message.sender = sender
  message
end

- (Object) reply

Replies to this message, including the original subject and body in the new message. Only the original direct receivers are added to the reply.



98
99
100
101
102
103
# File 'app/models/message.rb', line 98

def reply
  message = self.class.new(:subject => subject, :body => body)
  message.sender = sender
  message.to(to)
  message
end

- (Object) reply_to_all

Replies to all recipients on this message, including the original subject and body in the new message. All receivers (direct, cc, and bcc) are added to the reply.



108
109
110
111
112
113
# File 'app/models/message.rb', line 108

def reply_to_all
  message = reply
  message.cc(cc)
  message.bcc(bcc)
  message
end

- (Object) to(*receivers) Also known as: to=

Directly adds the receivers on the message (i.e. they are visible to all recipients)



71
72
73
# File 'app/models/message.rb', line 71

def to(*receivers)
  receivers(receivers, 'to')
end