Revision 3cd21861
Added by Marc Dequènes about 14 years ago
- ID 3cd21861e510bc60f5fb661dbd97dddcef2d31fa
lib/cyborghood/cyborg/conversation.rb | ||
---|---|---|
end
|
||
|
||
class Message
|
||
attr_reader :conv_thread, :action_code, :action_parameters, :action_id, :reply_to_action_id
|
||
attr_reader :conv_thread, :action_code, :action_parameters, :action_id
|
||
|
||
def initialize(conv_thread, action_code, action_parameters = nil, action_id = nil)
|
||
@conv_thread = conv_thread
|
||
@action_code = action_code
|
||
@action_parameters = action_parameters
|
||
@reply_to_action_id = action_id
|
||
# reply with the matching action id
|
||
# (the namespace for requests is on our side, the namespace for replies is on peer side,
|
||
# and we may end up using the same action id is a server acts as client)
|
||
@action_id = action_id
|
||
|
||
@action_id = nil
|
||
@sent = false
|
||
end
|
||
|
||
def new?
|
||
@reply_to_action_id.nil?
|
||
@action_id.nil?
|
||
end
|
||
|
||
def sent?
|
||
@action_id.nil?
|
||
@sent
|
||
end
|
||
|
||
def send
|
||
raise CyberError.new(:unrecoverable, "bot/conversation", "Not sending twice the same message") unless self.sent?
|
||
@action_id = @conv_thread.next_action_id
|
||
raise CyberError.new(:unrecoverable, "bot/conversation", "Not sending twice the same message") if self.sent?
|
||
@action_id = @conv_thread.next_action_id if @action_id.nil?
|
||
@conv_thread.conversation.send_message(self)
|
||
@sent = true
|
||
end
|
||
|
||
def create_reply(action_code, parameters = nil)
|
||
... | ... | |
parameters = YAML.load(@split_data.join("\n"))
|
||
reply_syntax_error("bad parameters format") if parameters.nil?
|
||
|
||
message = @split_data_message.conv_thread.new_message(@split_data_message.action_code, parameters, @split_data_message.reply_to_action_id)
|
||
message = @split_data_message.conv_thread.new_message(@split_data_message.action_code, parameters, @split_data_message.action_id)
|
||
receive_message(message)
|
||
else
|
||
reply_fatal_error "not in split mode"
|
Also available in: Unified diff
[fix] correct action_id generation (a reply should use the same id as the corresponding request)