Class: Chatrix::Components::Timeline
- Inherits:
-
Object
- Object
- Chatrix::Components::Timeline
- Includes:
- Wisper::Publisher
- Defined in:
- lib/chatrix/components/timeline.rb
Overview
Manages the timeline for a room.
Instance Method Summary collapse
-
#handle_message(event) ⇒ Object
private
Process a message event.
-
#initialize(room, users) ⇒ Timeline
constructor
Initializes a new Timeline instance.
-
#process_event(event) ⇒ Object
private
Processes a timeline event.
-
#update(data) ⇒ Object
Process timeline events.
Constructor Details
#initialize(room, users) ⇒ Timeline
Initializes a new Timeline instance.
19 20 21 22 |
# File 'lib/chatrix/components/timeline.rb', line 19 def initialize(room, users) @room = room @users = users end |
Instance Method Details
#handle_message(event) ⇒ Object (private)
Process a message event.
46 47 48 49 50 51 52 53 |
# File 'lib/chatrix/components/timeline.rb', line 46 def (event) sender = @users[event['sender']] = event['origin_server_ts'] || Time.now.to_i content = event['content'] = Message.new sender, , content broadcast(:message, @room, ) Events.processed event end |
#process_event(event) ⇒ Object (private)
Processes a timeline event.
38 39 40 41 42 |
# File 'lib/chatrix/components/timeline.rb', line 38 def process_event(event) return if Events.processed? event name = 'handle_' + event['type'].match(/\w+$/).to_s send(name, event) if respond_to? name, true end |
#update(data) ⇒ Object
Process timeline events.
26 27 28 29 30 31 32 |
# File 'lib/chatrix/components/timeline.rb', line 26 def update(data) data['events'].each { |e| process_event e } if data.key? 'events' # Pass the event data to state to handle any state updates # in the timeline @room.state.update data end |