From fe4231b1dbb41f9eced8005b2e46453a81f08fa9 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Tue, 9 Jun 2020 19:48:35 +0200 Subject: Make sure to send update messages for all create messages that was originally the result of a move message. --- src/messageparser.cc | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'src/messageparser.cc') diff --git a/src/messageparser.cc b/src/messageparser.cc index 1b5fd7f..0f1844e 100644 --- a/src/messageparser.cc +++ b/src/messageparser.cc @@ -332,8 +332,9 @@ MessageList parse_msg_client(std::string data) return msgList; } -std::string msg_tostring(message_t m) +std::vector msg_tostring(message_t m) { + std::vector msgs; std::string msg; switch(m.cmd) @@ -342,27 +343,45 @@ std::string msg_tostring(message_t m) msg = "create " + std::to_string(m.create.id) + " " + std::to_string(m.create.parentid) + " " + - std::to_string(m.create.insertbeforeid); + std::to_string(m.create.insertbeforeid) + ";"; + msgs.push_back(msg); + break; + case cmd::create_with_attributes: + msg = "create " + + std::to_string(m.create.id) + " " + + std::to_string(m.create.parentid) + " " + + std::to_string(m.create.insertbeforeid) + ";"; + msgs.push_back(msg); + for(const auto& attribute : m.attributes) + { + msg = "update " + + std::to_string(m.create.id) + " \"" + + attribute.first + "\" \"" + attribute.second + "\";"; + msgs.push_back(msg); + } break; case cmd::remove: - msg = "remove " + std::to_string(m.remove.id); + msg = "remove " + std::to_string(m.remove.id) + ";"; + msgs.push_back(msg); break; case cmd::move: msg = "move " + std::to_string(m.move.id) + " " + std::to_string(m.move.parentid) + " " + - std::to_string(m.move.insertbeforeid); + std::to_string(m.move.insertbeforeid) + ";"; + msgs.push_back(msg); break; case cmd::update: msg = "update " + std::to_string(m.update.id) + " \"" + - m.update.attribute + "\" \"" + m.update.value + "\""; + m.update.attribute + "\" \"" + m.update.value + "\";"; + msgs.push_back(msg); break; default: break; } - return msg + ";"; + return msgs; } message_t create_msg_create(node_t t, nodeid_t insertbeforeid) @@ -375,6 +394,14 @@ message_t create_msg_create(node_t t, nodeid_t insertbeforeid) return m; } +message_t create_msg_create_with_attributes(node_t node, + nodeid_t insertbeforeid) +{ + auto msg = create_msg_create(node, insertbeforeid); + msg.cmd = cmd::create_with_attributes; + return msg; +} + message_t create_msg_update(node_t t, const std::string &attr) { message_t m; -- cgit v1.2.3