Class: Chatrix::Room
- Inherits:
-
Object
- Object
- Chatrix::Room
- 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
-
#canonical_alias ⇒ String
Convenience method to get the canonical alias from this room's state.
-
#initialize(id, users, matrix) ⇒ Room
constructor
Initializes a new Room instance.
-
#name ⇒ String
Convenience method to get the name from this room's state.
-
#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.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/chatrix/room.rb', line 36 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 end |
Instance Attribute Details
#admin ⇒ Admin (readonly)
Returns Administration object for carrying out administrative actions like kicking and banning of users.
26 27 28 |
# File 'lib/chatrix/room.rb', line 26 def admin @admin end |
#id ⇒ String (readonly)
Returns The ID of this room.
16 17 18 |
# File 'lib/chatrix/room.rb', line 16 def id @id end |
#messaging ⇒ Messaging (readonly)
Returns Handle various message actions through this object.
29 30 31 |
# File 'lib/chatrix/room.rb', line 29 def messaging @messaging end |
#state ⇒ State (readonly)
Returns The state object for this room.
19 20 21 |
# File 'lib/chatrix/room.rb', line 19 def state @state end |
#timeline ⇒ Timeline (readonly)
Returns The timeline object for this room.
22 23 24 |
# File 'lib/chatrix/room.rb', line 22 def timeline @timeline end |
Instance Method Details
#canonical_alias ⇒ String
Convenience method to get the canonical alias from this room's state.
49 50 51 |
# File 'lib/chatrix/room.rb', line 49 def canonical_alias @state.canonical_alias end |
#name ⇒ String
Convenience method to get the name from this room's state.
55 56 57 |
# File 'lib/chatrix/room.rb', line 55 def name @state.name end |
#process_invite(data) ⇒ Object
Process invite events for this room.
68 69 70 |
# File 'lib/chatrix/room.rb', line 68 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.
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/chatrix/room.rb', line 92 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.
61 62 63 64 |
# File 'lib/chatrix/room.rb', line 61 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.
75 76 77 78 |
# File 'lib/chatrix/room.rb', line 75 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.
84 85 86 |
# File 'lib/chatrix/room.rb', line 84 def to_s name || canonical_alias || @id end |