diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index 13b4999f0..e906b3582 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -64,28 +64,22 @@ void ChildProcess::setDocumentBroker(const std::shared_ptr& docB docBroker->addSocketToPoll(getSocket()); } -namespace +void DocumentBroker::broadcastLastModificationTime( + const std::shared_ptr& session) const { - -void sendLastModificationTime(const std::shared_ptr& session, - DocumentBroker* documentBroker, - const std::chrono::system_clock::time_point& documentLastModifiedTime) -{ - if (!session) - return; - - if (documentLastModifiedTime == std::chrono::system_clock::time_point()) + if (_documentLastModifiedTime == std::chrono::system_clock::time_point()) // No time from the storage (e.g., SharePoint 2013 and 2016) -> don't send return; - std::stringstream stream; - stream << "lastmodtime: " << documentLastModifiedTime; + std::ostringstream stream; + stream << "lastmodtime: " << _documentLastModifiedTime; const std::string message = stream.str(); - session->sendTextFrame(message); - if (documentBroker) - documentBroker->broadcastMessage(message); -} + // While loading, the current session is not yet added to + // the sessions container, so we need to send to it directly. + if (session) + session->sendTextFrame(message); + broadcastMessage(message); } Poco::URI DocumentBroker::sanitizeURI(const std::string& uri) @@ -791,7 +785,7 @@ bool DocumentBroker::load(const std::shared_ptr& session, const s } } - sendLastModificationTime(session, this, _documentLastModifiedTime); + broadcastLastModificationTime(session); // Let's load the document now, if not loaded. if (!_storage->isLoaded()) @@ -1141,7 +1135,7 @@ bool DocumentBroker::saveToStorageInternal(const std::string& sessionId, bool su "] with name [" << filenameAnonym << "] successfully."); } - sendLastModificationTime(it->second, this, _documentLastModifiedTime); + broadcastLastModificationTime(); return true; } @@ -2341,7 +2335,7 @@ void DocumentBroker::closeDocument(const std::string& reason) _closeRequest = true; } -void DocumentBroker::broadcastMessage(const std::string& message) +void DocumentBroker::broadcastMessage(const std::string& message) const { assertCorrectThread(); diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp index 216e144e1..5e279ce38 100644 --- a/wsd/DocumentBroker.hpp +++ b/wsd/DocumentBroker.hpp @@ -286,7 +286,7 @@ public: bool isExitSave = false, const std::string& extendedData = std::string()); /// Sends a message to all sessions - void broadcastMessage(const std::string& message); + void broadcastMessage(const std::string& message) const; /// Returns true iff an initial setting by the given name is already initialized. bool isInitialSettingSet(const std::string& name) const; @@ -356,6 +356,9 @@ private: */ void broadcastSaveResult(bool success, const std::string& result = "", const std::string& errorMsg = ""); + /// Broadcasts to all sessions the last modification time of the document. + void broadcastLastModificationTime(const std::shared_ptr& session = nullptr) const; + /// True iff a save is in progress (requested but not completed). bool isSaving() const { return _lastSaveResponseTime < _lastSaveRequestTime; }