[Libreoffice-commits] online.git: loleaflet/src wsd/ClientSession.cpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/protocol.txt

Pranav Kant pranavk at collabora.co.uk
Thu Jun 1 16:13:23 UTC 2017


 loleaflet/src/core/Socket.js |   12 ++++++++++++
 wsd/ClientSession.cpp        |    5 ++++-
 wsd/DocumentBroker.cpp       |   18 +++++++++++++-----
 wsd/DocumentBroker.hpp       |    3 +++
 wsd/protocol.txt             |   14 +++++++++-----
 5 files changed, 41 insertions(+), 11 deletions(-)

New commits:
commit f4b22bbb3c82c1e841934f98280f5deb2256f326
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Thu Jun 1 21:41:11 2017 +0530

    Broadcast command result back to clients
    
    This is required to tell the clients if the command they issued was
    successfull or not. In this case 'savetostorage' is the command that we
    are interested in knowing the success status of.
    
    With this, now if the user commands to overwrite the document, dialog
    boxes of all other users are automatically closed.
    
    Can easily more commands in future for this kind of thing. Its similar
    to unocommandresult, except its not a uno command, but our internal
    command.
    
    Change-Id: I2e7e1fd5edbd55c13ee4bf9bce24284483d6507f

diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index b3b99f48..e1cfde78 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -221,6 +221,18 @@ L.Socket = L.Class.extend({
 			this._map.fire('wopiprops', wopiInfo);
 			return;
 		}
+		else if (textMsg.startsWith('commandresult: ')) {
+			var commandresult = JSON.parse(textMsg.substring(textMsg.indexOf('{')));
+			if (commandresult['command'] === 'savetostorage' && commandresult['success']) {
+				// Close any open confirmation dialogs
+				if (vex.dialogID > 0) {
+					var id = vex.dialogID;
+					vex.dialogID = -1;
+					vex.close(id);
+				}
+			}
+			return;
+		}
 		else if (textMsg.startsWith('close: ')) {
 			textMsg = textMsg.substring('close: '.length);
 			msg = '';
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 7af580bb..20b50b22 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -226,7 +226,10 @@ bool ClientSession::_handleInput(const char *buffer, int length)
     {
         int force = 0;
         getTokenInteger(tokens[1], "force", force);
-        docBroker->saveToStorage(getId(), true, "" /* This is irrelevant when success is true*/, true);
+        if (docBroker->saveToStorage(getId(), true, "" /* This is irrelevant when success is true*/, true))
+        {
+            docBroker->broadcastMessage("commandresult: { \"command\": \"savetostorage\", \"success\": true }");
+        }
     }
     else
     {
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 2aa10d21..dfad745e 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -627,6 +627,7 @@ bool DocumentBroker::saveToStorageInternal(const std::string& sessionId,
 
         // So set _documentLastModifiedTime then
         _documentLastModifiedTime = _storage->getFileInfo()._modifiedTime;
+
         // After a successful save, we are sure that document in the storage is same as ours
         _documentChangedInStorage = false;
 
@@ -662,11 +663,7 @@ bool DocumentBroker::saveToStorageInternal(const std::string& sessionId,
     {
         LOG_ERR("PutFile says that Document changed in storage");
         _documentChangedInStorage = true;
-        // Inform all clients
-        for (const auto& sessionIt : _sessions)
-        {
-            sessionIt.second->sendTextFrame("error: cmd=storage kind=documentconflict");
-        }
+        broadcastMessage("error: cmd=storage kind=documentconflict");
     }
 
     return false;
@@ -1418,6 +1415,17 @@ void DocumentBroker::closeDocument(const std::string& reason)
     terminateChild(reason, false);
 }
 
+void DocumentBroker::broadcastMessage(const std::string& message)
+{
+    assertCorrectThread();
+
+    LOG_DBG("Broadcasting message [" << message << "] to all sessions.");
+    for (const auto& sessionIt : _sessions)
+    {
+        sessionIt.second->sendTextFrame(message);
+    }
+}
+
 void DocumentBroker::updateLastActivityTime()
 {
     _lastActivityTime = std::chrono::steady_clock::now();
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 7f563647..1329fcb1 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -339,6 +339,9 @@ public:
     /// Sends the .uno:Save command to LoKit.
     bool sendUnoSave(const std::string& sessionId, bool dontTerminateEdit = true, bool dontSaveIfUnmodified = true);
 
+    /// Sends a message to all sessions
+    void broadcastMessage(const std::string& message);
+
 private:
 
     /// Shutdown all client connections with the given reason.
diff --git a/wsd/protocol.txt b/wsd/protocol.txt
index e3bf12ab..7f43e472 100644
--- a/wsd/protocol.txt
+++ b/wsd/protocol.txt
@@ -334,6 +334,10 @@ tile: part=<partNumber> width=<width> height=<height> tileposx=<xpos> tileposy=<
     a hash of the tile contents, and can be included by the client in
     the next 'tile' message requesting the same tile.
 
+commandresult: <payload>
+    This is used to acknowledge the commands from the client.
+    <payload> is { command: <command name>, success: 'true' }
+
 Each LOK_CALLBACK_FOO_BAR callback except
 LOK_CALLBACK_INVALIDATE_TILES causes a corresponding message to the
 client, consisting of the FOO_BAR part in lowercase, without
@@ -343,12 +347,12 @@ message as documented above.) For instance:
 
 invalidatecursor: <payload>
 
-The payload contains a rectangle describing the cursor position.
+    The payload contains a rectangle describing the cursor position.
 
-The communication between the parent process (the one keeping open the
-Websocket connections to the clients) and a child process (handling
-one document through LibreOfficeKit) uses the same protocol, with
-the following additions and changes:
+    The communication between the parent process (the one keeping open the
+    Websocket connections to the clients) and a child process (handling
+    one document through LibreOfficeKit) uses the same protocol, with
+    the following additions and changes:
 
 unocommandresult: <payload>
 


More information about the Libreoffice-commits mailing list