Revision 06f77931
Added by Marc Dequènes over 13 years ago
- ID 06f77931318bb489eca93b67514ccc34db6f788e
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
|
||
... | ... | |
@peer_name = nil
|
||
@peer_capabilities = []
|
||
|
||
@system_notification = EventMachine::Channel.new
|
||
@user_notification = EventMachine::Channel.new
|
||
|
||
@protocol = BotProtocol.new(self)
|
||
|
||
@pending_thread_close = Set.new
|
||
# we don't know the peer name yet
|
||
@system_notification_name = "peer/#{identifier}/system"
|
||
@system_notification = @bot.get_channel(@system_notification_name)
|
||
@system_notification_processing = @system_notification.subscribe do |msg|
|
||
process_system_notification(msg)
|
||
end
|
||
... | ... | |
def unbind
|
||
logger.info "Conversation finished with #{identifier} (#{@peer_name})"
|
||
@bot.unregister_communication @peer_name unless @peer_name.nil?
|
||
@bot.drop_channel(@system_notification_name)
|
||
@conv_threads.each_value {|s| s.close(false) }
|
||
@conv_threads = {}
|
||
@conv_threads_index = {}
|
||
... | ... | |
|
||
# if only the system thread remains, notify idleness
|
||
if @conv_threads.size == 1
|
||
@bot.system_notification << { :topic => 'CONVERSATION IDLE', :peer => peer_name }
|
||
@bot.get_channel('global/system') << {
|
||
:topic => 'CONVERSATION IDLE',
|
||
:peer => peer_name
|
||
}
|
||
end
|
||
end
|
||
|
||
... | ... | |
end
|
||
end
|
||
|
||
def identifier
|
||
"#{@bot.identifier_prefix}/#{@signature}"
|
||
end
|
||
|
||
protected
|
||
|
||
def clear_receive_info
|
||
... | ... | |
@split_data = []
|
||
end
|
||
|
||
def identifier
|
||
"#{@bot.identifier_prefix}/#{@signature}"
|
||
end
|
||
|
||
def process_system_notification(msg)
|
||
return unless msg[:topic] == 'THREAD IDLE'
|
||
|
Also available in: Unified diff
[evol] reworked notification system a bit (global registration)