Skip to content

Commit b1066a2

Browse files
committed
fetch "shared with me" information separately
if the parameter `shared_with_me` is set to `"true"` on the shares API call the response will only include that and not return any other sharing information. therefore let's fetch it inside another job (this is also how the web client does it). Signed-off-by: Jyrki Gadinger <[email protected]>
1 parent 2c9bc0c commit b1066a2

File tree

6 files changed

+97
-40
lines changed

6 files changed

+97
-40
lines changed

src/gui/filedetails/sharemodel.cpp

+50-30
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ void ShareModel::initShareManager()
363363
if (_manager.isNull() && sharingPossible) {
364364
_manager.reset(new ShareManager(_accountState->account(), this));
365365
connect(_manager.data(), &ShareManager::sharesFetched, this, &ShareModel::slotSharesFetched);
366+
connect(_manager.data(), &ShareManager::sharedWithMeFetched, this, &ShareModel::slotSharedWithMeFetched);
366367
connect(_manager.data(), &ShareManager::shareCreated, this, [&] {
367368
_manager->fetchShares(_sharePath);
368369
});
@@ -375,6 +376,7 @@ void ShareModel::initShareManager()
375376
});
376377

377378
_manager->fetchShares(_sharePath);
379+
_manager->fetchSharedWithMe(_sharePath);
378380
}
379381
}
380382

@@ -489,38 +491,13 @@ void ShareModel::slotSharesFetched(const QList<SharePtr> &shares)
489491
qCInfo(lcSharing) << "Fetched" << shares.count() << "shares";
490492

491493
for (const auto &share : shares) {
492-
if (share.isNull()) {
494+
if (share.isNull() ||
495+
share->account().isNull() ||
496+
share->getUidOwner() != share->account()->davUser()) {
493497
continue;
494-
} else if (const auto selfUserId = share->account()->davUser(); share->getUidOwner() != selfUserId) {
495-
_displayShareOwner = true;
496-
Q_EMIT displayShareOwnerChanged();
497-
_shareOwnerDisplayName = share->getOwnerDisplayName();
498-
Q_EMIT shareOwnerDisplayNameChanged();
499-
_shareOwnerAvatar = "image://avatars/user-id="
500-
+ share->getUidOwner()
501-
+ "/local-account:"
502-
+ share->account()->displayName();
503-
Q_EMIT shareOwnerAvatarChanged();
504-
505-
if (share->getShareType() == Share::TypeUser &&
506-
share->getShareWith() &&
507-
share->getShareWith()->shareWith() == selfUserId)
508-
{
509-
const auto userShare = share.objectCast<UserGroupShare>();
510-
const auto expireDate = userShare->getExpireDate();
511-
const auto daysToExpire = QDate::currentDate().daysTo(expireDate);
512-
_sharedWithMeExpires = expireDate.isValid();
513-
Q_EMIT sharedWithMeExpiresChanged();
514-
_sharedWithMeRemainingTimeString = daysToExpire > 1
515-
? tr("%1 days").arg(daysToExpire)
516-
: daysToExpire > 0
517-
? tr("1 day")
518-
: tr("Today");
519-
Q_EMIT sharedWithMeRemainingTimeStringChanged();
520-
}
521-
} else {
522-
slotAddShare(share);
523498
}
499+
500+
slotAddShare(share);
524501
}
525502

526503
// Perform forward pass on shares and check for duplicate display names; store these indeces so
@@ -561,6 +538,49 @@ void ShareModel::slotSharesFetched(const QList<SharePtr> &shares)
561538
handleLinkShare();
562539
}
563540

