[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-2-1' - loleaflet/src wsd/DocumentBroker.cpp wsd/reference.txt wsd/Storage.cpp wsd/Storage.hpp

2017-08-29 Thread Jan Holesovsky
 loleaflet/src/core/Socket.js  |9 +++--
 loleaflet/src/map/Map.js  |9 +++--
 loleaflet/src/map/handler/Map.WOPI.js |2 ++
 wsd/DocumentBroker.cpp|1 +
 wsd/Storage.cpp   |4 +++-
 wsd/Storage.hpp   |4 
 wsd/reference.txt |6 ++
 7 files changed, 30 insertions(+), 5 deletions(-)

New commits:
commit f71ea056a8b1820188fc5091cfa2b2c7b79eb8c0
Author: Jan Holesovsky 
Date:   Tue Aug 29 18:59:14 2017 +0200

WOPI extension: DisableInactiveMessages to avoid showing message when 
dimmed.

Change-Id: I925602295dde95611ab1a6565dd7266460769a50
Reviewed-on: https://gerrit.libreoffice.org/41707
Reviewed-by: pranavk 
Tested-by: pranavk 

diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index b9f9b0fe..163dfd5c 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -244,7 +244,7 @@ L.Socket = L.Class.extend({
msg = _('Session terminated by document owner');
}
else if (textMsg === 'idle' || textMsg === 'oom') {
-   msg = _('Session was terminated due to idleness 
- please click to reload');
+   msg = _('Idle document - please click to reload 
and resume editing');
this._map._documentIdle = true;
}
else if (textMsg === 'shuttingdown') {
@@ -310,12 +310,17 @@ L.Socket = L.Class.extend({
vex.close(id);
}
 
+   var message = '';
+   if (!this._map['wopi'].DisableInactiveMessages) {
+   message = msg;
+   }
+
var options = $.extend({}, vex.defaultOptions, {
contentCSS: {'background':'rgba(0, 0, 0, 0)',
 'font-size': 'xx-large',
 'color': '#fff',
 'text-align': 'center'},
-   content: msg
+   content: message
});
options.id = vex.globalID;
vex.dialogID = options.id;
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index 0405102b..d4869820 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -843,12 +843,18 @@ L.Map = L.Evented.extend({
this._active = false;
clearTimeout(vex.timer);
 
+   var message = '';
+   var map = this;
+   if (!map['wopi'].DisableInactiveMessages) {
+   message = _('Inactive document - please click to resume 
editing');
+   }
+
var options = $.extend({}, vex.defaultOptions, {
contentCSS: {'background':'rgba(0, 0, 0, 0)',
 'font-size': 'xx-large',
 'color': '#fff',
 'text-align': 'center'},
-   content: _('Inactive document - please click to resume 
editing')
+   content: message
});
options.id = vex.globalID;
vex.dialogID = options.id;
@@ -860,7 +866,6 @@ L.Map = L.Evented.extend({
vex: options
});
 
-   var map = this;
options.$vex.bind('click.vex', function(e) {
console.debug('_dim: click.vex function');
return map._activate();
diff --git a/loleaflet/src/map/handler/Map.WOPI.js 
b/loleaflet/src/map/handler/Map.WOPI.js
index 8e96efcc..acc999b8 100644
--- a/loleaflet/src/map/handler/Map.WOPI.js
+++ b/loleaflet/src/map/handler/Map.WOPI.js
@@ -15,6 +15,7 @@ L.Map.WOPI = L.Handler.extend({
DisablePrint: false,
DisableExport: false,
DisableCopy: false,
+   DisableInactiveMessages: false,
 
_appLoadedConditions: {
doclayerinit: false,
@@ -65,6 +66,7 @@ L.Map.WOPI = L.Handler.extend({
this.DisablePrint = !!wopiInfo['DisablePrint'];
this.DisableExport = !!wopiInfo['DisableExport'];
this.DisableCopy = !!wopiInfo['DisableCopy'];
+   this.DisableInactiveMessages = 
!!wopiInfo['DisableInactiveMessages'];
 
this._map.fire('postMessage', {msgId: 'App_LoadingStatus', 
args: {Status: 'Frame_Ready'}});
},
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index c18526cd..04bb2685 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -442,6 +442,7 @@ 

[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-2-1' - loleaflet/src wsd/DocumentBroker.cpp wsd/protocol.txt

2017-08-01 Thread Pranav Kant
 loleaflet/src/core/Socket.js |3 +--
 wsd/DocumentBroker.cpp   |   22 ++
 wsd/protocol.txt |6 +++---
 3 files changed, 22 insertions(+), 9 deletions(-)

New commits:
commit c8e462fb6fd2b78e2d522a22005558f203dadced
Author: Pranav Kant 
Date:   Mon Jun 19 20:00:37 2017 +0530

wsd: Don't show dialog if document is unmodified

Change-Id: Ibb9e2122461c577863d1f713070748bdda6129d1
(cherry picked from commit c88780b2d4d7b86810f24fecd5cc2aa8a04781e7)
Reviewed-on: https://gerrit.libreoffice.org/40616
Reviewed-by: Jan Holesovsky 
Tested-by: Jan Holesovsky 

diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 88d3fd4d..2de5cceb 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -282,8 +282,7 @@ L.Socket = L.Class.extend({
}, timeoutMs);
}
else if (textMsg.startsWith('documentconflict')) {
-   var username = 
textMsg.substring('documentconflict '.length);
-   msg = _('%user asked to refresh the document. 
Document will now refresh automatically.').replace('%user', username);
+   msg = _('Document has changed in storage. 
Loading the new document. Your version is available as revision.');
 
if (this._map._docLayer) {
this._map._docLayer.removeAllViews();
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 46eef5e5..eb3fc099 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -511,9 +511,16 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
  << "Actual: " << fileInfo._modifiedTime << Log::end;
 
 _documentChangedInStorage = true;
-const std::string errorMsg = "error: cmd=storage 
kind=documentconflict";
-session->sendTextFrame(errorMsg);
-broadcastMessage(errorMsg);
+if (_isModified)
+{
+const std::string errorMsg = "error: cmd=storage 
kind=documentconflict";
+session->sendTextFrame(errorMsg);
+broadcastMessage(errorMsg);
+}
+else
+{
+closeDocument("documentconflict");
+}
 }
 }
 
@@ -675,7 +682,14 @@ bool DocumentBroker::saveToStorageInternal(const 
std::string& sessionId,
 {
 LOG_ERR("PutFile says that Document changed in storage");
 _documentChangedInStorage = true;
-broadcastMessage("error: cmd=storage kind=documentconflict");
+if (_isModified)
+{
+broadcastMessage("error: cmd=storage kind=documentconflict");
+}
+else
+{
+closeDocument("documentconflict");
+}
 }
 
 return false;
diff --git a/wsd/protocol.txt b/wsd/protocol.txt
index e775a605..7ac54b68 100644
--- a/wsd/protocol.txt
+++ b/wsd/protocol.txt
@@ -277,9 +277,9 @@ close: 
 shutting down to let clients know they can try connecting
 after a short interval.
 
-* documentconflict  - All sessions of this document are going 
down
-because file was changed in storage and one of the user ( with ) asked to reload the session for all.
+* documentconflict - All sessions of this document are going down
+because file was changed in storage and we want to load the new document
+from the storage.
 
 getchildid: id=
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-2-1' - loleaflet/src wsd/DocumentBroker.cpp

2017-06-22 Thread Pranav Kant
 loleaflet/src/core/Socket.js |3 +++
 wsd/DocumentBroker.cpp   |8 +++-
 2 files changed, 6 insertions(+), 5 deletions(-)

New commits:
commit eb7fcd66074785cf37a522922d92105b52ce2c2a
Author: Pranav Kant 
Date:   Thu Jun 1 22:02:08 2017 +0530

Inform the current session about document change too

Change-Id: I9947eb8b23e5a698cc2cbf39bfde4e1941aae0f0
(cherry picked from commit a0710c9613309cb7be2934e8eedc75507185b87f)
Reviewed-on: https://gerrit.libreoffice.org/38534
Reviewed-by: Jan Holesovsky 
Tested-by: Jan Holesovsky 

diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index fa03820a..444abe62 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -285,6 +285,9 @@ L.Socket = L.Class.extend({
var username = 
textMsg.substring('documentconflict '.length);
msg = _('%user asked to refresh the document. 
Document will now refresh automatically.').replace('%user', username);
 
+   if (this._map._docLayer) {
+   this._map._docLayer.removeAllViews();
+   }
// Detach all the handlers from current socket, 
otherwise _onSocketClose tries to reconnect again
// However, we want to reconnect manually here.
this.close();
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 850baf66..cd7c3438 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -495,11 +495,9 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 {
 LOG_WRN("Document [" << _docKey << "] has been modified behind our 
back. Informing all clients.");
 _documentChangedInStorage = true;
-// Inform all clients
-for (const auto& sessionIt : _sessions)
-{
-sessionIt.second->sendTextFrame("error: cmd=storage 
kind=documentconflict");
-}
+const std::string errorMsg = "error: cmd=storage 
kind=documentconflict";
+session->sendTextFrame(errorMsg);
+broadcastMessage(errorMsg);
 }
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-2-1' - loleaflet/src wsd/DocumentBroker.cpp wsd/Storage.cpp wsd/Storage.hpp

2017-06-22 Thread Pranav Kant
 loleaflet/src/core/Socket.js |4 +
 wsd/DocumentBroker.cpp   |   18 ++-
 wsd/Storage.cpp  |  100 +++
 wsd/Storage.hpp  |7 +++
 4 files changed, 100 insertions(+), 29 deletions(-)

New commits:
commit 4f60d5d359ace0c2671ebc68524ba5db7db08e34
Author: Pranav Kant 
Date:   Wed May 31 23:18:33 2017 +0530

Inform all clients when document changed behind our back

Introduce a new header X-LOOL-WOPI-Timestamp

This is a WOPI header extension to detect any external document change. For
example, when the file that is already opened by LOOL is changed
in storage.

The WOPI host sends LastModifiedTime field (in WOPI specs) as part
of the CheckFileInfo response. It also expects wsd to send the
same timestamp in X-LOOL-WOPI-Timestamp header during WOPI::PutFile. If
this header is present, then WOPI host checks, before saving the
document, if the timestamp in the header is equal to the timestamp of
the file in its storage. Only upon meeting this condition, it saves the
file back to storage, otherwise it informs us about some change
to the document.

We are supposed to inform the user accordingly. If user is okay
with over-writing the document, then we can omit sending
X-LOOL-WOPI-Timestamp header, in which case, no check as mentioned above
would be performed while saving the file and document will be
overwritten.

Also, use a separate list of LOOL status codes to denote such a change.
It would be wrong to use HTTP_CONFLICT status code for denoting doc
changed in storage scenario. WOPI specs reserves that for WOPI locks
which are not yet implemented. Better to use a separate LOOL specific
status codes synced across WOPI hosts and us to denote scenario that we
expect and are not covered in WOPI specs.

(cherry picked from commit ba4e75cfae5eb174f8b56254f3c9513bab2afed5)

Change-Id: I61539dfae672bc104b8008f030f96e90f9ff48a5
Reviewed-on: https://gerrit.libreoffice.org/38527
Reviewed-by: Jan Holesovsky 
Tested-by: Jan Holesovsky 

diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index e137acca..894725aa 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -343,6 +343,10 @@ L.Socket = L.Class.extend({
this._map.hideBusy();
this.close();
}
+   else if (command.errorKind === 'documentconflict')
+   {
+   storageError = 
errorMessages.storage.documentconflict;
+   }
 
// Parse the storage url as link
var tmpLink = document.createElement('a');
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 138b9bb7..2157e191 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -492,8 +492,12 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 fileInfo._modifiedTime != Zero &&
 _documentLastModifiedTime != fileInfo._modifiedTime)
 {
-LOG_ERR("Document has been modified behind our back, URI [" << 
session->getPublicUri().toString() << "].");
-// What do do?
+LOG_WRN("Document [" << _docKey << "] has been modified behind our 
back. Informing all clients.");
+// Inform all clients
+for (const auto& sessionIt : _sessions)
+{
+sessionIt.second->sendTextFrame("error: cmd=storage 
kind=documentconflict");
+}
 }
 }
 
@@ -644,6 +648,16 @@ bool DocumentBroker::saveToStorageInternal(const 
std::string& sessionId,
 LOG_ERR("Failed to save docKey [" << _docKey << "] to URI [" << uri << 
"]. Notifying client.");
 it->second->sendTextFrame("error: cmd=storage kind=savefailed");
 }
+else if (storageSaveResult == StorageBase::SaveResult::DOC_CHANGED)
+{
+LOG_ERR("PutFile says that Document changed in storage");
+
+// Inform all clients
+for (const auto& sessionIt : _sessions)
+{
+sessionIt.second->sendTextFrame("error: cmd=storage 
kind=documentconflict");
+}
+}
 
 return false;
 }
diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp
index 5725c58e..aee09ae9 100644
--- a/wsd/Storage.cpp
+++ b/wsd/Storage.cpp
@@ -351,6 +351,27 @@ int getLevenshteinDist(const std::string& string1, const 
std::string& string2) {
 return matrix[string1.size()][string2.size()];
 }
 
+// Gets value for `key` directly from the given JSON in `object`
+template 
+T getJSONValue(const Poco::JSON::Object::Ptr , const std::string& key)
+{
+T value = T();
+try
+{
+const Poco::Dynamic::Var valueVar = object->get(key);
+value =