Class: Message
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Message
- Defined in:
- lib/has_messages/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
-
#bcc(*receivers) ⇒ Object
(also: #bcc=)
Blind carbon copies the receivers on the message.
-
#cc(*receivers) ⇒ Object
(also: #cc=)
Carbon copies the receivers on the message.
-
#forward ⇒ Object
Forwards this message, including the original subject and body in the new message.
- #latest_message ⇒ Object
-
#reply ⇒ Object
Replies to this message, including the original subject and body in the new message.
-
#reply_to_all ⇒ Object
Replies to all recipients on this message, including the original subject and body in the new message.
- #thread ⇒ Object
-
#to(*receivers) ⇒ Object
(also: #to=)
Directly adds the receivers on the message (i.e. they are visible to all recipients).
Instance Method Details
#bcc(*receivers) ⇒ Object Also known as: bcc=
Blind carbon copies the receivers on the message
93 94 95 |
# File 'lib/has_messages/models/message.rb', line 93 def bcc(*receivers) receivers(receivers, 'bcc') end |
#cc(*receivers) ⇒ Object Also known as: cc=
Carbon copies the receivers on the message
87 88 89 |
# File 'lib/has_messages/models/message.rb', line 87 def cc(*receivers) receivers(receivers, 'cc') end |
#forward ⇒ Object
Forwards this message, including the original subject and body in the new message
100 101 102 103 104 |
# File 'lib/has_messages/models/message.rb', line 100 def forward = self.class.new(:subject => subject, :body => body) .sender = sender end |
#latest_message ⇒ Object
76 77 78 |
# File 'lib/has_messages/models/message.rb', line 76 def .last || self end |
#reply ⇒ Object
Replies to this message, including the original subject and body in the new message. Only the original direct receivers are added to the reply.
108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/has_messages/models/message.rb', line 108 def reply = self.class.new(:subject => subject, :body => body) .sender = sender .to(to) # use the very first message to anchor all replies if self. . = self. else . = self end end |
#reply_to_all ⇒ Object
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.
124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/has_messages/models/message.rb', line 124 def reply_to_all = reply .cc(cc) .bcc(bcc) # use the very first message to anchor all replies if self. . = self. else . = self end end |
#thread ⇒ Object
72 73 74 |
# File 'lib/has_messages/models/message.rb', line 72 def thread [self] + end |
#to(*receivers) ⇒ Object Also known as: to=
Directly adds the receivers on the message (i.e. they are visible to all recipients)
81 82 83 |
# File 'lib/has_messages/models/message.rb', line 81 def to(*receivers) receivers(receivers, 'to') end |