class Chatrix::Message
Describes a message sent in a room.
Constants
- TYPES
Supported message types.
`:html` is a special message type parsed in {#parse_body!}.
Attributes
body[R]
@return [String] 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.
raw[R]
@return [Hash] The raw message data (the `content` field).
sender[R]
@return [User] The user who sent this message.
timestamp[R]
@return [Integer] The timestamp of the message, indicating when
it was sent, according to the origin server.
type[R]
@return [Symbol,nil] The type of message. Will be nil if the type
failed to parse.
Public Class Methods
new(sender, timestamp, content)
click to toggle source
Initializes a new Message
instance.
@param sender [User] The user who sent the message. @param timestamp [Integer] The timestamp of the message. @param content [Hash] The message content.
# File lib/chatrix/message.rb, line 40 def initialize(sender, timestamp, content) @raw = content @type = TYPES[@raw['msgtype']] @body = @raw['body'] @sender = sender @timestamp = timestamp parse_body! end
Private Instance Methods
parse_body!()
click to toggle source
Parses the message content to see if there's any special formatting available.
# 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