wsd: session is optional to broadcasting doc modification time
The current session is needed only while loading, as it's not yet in the sessions container. But while saving, broadcasting to all sessions includes the current session as well, and we avoid sending duplicate message to the current session. We also make the broadcast helper a member of DocumentBroker which simplifies it. Change-Id: I3bb37cc808d97ba2b772b88474a8c10f7fdff6b7 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
This commit is contained in:
parent
06a45e6db9
commit
0d3a8f77d3
2 changed files with 17 additions and 20 deletions
|
@ -64,28 +64,22 @@ void ChildProcess::setDocumentBroker(const std::shared_ptr<DocumentBroker>& docB
|
|||
docBroker->addSocketToPoll(getSocket());
|
||||
}
|
||||
|
||||
namespace
|
||||
void DocumentBroker::broadcastLastModificationTime(
|
||||
const std::shared_ptr<ClientSession>& session) const
|
||||
{
|
||||
|
||||
void sendLastModificationTime(const std::shared_ptr<Session>& 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<ClientSession>& 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();
|
||||
|
||||
|
|
|
@ -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<ClientSession>& session = nullptr) const;
|
||||
|
||||
/// True iff a save is in progress (requested but not completed).
|
||||
bool isSaving() const { return _lastSaveResponseTime < _lastSaveRequestTime; }
|
||||
|
||||
|
|
Loading…
Reference in a new issue