Class: Chatrix::Message
- Inherits:
-
Object
- Object
- Chatrix::Message
- Defined in:
- lib/chatrix/message.rb
Overview
Describes a message sent in a room.
Constant Summary collapse
- TYPES =
Supported message types.
:html
is a special message type parsed in #parse_body!. { 'm.text' => :text, 'm.emote' => :emote, 'm.notice' => :notice }.freeze
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
The text content of the message.
-
#raw ⇒ Hash
readonly
The raw message data (the
content
field). -
#sender ⇒ User
readonly
The user who sent this message.
-
#timestamp ⇒ Integer
readonly
The timestamp of the message, indicating when it was sent, according to the origin server.
-
#type ⇒ Symbol?
readonly
The type of message.
Instance Method Summary collapse
-
#initialize(sender, timestamp, content) ⇒ Message
constructor
Initializes a new Message instance.
-
#parse_body! ⇒ Object
private
Parses the message content to see if there's any special formatting available.
Constructor Details
#initialize(sender, timestamp, content) ⇒ Message
Initializes a new Message instance.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/chatrix/message.rb', line 40 def initialize(sender, , content) @raw = content @type = TYPES[@raw['msgtype']] @body = @raw['body'] @sender = sender @timestamp = parse_body! end |
Instance Attribute Details
#body ⇒ String (readonly)
Returns The text content of the message. If the message is
of :html
type, this will contain HTML format. To get the raw
message text, use the 'body'
field of the #raw hash.
29 30 31 |
# File 'lib/chatrix/message.rb', line 29 def body @body end |
#raw ⇒ Hash (readonly)
Returns The raw message data (the content
field).
17 18 19 |
# File 'lib/chatrix/message.rb', line 17 def raw @raw end |
#sender ⇒ User (readonly)
Returns The user who sent this message.
24 25 26 |
# File 'lib/chatrix/message.rb', line 24 def sender @sender end |
#timestamp ⇒ Integer (readonly)
Returns The timestamp of the message, indicating when it was sent, according to the origin server.
33 34 35 |
# File 'lib/chatrix/message.rb', line 33 def @timestamp end |
#type ⇒ Symbol? (readonly)
Returns The type of message. Will be nil if the type failed to parse.
21 22 23 |
# File 'lib/chatrix/message.rb', line 21 def type @type end |
Instance Method Details
#parse_body! ⇒ Object (private)
Parses the message content to see if there's any special formatting available.
55 56 57 58 59 60 61 62 |
# File 'lib/chatrix/message.rb', line 55 def parse_body! return unless @raw.key? 'format' case @raw['format'] when 'org.matrix.custom.html' @type = :html @formatted = @raw['formatted_body'] end end |