Class: Chatrix::Room
- Inherits:
-
Object
- Object
- Chatrix::Room
- Extended by:
- Forwardable
- Includes:
- Wisper::Publisher
- Defined in:
- lib/chatrix/room.rb
Overview
Provides functionality for interacting with a room.
Instance Attribute Summary collapse
-
#admin ⇒ Admin
readonly
Administration object for carrying out administrative actions like kicking and banning of users.
-
#id ⇒ String
readonly
The ID of this room.
-
#messaging ⇒ Messaging
readonly
Handle various message actions through this object.
-
#state ⇒ State
readonly
The state object for this room.
-
#timeline ⇒ Timeline
readonly
The timeline object for this room.
Instance Method Summary collapse
-
#initialize(id, users, matrix) ⇒ Room
constructor
Initializes a new Room instance.
-
#process_invite(data) ⇒ Object
Process invite events for this room.
-
#process_invite_event(event) ⇒ Object
private
Process an invite event for this room.
-
#process_join(data) ⇒ Object
Process join events for this room.
-
#process_leave(data) ⇒ Object
Process leave events for this room.
-
#to_s ⇒ String
Gets a string representation of this room.
Constructor Details
#initialize(id, users, matrix) ⇒ Room
Initializes a new Room instance.
47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 |
Instance Attribute Details
#admin ⇒ Admin (readonly)
Returns Administration object for carrying out administrative actions like kicking and banning of users.
28 29 30 |
# File 'lib/chatrix/room.rb', line 28 def admin @admin end |
#id ⇒ String (readonly)
Returns The ID of this room.
18 19 20 |
# File 'lib/chatrix/room.rb', line 18 def id @id end |
#messaging ⇒ Messaging (readonly)
Returns Handle various message actions through this object.
31 32 33 |
# File 'lib/chatrix/room.rb', line 31 def messaging @messaging end |
#state ⇒ State (readonly)
Returns The state object for this room.
21 22 23 |
# File 'lib/chatrix/room.rb', line 21 def state @state end |
#timeline ⇒ Timeline (readonly)
Returns The timeline object for this room.
24 25 26 |
# File 'lib/chatrix/room.rb', line 24 def timeline @timeline end |
Instance Method Details
#process_invite(data) ⇒ Object
Process invite events for this room.
69 70 71 |
# File 'lib/chatrix/room.rb', line 69 def process_invite(data) data['invite_state']['events'].each { |e| process_invite_event e } end |
#process_invite_event(event) ⇒ Object (private)
Process an invite event for this room.
93 94 95 96 97 98 99 100 101 102 |
# 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 |
#process_join(data) ⇒ Object
Process join events for this room.
62 63 64 65 |
# 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) ⇒ Object
Process leave events for this room.
76 77 78 79 |
# 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 ⇒ String
Gets a string representation of this room.
85 86 87 |
# File 'lib/chatrix/room.rb', line 85 def to_s name || canonical_alias || @id end |