diff options
Diffstat (limited to 'src/munia_proto.cc')
-rw-r--r-- | src/munia_proto.cc | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/src/munia_proto.cc b/src/munia_proto.cc index d9b068f..3022042 100644 --- a/src/munia_proto.cc +++ b/src/munia_proto.cc @@ -147,30 +147,62 @@ int callback_lws_task(struct libwebsocket_context * context, std::string msgstr; msgstr.append((size_t)LWS_SEND_BUFFER_PRE_PADDING, ' '); + int c = 0; + message_t prevmsg; + std::queue<message_t> messages; while(msgqueue[wsi].size() > 0) { message_t msg = msgqueue[wsi].front(); msgqueue[wsi].pop(); + + //Rewriting delete id followed by create id to move to_id from_id + // look at previous message from create commands + if(c > 0 && // look backward (skip first entry) + msg.cmd == cmd::create && // look from create commands + prevmsg.cmd == cmd::remove && // if previous msg is a remove command + msg.create.id == prevmsg.remove.id) { // and commands have same id + + printf("\tprevmsg: %s, msg: %s\n", msg_tostring(prevmsg).c_str(), + msg_tostring(msg).c_str()); + message_t movemsg = create_msg_move(msg.create.id, msg.create.parentid); + msg = movemsg; + } + else if(c > 0) { + messages.push(prevmsg); + } + + prevmsg = msg; + c++; + } + if(c > 0) { // Push last msg + messages.push(prevmsg); + } + + // create msg string + // while(msgqueue[wsi].size() > 0) { + while(messages.size() > 0) { + message_t msg = messages.front(); + messages.pop(); char buf[32]; sprintf(buf, "%d", msg.tid); + printf("msg: %s\n", msg_tostring(msg).c_str()); if(msgstr.size() > LWS_SEND_BUFFER_PRE_PADDING) msgstr += " "; msgstr += std::string(buf) + " " + msg_tostring(msg); } msgstr.append((size_t)LWS_SEND_BUFFER_POST_PADDING, ' '); - + int n = libwebsocket_write(wsi, (unsigned char *) - msgstr.c_str() + - LWS_SEND_BUFFER_PRE_PADDING, - msgstr.length() - - LWS_SEND_BUFFER_POST_PADDING - - LWS_SEND_BUFFER_PRE_PADDING, - LWS_WRITE_TEXT); + msgstr.c_str() + + LWS_SEND_BUFFER_PRE_PADDING, + msgstr.length() - + LWS_SEND_BUFFER_POST_PADDING - + LWS_SEND_BUFFER_PRE_PADDING, + LWS_WRITE_TEXT); if(n < 0) { fprintf(stderr, "ERROR writing to socket"); exit(1); - } - } - + } } + break; /* @@ -228,7 +260,6 @@ int callback_lws_task(struct libwebsocket_context * context, id++; } - } else { printf("%d nodes affected by command\n", omi->nodes.size()); |