class Chatrix::Room

Provides functionality for interacting with a room.

Attributes

admin[R]

@return [Admin] Administration object for carrying out administrative

actions like kicking and banning of users.
id[R]

@return [String] The ID of this room.

messaging[R]

@return [Messaging] Handle various message actions through this object.

state[R]

@return [State] The state object for this room.

timeline[R]

@return [Timeline] The timeline object for this room.

Public Class Methods

new(id, users, matrix) click to toggle source

Initializes a new Room instance.

@param id [String] The room ID. @param users [Users] The User manager. @param matrix [Matrix] The Matrix API instance.

# File lib/chatrix/room.rb, line 47
def initialize(id, users, matrix)
  @id = id
  @users = users
  @matrix = matrix

  @state = Components::State.new self, @users
  @timeline = Components::Timeline.new self, @users
  @messaging = Components::Messaging.new self, @matrix
  @admin = Components::Admin.new self, @matrix

  @timeline.on(:message) { |r, m| broadcast(:message, r, m) }
end

Public Instance Methods

process_invite(data) click to toggle source

Process invite events for this room. @param data [Hash] Event data containing special invite data.

# File lib/chatrix/room.rb, line 69
def process_invite(data)
  data['invite_state']['events'].each { |e| process_invite_event e }
end
process_join(data) click to toggle source

Process join events for this room. @param data [Hash] Event data containing state and timeline events.

# File lib/chatrix/room.rb, line 62
def process_join(data)
  @state.update data['state'] if data.key? 'state'
  @timeline.update data['timeline'] if data.key? 'timeline'
end
process_leave(data) click to toggle source

Process leave events for this room. @param data [Hash] Event data containing state and timeline events up

until the point of leaving the room.
# File lib/chatrix/room.rb, line 76
def process_leave(data)
  @state.update data['state'] if data.key? 'state'
  @timeline.update data['timeline'] if data.key? 'timeline'
end
to_s() click to toggle source

Gets a string representation of this room. @return [String] If the room has a name, that name is returned.

If it has a canonical alias, the alias is returned.
If it has neither a name nor alias, the room ID is returned.
# File lib/chatrix/room.rb, line 85
def to_s
  name || canonical_alias || @id
end

Private Instance Methods

process_invite_event(event) click to toggle source

Process an invite event for this room. @param event [Hash] Event data.

# File lib/chatrix/room.rb, line 93
def process_invite_event(event)
  return unless event['type'] == 'm.room.member'
  return unless event['content']['membership'] == 'invite'
  @users.process_invite self, event
  sender = @users[event['sender']]
  invitee = @users[event['state_key']]
  # Return early if the user is already in the room
  return if @state.member? invitee
  broadcast(:invited, sender, invitee)
end