Skip to content

Commit

Permalink
Make batch messages consistent.
Browse files Browse the repository at this point in the history
  • Loading branch information
sents committed May 21, 2021
1 parent 89a2315 commit 811e5da
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 34 deletions.
20 changes: 6 additions & 14 deletions client-data/tools/hand/hand.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@
}
})
var msg = {
type: "batch",
msgs: msgs
_children: msgs
};
{
let tmatrix = get_translate_matrix(selectionRect);
Expand Down Expand Up @@ -188,19 +187,11 @@
}

function draw(data) {
if (data._children) {
batchCall(draw, data._children);
}
else {
switch (data.type) {
case "batch":
for ([i,msg] of data.msgs.entries()) {
switch (msg.type) {
case "update":
let tmatrix = get_translate_matrix(Tools.svg.getElementById(msg.id));
tmatrix.e = msg.deltax || 0;
tmatrix.f = msg.deltay || 0;
break;
// Eventually also "delete"?
}
}
break;
case "update":
var elem = Tools.svg.getElementById(data.id);
if (!elem) throw new Error("Mover: Tried to move an element that does not exist.");
Expand All @@ -212,6 +203,7 @@
throw new Error("Mover: 'move' instruction with unknown type. ", data);
}
}
}

function clickSelector(x ,y , evt) {
var scale = Tools.drawingArea.getCTM().a
Expand Down
4 changes: 1 addition & 3 deletions server/boardData.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class BoardData {
* @param {envelope} array of messages to be delegated to the other methods
*/
batch(envelope) {
for (const message of envelope.msgs) {
for (const message of envelope._children) {
let id = message.id;
switch (message.type) {
case "delete":
Expand All @@ -125,8 +125,6 @@ class BoardData {
case "child":
this.addChild(message.parent, message);
break;
case "batch":
throw new Error("Nested batch message: ", message);
default:
//Add data
if (!id) throw new Error("Invalid message: ", message);
Expand Down
39 changes: 22 additions & 17 deletions server/sockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,29 @@ function handleMessage(boardName, message, socket) {

async function saveHistory(boardName, message) {
var id = message.id;
if (!message.tool && !message._children) {
console.error("Received a badly formatted message (no tool). ", message);
}
var board = await getBoard(boardName);
switch (message.type) {
case "delete":
if (id) board.delete(id);
break;
case "update":
if (id) board.update(id, message);
break;
case "child":
board.addChild(message.parent, message);
break;
case "batch":
board.batch(message);
break;
default:
//Add data
if (!id) throw new Error("Invalid message: ", message);
board.set(id, message);
if (message._children) {
board.batch(message);
}
else {
switch (message.type) {
case "delete":
if (id) board.delete(id);
break;
case "update":
if (id) board.update(id, message);
break;
case "child":
board.addChild(message.parent, message);
break;
default:
//Add data
if (!id) throw new Error("Invalid message: ", message);
board.set(id, message);
}
}
}

Expand Down

0 comments on commit 811e5da

Please sign in to comment.