Revision 8f6f45f7
Added by Marc Dequènes about 14 years ago
- ID 8f6f45f7b7fcaba40dd0a82c67e1e0ad7cde4dd7
lib/cyborghood/cyborg/conversation.rb | ||
---|---|---|
MAXIMUM_LINES = 1024
|
||
|
||
attr_reader :bot, :peer_name, :peer_capabilities, :protocol
|
||
attr_reader :system_notification, :user_notification
|
||
|
||
def initialize(bot, block = nil)
|
||
@bot = bot
|
||
... | ... | |
@split_data_mode = false
|
||
@split_data_message = nil
|
||
@split_data = []
|
||
@comm_stop = false
|
||
|
||
# associated conversation threads
|
||
@conv_threads = {}
|
||
... | ... | |
@peer_name = nil
|
||
@peer_capabilities = []
|
||
|
||
@comm_stop = false
|
||
@system_notification = EventMachine::Channel.new
|
||
@user_notification = EventMachine::Channel.new
|
||
|
||
@protocol = BotProtocol.new(self)
|
||
|
||
@pending_thread_close = Set.new
|
||
@system_notification_processing = @protocol.system_notification.subscribe do |msg|
|
||
@system_notification_processing = @system_notification.subscribe do |msg|
|
||
process_system_notification(msg)
|
||
end
|
||
end
|
||
... | ... | |
logger.debug "Received data [#{identifier}]: #{data}"
|
||
|
||
if data =~ Regexp.new(ACTION_PATTERN)
|
||
# TODO: pass peer_name into Message and use it in Protocol to check replies match
|
||
peer_name = $1
|
||
conv_thread_id = $2.to_i
|
||
action_id = $3.to_i
|
||
... | ... | |
|
||
def set_comm_stop(peer_left = false)
|
||
@comm_stop = true
|
||
@protocol.system_notification.unsubscribe(@system_notification_processing)
|
||
@system_notification.unsubscribe(@system_notification_processing)
|
||
yield if block_given?
|
||
peer_left ? close_connection : close_connection_after_writing
|
||
end
|
lib/cyborghood/cyborg/protocol.rb | ||
---|---|---|
VERSION = "0.1"
|
||
CAPABILITIES = []
|
||
|
||
attr_reader :system_notification, :user_notification
|
||
|
||
@@request_callback = proc do |result|
|
||
protocol = result[:reply_message].conv_thread.conversation.protocol
|
||
protocol.process_request_result(result)
|
||
... | ... | |
@negociation_ok = false
|
||
|
||
@action_followup = {}
|
||
|
||
@system_notification = EventMachine::Channel.new
|
||
@user_notification = EventMachine::Channel.new
|
||
end
|
||
|
||
def negociation_ok?
|
||
... | ... | |
end
|
||
|
||
def receive_notify_event(message)
|
||
@user_notification << {
|
||
@conversation.user_notification << {
|
||
:from => message.conversation.peer_id,
|
||
:topic => message.action_parameters[:name],
|
||
:info => message.action_parameters[:info]
|
||
... | ... | |
def check_thread_idle(conv_thread)
|
||
return if @action_followup.has_key? conv_thread.id
|
||
|
||
@system_notification << { :topic => 'THREAD IDLE', :thread => conv_thread.name }
|
||
@conversation.system_notification << { :topic => 'THREAD IDLE', :thread => conv_thread.name }
|
||
end
|
||
end
|
||
end
|
Also available in: Unified diff
[evol] move notification from Protocol to Conversation