summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Parser/PayloadParsers/WhiteboardParser.cpp2
-rw-r--r--Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp1
-rw-r--r--Swiften/Whiteboard/Operations/WhiteboardUpdateOperation.h9
-rw-r--r--Swiften/Whiteboard/WhiteboardTransformer.cpp36
4 files changed, 44 insertions, 4 deletions
diff --git a/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp
index 12bed17..7ec181f 100644
--- a/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp
+++ b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp
@@ -33,6 +33,8 @@ namespace Swift {
operation = insertOp;
} else if (type == "update") {
WhiteboardUpdateOperation::ref updateOp = boost::make_shared<WhiteboardUpdateOperation>();
+ std::string move = attributes.getAttributeValue("newpos").get_value_or("0");
+ updateOp->setNewPos(boost::lexical_cast<int>(attributes.getAttributeValue("newpos").get_value_or("0")));
operation = updateOp;
} else if (type == "delete") {
WhiteboardDeleteOperation::ref deleteOp = boost::make_shared<WhiteboardDeleteOperation>();
diff --git a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp
index a4fd618..e1380b2 100644
--- a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp
+++ b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp
@@ -160,6 +160,7 @@ namespace Swift {
operationNode->setAttribute("pos", boost::lexical_cast<std::string>(updateOp->getPos()));
operationNode->setAttribute("id", updateOp->getID());
operationNode->setAttribute("parentid", updateOp->getParentID());
+ operationNode->setAttribute("newpos", boost::lexical_cast<std::string>(updateOp->getNewPos()));
} catch (boost::bad_lexical_cast&) {
}
updateOp->getElement()->accept(visitor);
diff --git a/Swiften/Whiteboard/Operations/WhiteboardUpdateOperation.h b/Swiften/Whiteboard/Operations/WhiteboardUpdateOperation.h
index 7c4b088..1b79043 100644
--- a/Swiften/Whiteboard/Operations/WhiteboardUpdateOperation.h
+++ b/Swiften/Whiteboard/Operations/WhiteboardUpdateOperation.h
@@ -26,7 +26,16 @@ namespace Swift {
element_ = element;
}
+ int getNewPos() const {
+ return newPos_;
+ }
+
+ void setNewPos(int newPos) {
+ newPos_ = newPos;
+ }
+
private:
WhiteboardElement::ref element_;
+ int newPos_;
};
}
diff --git a/Swiften/Whiteboard/WhiteboardTransformer.cpp b/Swiften/Whiteboard/WhiteboardTransformer.cpp
index c9dbbbd..88ab7d5 100644
--- a/Swiften/Whiteboard/WhiteboardTransformer.cpp
+++ b/Swiften/Whiteboard/WhiteboardTransformer.cpp
@@ -61,6 +61,24 @@ namespace Swift {
result.second = boost::make_shared<WhiteboardUpdateOperation>(*clientOp);
result.second->setParentID(serverOp->getID());
}
+
+ if (clientOp->getPos() < serverOp->getPos() && clientOp->getNewPos() > serverOp->getPos()) {
+ result.first->setPos(result.first->getPos()-1);
+ if (clientOp->getNewPos() >= serverOp->getNewPos()) {
+ result.first->setNewPos(result.first->getNewPos()-1);
+ }
+ } else if (clientOp->getNewPos() >= serverOp->getNewPos()) {
+ result.first->setNewPos(result.first->getNewPos()-1);
+ }
+
+ if (serverOp->getPos() < clientOp->getPos() && serverOp->getNewPos() > clientOp->getPos()) {
+ result.second->setPos(result.second->getPos()-1);
+ if (serverOp->getNewPos() >= clientOp->getNewPos()) {
+ result.second->setNewPos(result.second->getNewPos()-1);
+ }
+ } else if (serverOp->getNewPos() >= clientOp->getNewPos()) {
+ result.second->setNewPos(result.second->getNewPos()-1);
+ }
return result;
}
@@ -144,7 +162,8 @@ namespace Swift {
std::pair<WhiteboardDeleteOperation::ref, WhiteboardOperation::ref> result;
result.first = boost::make_shared<WhiteboardDeleteOperation>(*serverOp);
result.first->setParentID(clientOp->getID());
- result.second = boost::make_shared<WhiteboardUpdateOperation>(*clientOp);
+ WhiteboardUpdateOperation::ref updateOp = boost::make_shared<WhiteboardUpdateOperation>(*clientOp);
+ result.second = updateOp;
result.second->setParentID(serverOp->getID());
if (clientOp->getPos() == serverOp->getPos()) {
WhiteboardDeleteOperation::ref deleteOp = boost::make_shared<WhiteboardDeleteOperation>();
@@ -153,16 +172,21 @@ namespace Swift {
result.second->setID(clientOp->getID());
result.second->setParentID(serverOp->getID());
deleteOp->setElementID(serverOp->getElementID());
+ } else if (clientOp->getPos() > serverOp->getPos() && clientOp->getNewPos() <= serverOp->getPos()) {
+ result.second->setPos(result.second->getPos()-1);
+ } else if (clientOp->getPos() < serverOp->getPos() && clientOp->getNewPos() >= serverOp->getPos()) {
+ updateOp->setNewPos(updateOp->getNewPos()-1);
} else if (clientOp->getPos() > serverOp->getPos()) {
result.second->setPos(result.second->getPos()-1);
+ updateOp->setNewPos(updateOp->getNewPos()-1);
}
return result;
-//TODO: situation with the same pos
}
std::pair<WhiteboardOperation::ref, WhiteboardOperation::ref> WhiteboardTransformer::transform(WhiteboardDeleteOperation::ref clientOp, WhiteboardUpdateOperation::ref serverOp) {
std::pair<WhiteboardOperation::ref, WhiteboardDeleteOperation::ref> result;
- result.first = boost::make_shared<WhiteboardUpdateOperation>(*serverOp);
+ WhiteboardUpdateOperation::ref updateOp = boost::make_shared<WhiteboardUpdateOperation>(*serverOp);
+ result.first = updateOp;
result.first->setParentID(clientOp->getID());
result.second = boost::make_shared<WhiteboardDeleteOperation>(*clientOp);
result.second->setParentID(serverOp->getID());
@@ -173,10 +197,14 @@ namespace Swift {
result.first->setID(serverOp->getID());
result.first->setParentID(clientOp->getID());
deleteOp->setElementID(clientOp->getElementID());
+ } else if (clientOp->getPos() < serverOp->getPos() && clientOp->getPos() >= serverOp->getNewPos()) {
+ result.first->setPos(result.first->getPos()-1);
+ } else if (clientOp->getPos() > serverOp->getPos() && clientOp->getPos() <= serverOp->getNewPos()) {
+ updateOp->setNewPos(updateOp->getNewPos()-1);
} else if (clientOp->getPos() < serverOp->getPos()) {
result.first->setPos(result.first->getPos()-1);
+ updateOp->setNewPos(updateOp->getNewPos()-1);
}
return result;
-//TODO: situation with the same pos
}
}