Project

General

Profile

« Previous | Next » 

Revision 4afb2001

Added by Marc Dequènes over 13 years ago

  • ID 4afb2001a4b374e656585a1bccdc629d94d74ad9

[evol] preliminary work for NOTIFY: closed thread are handled but close too early in most situations yet (need request/reply tracking)

View differences:

lib/cyborghood/cyborg/conversation.rb
@name = name
@id = id
@session = Session.new
# no need for session for system thread
@session = Session.new unless name == 'system'
@next_action_id = 0
end
......
id
end
def close
def close(notify = true)
# the system thread cannot be closed
return if name == 'system'
@conversation.protocol.send_notify_thread_closed(self) if notify
@conversation.delete_thread(self)
@session.clear
end
end
......
def unbind
logger.info "Conversation finished with #{identifier} (#{@peer_name})"
@bot.unregister_communication @peer_name unless @peer_name.nil?
@conv_threads.each_value {|s| s.close }
@conv_threads.each_value {|s| s.close(false) }
@conv_threads = {}
@conv_threads_index = {}
@comm_logic_block.call false unless @comm_logic_block.nil? or @protocol.negociation_ok?
end
......
end
def thread(name = 'default')
@conv_threads[name] || new_thread(name)
th = @conv_threads[name] || new_thread(name)
if block_given?
yield th
# TODO: wait for end of chat
close_thread(name)
else
th
end
end
def thread_by_id(id)
......
name.nil? ? new_thread("noname/#{id}", id) : @conv_threads[name]
end
def close_thread(name)
return if name == 'system'
# ignore mistakes
return unless @conv_threads.has_key? name
@conv_threads[name].close
end
def delete_thread(th)
@conv_threads_index.delete(th.id)
@conv_threads.delete(th.name)
end
def send_message(message)
raise CyberError.new(:unrecoverable, "bot/conversation", "Cannot send message without action id") if message.action_id.nil?

Also available in: Unified diff