Class: MessageRecipient

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

Overview

Represents a recipient on a message. The kind of recipient (to, cc, or bcc) is determined by the kind attribute.

States

Recipients can be in 1 of 2 states:

  • unread - The message has been sent, but not yet read by the recipient. This is the initial state.

  • read - The message has been read by the recipient

Interacting with the message

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

  • view - Marks the message as read by the recipient

Hiding messages

Although you can delete a recipient, it will also delete it from everyone else's message, meaning that no one will know that person was ever a recipient of the message. 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 recipient

  • hidden - The message is hidden from the recipient

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

  • hide -Hides the message from the recipient

  • unhide - Makes the message visible again

Instance Method Summary (collapse)

Instance Method Details

- (Object) forward

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



71
72
73
74
75
# File 'app/models/message_recipient.rb', line 71

def forward
  message = self.message.class.new(:subject => subject, :body => body)
  message.sender = receiver
  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.



79
80
81
82
83
84
# File 'app/models/message_recipient.rb', line 79

def reply
  message = self.message.class.new(:subject => subject, :body => body)
  message.sender = receiver
  message.to(sender)
  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 (sender, direct, cc, and bcc) are added to the reply.



89
90
91
92
93
94
95
# File 'app/models/message_recipient.rb', line 89

def reply_to_all
  message = reply
  message.to(to - [receiver] + [sender])
  message.cc(cc - [receiver])
  message.bcc(bcc - [receiver])
  message
end