541+
void ShareModel::slotSharedWithMeFetched(const QList<OCC::SharePtr> &shares)
542+
{
543+
qCInfo(lcSharing) << "Fetched" << shares.count() << "shares that have been shared_with_me";
544+
545+
for (const auto &share : shares) {
546+
if (share.isNull()) {
547+
continue;
548+
}
549+
550+
const auto selfUserId = share->account()->davUser();
551+
if (share->getUidOwner() == selfUserId) {
552+
continue;
553+
}
554+
555+
_displayShareOwner = true;
556+
Q_EMIT displayShareOwnerChanged();
557+
_shareOwnerDisplayName = share->getOwnerDisplayName();
558+
Q_EMIT shareOwnerDisplayNameChanged();
559+
_shareOwnerAvatar = "image://avatars/user-id="
560+
+ share->getUidOwner()
561+
+ "/local-account:"
562+
+ share->account()->displayName();
563+
Q_EMIT shareOwnerAvatarChanged();
564+
565+
if (share->getShareType() == Share::TypeUser &&
566+
share->getShareWith() &&
567+
share->getShareWith()->shareWith() == selfUserId)
568+
{
569+
const auto userShare = share.objectCast<UserGroupShare>();
570+
const auto expireDate = userShare->getExpireDate();
571+
const auto daysToExpire = QDate::currentDate().daysTo(expireDate);
572+
_sharedWithMeExpires = expireDate.isValid();
573+
Q_EMIT sharedWithMeExpiresChanged();
574+
_sharedWithMeRemainingTimeString = daysToExpire > 1
575+
? tr("%1 days").arg(daysToExpire)
576+
: daysToExpire > 0
577+
? tr("1 day")
578+
: tr("Today");
579+
Q_EMIT sharedWithMeRemainingTimeStringChanged();
580+
}
581+
}
582+
}
583+
564584
void ShareModel::setupInternalLinkShare()
565585
{
566586
if (!_accountState ||

src/gui/filedetails/sharemodel.h

+1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ private slots:
220220
void slotAddShare(const OCC::SharePtr &share);
221221
void slotRemoveShareWithId(const QString &shareId);
222222
void slotSharesFetched(const QList<OCC::SharePtr> &shares);
223+
void slotSharedWithMeFetched(const QList<OCC::SharePtr> &shares);
223224
void slotAddSharee(const OCC::ShareePtr &sharee);
224225
void slotRemoveSharee(const OCC::ShareePtr &sharee);
225226

src/gui/ocssharejob.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ void OcsShareJob::getShares(const QString &path, const QMap<QString, QString> &p
3434

3535
addParam(QString::fromLatin1("path"), path);
3636
addParam(QString::fromLatin1("reshares"), QString("true"));
37-
addParam(QString::fromLatin1("shared_with_me"), QString("true"));
3837

3938
for (auto it = std::cbegin(params); it != std::cend(params); ++it) {
4039
addParam(it.key(), it.value());
@@ -208,10 +207,13 @@ void OcsShareJob::createShare(const QString &path,
208207
start();
209208
}
210209

211-
void OcsShareJob::getSharedWithMe()
210+
void OcsShareJob::getSharedWithMe(const QString &path)
212211
{
213212
setVerb("GET");
214-
addParam(QLatin1String("shared_with_me"), QLatin1String("true"));
213+
214+
addParam(QString::fromLatin1("path"), path);
215+
addParam(QString::fromLatin1("shared_with_me"), QString("true"));
216+
215217
start();
216218
}
217219

src/gui/ocssharejob.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ class OcsShareJob : public OcsJob
135135

136136
/**
137137
* Returns information on the items shared with the current user.
138+
* @param path Path to request shares for (default all shares)
138139
*/
139-
void getSharedWithMe();
140+
void getSharedWithMe(const QString &path = "");
140141

141142
static const QString _pathForSharesRequest;
142143

src/gui/sharemanager.cpp

+24-4
Original file line numberDiff line numberDiff line change
@@ -536,13 +536,21 @@ void ShareManager::slotShareCreated(const QJsonDocument &reply)
536536

537537
void ShareManager::fetchShares(const QString &path)
538538
{
539-
auto *job = new OcsShareJob(_account);
539+
const auto job = new OcsShareJob(_account);
540540
connect(job, &OcsShareJob::shareJobFinished, this, &ShareManager::slotSharesFetched);
541541
connect(job, &OcsJob::ocsError, this, &ShareManager::slotOcsError);
542542
job->getShares(path);
543543
}
544544

545-
void ShareManager::slotSharesFetched(const QJsonDocument &reply)
545+
void ShareManager::fetchSharedWithMe(const QString &path)
546+
{
547+
const auto sharedWithMeJob = new OcsShareJob(_account);
548+
connect(sharedWithMeJob, &OcsShareJob::shareJobFinished, this, &ShareManager::slotSharedWithMeFetched);
549+
connect(sharedWithMeJob, &OcsJob::ocsError, this, &ShareManager::slotOcsError);
550+
sharedWithMeJob->getSharedWithMe(path);
551+
}
552+
553+
const QList<SharePtr> ShareManager::parseShares(const QJsonDocument &reply) const
546554
{
547555
qDebug() << reply;
548556
auto tmpShares = reply.object().value("ocs").toObject().value("data").toArray();
@@ -570,10 +578,22 @@ void ShareManager::slotSharesFetched(const QJsonDocument &reply)
570578
}
571579

572580
qCDebug(lcSharing) << "Sending " << shares.count() << "shares";
581+
return shares;
582+
}
583+
584+
void ShareManager::slotSharesFetched(const QJsonDocument &reply)
585+
{
586+
auto shares = parseShares(reply);
573587
emit sharesFetched(shares);
574588
}
575589

576-
QSharedPointer<UserGroupShare> ShareManager::parseUserGroupShare(const QJsonObject &data)
590+
void ShareManager::slotSharedWithMeFetched(const QJsonDocument &reply)
591+
{
592+
auto shares = parseShares(reply);
593+
emit sharedWithMeFetched(shares);
594+
}
595+
596+
QSharedPointer<UserGroupShare> ShareManager::parseUserGroupShare(const QJsonObject &data) const
577597
{
578598
ShareePtr sharee(new Sharee(data.value("share_with").toString(),
579599
data.value("share_with_displayname").toString(),
@@ -602,7 +622,7 @@ QSharedPointer<UserGroupShare> ShareManager::parseUserGroupShare(const QJsonObje
602622
note));
603623
}
604624

605-
QSharedPointer<LinkShare> ShareManager::parseLinkShare(const QJsonObject &data)
625+
QSharedPointer<LinkShare> ShareManager::parseLinkShare(const QJsonObject &data) const
606626
{
607627
QUrl url;
608628

src/gui/sharemanager.h

+15-2
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,21 @@ class ShareManager : public QObject
440440
*/
441441
void fetchShares(const QString &path);
442442

443+
/**
444+
* Fetch shares with the current user for path
445+
*
446+
* @param path The path to get the shares for relative to the users folder on the server
447+
*
448+
* On success the sharedWithMeFetched signal is emitted
449+
* In case of a server error the serverError signal is emitted
450+
*/
451+
void fetchSharedWithMe(const QString &path);
452+
443453
signals:
444454
void shareCreated(const OCC::SharePtr &share);
445455
void linkShareCreated(const QSharedPointer<OCC::LinkShare> &share);
446456
void sharesFetched(const QList<OCC::SharePtr> &shares);
457+
void sharedWithMeFetched(const QList<OCC::SharePtr> &shares);
447458
void serverError(int code, const QString &message);
448459

449460
/** Emitted when creating a link share with password fails.
@@ -456,15 +467,17 @@ class ShareManager : public QObject
456467

457468
private slots:
458469
void slotSharesFetched(const QJsonDocument &reply);
470+
void slotSharedWithMeFetched(const QJsonDocument &reply);
459471
void slotLinkShareCreated(const QJsonDocument &reply);
460472
void slotShareCreated(const QJsonDocument &reply);
461473
void slotOcsError(int statusCode, const QString &message);
462474
void slotCreateE2eeShareJobFinised(int statusCode, const QString &message);
463475

464476
private:
465-
QSharedPointer<LinkShare> parseLinkShare(const QJsonObject &data);
466-
QSharedPointer<UserGroupShare> parseUserGroupShare(const QJsonObject &data);
477+
QSharedPointer<LinkShare> parseLinkShare(const QJsonObject &data) const;
478+
QSharedPointer<UserGroupShare> parseUserGroupShare(const QJsonObject &data) const;
467479
SharePtr parseShare(const QJsonObject &data) const;
480+
const QList<OCC::SharePtr> parseShares(const QJsonDocument &reply) const;
468481

469482
AccountPtr _account;
470483
};

0 commit comments

Comments
 (0)