summaryrefslogtreecommitdiffhomepage
path: root/whiteboard.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'whiteboard.cpp')
-rw-r--r--whiteboard.cpp34
1 files changed, 21 insertions, 13 deletions
diff --git a/whiteboard.cpp b/whiteboard.cpp
index b84f7cc..059571d 100644
--- a/whiteboard.cpp
+++ b/whiteboard.cpp
@@ -39,6 +39,7 @@
#include "libreichwein/xml.h"
#include "config.h"
+#include "diff.h"
#include "qrcode.h"
#include "storage.h"
@@ -151,20 +152,27 @@ std::string Whiteboard::handle_request(Whiteboard::connection& c, const std::str
if (command == "modify") {
std::string id {xml.get<std::string>("request.id")};
- std::string data {xml.get<std::string>("request.data")};
- if (m_storage->getDocument(id) != data) {
- m_storage->setDocument(id, data);
- m_registry.setId(c, id);
- notify_other_connections_file(c, id);
-
- int pos {xml.get<int>("request.pos")};
- if (m_storage->getCursorPos(id) != pos) {
- m_storage->setCursorPos(id, pos);
- notify_other_connections_pos(c, id);
- }
- return make_xml({{"type", "modify"}, {"revision", std::to_string(m_storage->getRevision(id)) }});
+
+ int baserev {xml.get<int>("request.baserev")};
+ if (baserev != m_storage->getRevision(id))
+ return make_xml({{"type", "error"}, {"message", "Bad base revision ("s + std::to_string(baserev) + "). Current: "s + std::to_string(m_storage->getRevision(id)) }});
+
+ pt::ptree ptree;
+ ptree.put_child("diff", xml.get_child("request.diff"));
+ Diff d{ptree};
+ std::string data {m_storage->getDocument(id)};
+ data = d.apply(data);
+
+ m_storage->setDocument(id, data);
+ m_registry.setId(c, id);
+ notify_other_connections_file(c, id);
+
+ int pos {xml.get<int>("request.pos")};
+ if (m_storage->getCursorPos(id) != pos) {
+ m_storage->setCursorPos(id, pos);
+ notify_other_connections_pos(c, id);
}
- return {};
+ return make_xml({{"type", "modify"}, {"revision", std::to_string(m_storage->getRevision(id)) }});
} else if (command == "cursorpos") {
std::string id {xml.get<std::string>("request.id")};
int pos {xml.get<int>("request.pos")};