|
|
@@ -491,23 +491,70 @@ void SocketApi::command_SHARE_MENU_TITLE(const QString &, SocketListener *listen
|
|
|
listener->sendMessage(QLatin1String("SHARE_MENU_TITLE:") + tr("Share with %1", "parameter is ownCloud").arg(Theme::instance()->appNameGUI()));
|
|
|
}
|
|
|
|
|
|
-void SocketApi::command_COPY_PRIVATE_LINK(const QString &localFile, SocketListener *)
|
|
|
+// Fetches the private link url asynchronously and then calls the target slot
|
|
|
+void fetchPrivateLinkUrl(const QString &localFile, SocketApi *target, void (SocketApi::*targetFun)(const QString &url) const)
|
|
|
{
|
|
|
- auto url = getPrivateLinkUrl(localFile);
|
|
|
- if (!url.isEmpty()) {
|
|
|
- QApplication::clipboard()->setText(url.toString());
|
|
|
+ Folder *shareFolder = FolderMan::instance()->folderForPath(localFile);
|
|
|
+ if (!shareFolder) {
|
|
|
+ qCWarning(lcSocketApi) << "Unknown path" << localFile;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const QString localFileClean = QDir::cleanPath(localFile);
|
|
|
+ const QString file = localFileClean.mid(shareFolder->cleanPath().length() + 1);
|
|
|
+
|
|
|
+ // Generate private link ourselves: used as a fallback
|
|
|
+ const SyncJournalFileRecord rec = shareFolder->journalDb()->getFileRecord(file);
|
|
|
+ if (!rec.isValid())
|
|
|
+ return;
|
|
|
+ const QString oldUrl =
|
|
|
+ shareFolder->accountState()->account()->deprecatedPrivateLinkUrl(rec.numericFileId()).toString(QUrl::FullyEncoded);
|
|
|
+
|
|
|
+ // If the server doesn't have the property, use the old url directly.
|
|
|
+ if (!shareFolder->accountState()->account()->capabilities().privateLinkPropertyAvailable()) {
|
|
|
+ (target->*targetFun)(oldUrl);
|
|
|
+ return;
|
|
|
}
|
|
|
+
|
|
|
+ // Retrieve the new link by PROPFIND
|
|
|
+ PropfindJob *job = new PropfindJob(shareFolder->accountState()->account(), file, target);
|
|
|
+ job->setProperties(QList<QByteArray>() << "http://owncloud.org/ns:privatelink");
|
|
|
+ job->setTimeout(10 * 1000);
|
|
|
+ QObject::connect(job, &PropfindJob::result, target, [=](const QVariantMap &result) {
|
|
|
+ auto privateLinkUrl = result["privatelink"].toString();
|
|
|
+ if (!privateLinkUrl.isEmpty()) {
|
|
|
+ (target->*targetFun)(privateLinkUrl);
|
|
|
+ } else {
|
|
|
+ (target->*targetFun)(oldUrl);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ QObject::connect(job, &PropfindJob::finishedWithError, target, [=](QNetworkReply *) {
|
|
|
+ (target->*targetFun)(oldUrl);
|
|
|
+ });
|
|
|
+ job->start();
|
|
|
+}
|
|
|
+
|
|
|
+void SocketApi::command_COPY_PRIVATE_LINK(const QString &localFile, SocketListener *)
|
|
|
+{
|
|
|
+ fetchPrivateLinkUrl(localFile, this, &SocketApi::copyPrivateLinkToClipboard);
|
|
|
}
|
|
|
|
|
|
void SocketApi::command_EMAIL_PRIVATE_LINK(const QString &localFile, SocketListener *)
|
|
|
{
|
|
|
- auto url = getPrivateLinkUrl(localFile);
|
|
|
- if (!url.isEmpty()) {
|
|
|
- Utility::openEmailComposer(
|
|
|
- tr("I shared something with you"),
|
|
|
- url.toString(QUrl::FullyEncoded),
|
|
|
- 0);
|
|
|
- }
|
|
|
+ fetchPrivateLinkUrl(localFile, this, &SocketApi::emailPrivateLink);
|
|
|
+}
|
|
|
+
|
|
|
+void SocketApi::copyPrivateLinkToClipboard(const QString &link) const
|
|
|
+{
|
|
|
+ QApplication::clipboard()->setText(link);
|
|
|
+}
|
|
|
+
|
|
|
+void SocketApi::emailPrivateLink(const QString &link) const
|
|
|
+{
|
|
|
+ Utility::openEmailComposer(
|
|
|
+ tr("I shared something with you"),
|
|
|
+ link,
|
|
|
+ 0);
|
|
|
}
|
|
|
|
|
|
void SocketApi::command_GET_STRINGS(const QString &, SocketListener *listener)
|
|
|
@@ -533,22 +580,4 @@ QString SocketApi::buildRegisterPathMessage(const QString &path)
|
|
|
return message;
|
|
|
}
|
|
|
|
|
|
-QUrl SocketApi::getPrivateLinkUrl(const QString &localFile) const
|
|
|
-{
|
|
|
- Folder *shareFolder = FolderMan::instance()->folderForPath(localFile);
|
|
|
- if (!shareFolder) {
|
|
|
- qCWarning(lcSocketApi) << "Unknown path" << localFile;
|
|
|
- return QUrl();
|
|
|
- }
|
|
|
-
|
|
|
- const QString localFileClean = QDir::cleanPath(localFile);
|
|
|
- const QString file = localFileClean.mid(shareFolder->cleanPath().length() + 1);
|
|
|
-
|
|
|
- SyncJournalFileRecord rec = shareFolder->journalDb()->getFileRecord(file);
|
|
|
- if (rec.isValid()) {
|
|
|
- return shareFolder->accountState()->account()->filePermalinkUrl(rec.numericFileId());
|
|
|
- }
|
|
|
- return QUrl();
|
|
|
-}
|
|
|
-
|
|
|
} // namespace OCC
|