Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch "shared with me" information separately #7744

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 50 additions & 30 deletions src/gui/filedetails/sharemodel.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/gui/filedetails/sharemodel.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/gui/filedetails/sharemodel.cpp

File src/gui/filedetails/sharemodel.cpp does not conform to Custom style guidelines. (lines 494, 495, 559, 560, 561, 565, 566, 567, 574, 575, 576, 577)
* Copyright (C) 2022 by Claudio Cambra <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -363,6 +363,7 @@
if (_manager.isNull() && sharingPossible) {
_manager.reset(new ShareManager(_accountState->account(), this));
connect(_manager.data(), &ShareManager::sharesFetched, this, &ShareModel::slotSharesFetched);
connect(_manager.data(), &ShareManager::sharedWithMeFetched, this, &ShareModel::slotSharedWithMeFetched);
connect(_manager.data(), &ShareManager::shareCreated, this, [&] {
_manager->fetchShares(_sharePath);
});
Expand All @@ -375,6 +376,7 @@
});

_manager->fetchShares(_sharePath);
_manager->fetchSharedWithMe(_sharePath);
}
}

Expand Down Expand Up @@ -489,38 +491,13 @@
qCInfo(lcSharing) << "Fetched" << shares.count() << "shares";

for (const auto &share : shares) {
if (share.isNull()) {
if (share.isNull() ||
share->account().isNull() ||
share->getUidOwner() != share->account()->davUser()) {
continue;
} else if (const auto selfUserId = share->account()->davUser(); share->getUidOwner() != selfUserId) {
_displayShareOwner = true;
Q_EMIT displayShareOwnerChanged();
_shareOwnerDisplayName = share->getOwnerDisplayName();
Q_EMIT shareOwnerDisplayNameChanged();
_shareOwnerAvatar = "image://avatars/user-id="
+ share->getUidOwner()
+ "/local-account:"
+ share->account()->displayName();
Q_EMIT shareOwnerAvatarChanged();

if (share->getShareType() == Share::TypeUser &&
share->getShareWith() &&
share->getShareWith()->shareWith() == selfUserId)
{
const auto userShare = share.objectCast<UserGroupShare>();
const auto expireDate = userShare->getExpireDate();
const auto daysToExpire = QDate::currentDate().daysTo(expireDate);
_sharedWithMeExpires = expireDate.isValid();
Q_EMIT sharedWithMeExpiresChanged();
_sharedWithMeRemainingTimeString = daysToExpire > 1
? tr("%1 days").arg(daysToExpire)
: daysToExpire > 0
? tr("1 day")
: tr("Today");
Q_EMIT sharedWithMeRemainingTimeStringChanged();
}
} else {
slotAddShare(share);
}

slotAddShare(share);
}

// Perform forward pass on shares and check for duplicate display names; store these indeces so
Expand Down Expand Up @@ -561,7 +538,50 @@
handleLinkShare();
}

void ShareModel::slotSharedWithMeFetched(const QList<OCC::SharePtr> &shares)
{
qCInfo(lcSharing) << "Fetched" << shares.count() << "shares that have been shared_with_me";

for (const auto &share : shares) {
if (share.isNull()) {
continue;
}

const auto selfUserId = share->account()->davUser();
if (share->getUidOwner() == selfUserId) {
continue;
}

_displayShareOwner = true;
Q_EMIT displayShareOwnerChanged();
_shareOwnerDisplayName = share->getOwnerDisplayName();
Q_EMIT shareOwnerDisplayNameChanged();
_shareOwnerAvatar = "image://avatars/user-id="
+ share->getUidOwner()
+ "/local-account:"
+ share->account()->displayName();
Q_EMIT shareOwnerAvatarChanged();

if (share->getShareType() == Share::TypeUser &&
share->getShareWith() &&
share->getShareWith()->shareWith() == selfUserId)
{
const auto userShare = share.objectCast<UserGroupShare>();
const auto expireDate = userShare->getExpireDate();
const auto daysToExpire = QDate::currentDate().daysTo(expireDate);
_sharedWithMeExpires = expireDate.isValid();
Q_EMIT sharedWithMeExpiresChanged();
_sharedWithMeRemainingTimeString = daysToExpire > 1
? tr("%1 days").arg(daysToExpire)
: daysToExpire > 0
? tr("1 day")
: tr("Today");
Q_EMIT sharedWithMeRemainingTimeStringChanged();
}
}
}

void ShareModel::setupInternalLinkShare()

Check warning on line 584 in src/gui/filedetails/sharemodel.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/filedetails/sharemodel.cpp:584:18 [readability-convert-member-functions-to-static]

method 'setupInternalLinkShare' can be made static
{
if (!_accountState ||
_accountState->account().isNull() ||
Expand Down
1 change: 1 addition & 0 deletions src/gui/filedetails/sharemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#pragma once

#include <QAbstractListModel>

Check failure on line 17 in src/gui/filedetails/sharemodel.h

View workflow job for this annotation

GitHub Actions / build

src/gui/filedetails/sharemodel.h:17:10 [clang-diagnostic-error]

'QAbstractListModel' file not found

#include "accountstate.h"
#include "folder.h"
Expand Down Expand Up @@ -220,6 +220,7 @@
void slotAddShare(const OCC::SharePtr &share);
void slotRemoveShareWithId(const QString &shareId);
void slotSharesFetched(const QList<OCC::SharePtr> &shares);
void slotSharedWithMeFetched(const QList<OCC::SharePtr> &shares);
void slotAddSharee(const OCC::ShareePtr &sharee);
void slotRemoveSharee(const OCC::ShareePtr &sharee);

Expand Down
8 changes: 5 additions & 3 deletions src/gui/ocssharejob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

addParam(QString::fromLatin1("path"), path);
addParam(QString::fromLatin1("reshares"), QString("true"));
addParam(QString::fromLatin1("shared_with_me"), QString("true"));

for (auto it = std::cbegin(params); it != std::cend(params); ++it) {
addParam(it.key(), it.value());
Expand Down Expand Up @@ -208,10 +207,13 @@
start();
}

void OcsShareJob::getSharedWithMe()
void OcsShareJob::getSharedWithMe(const QString &path)

Check warning on line 210 in src/gui/ocssharejob.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/ocssharejob.cpp:210:19 [readability-convert-member-functions-to-static]

method 'getSharedWithMe' can be made static
{
setVerb("GET");
addParam(QLatin1String("shared_with_me"), QLatin1String("true"));

addParam(QString::fromLatin1("path"), path);
addParam(QString::fromLatin1("shared_with_me"), QString("true"));

start();
}

Expand Down
3 changes: 2 additions & 1 deletion src/gui/ocssharejob.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ class OcsShareJob : public OcsJob

/**
* Returns information on the items shared with the current user.
* @param path Path to request shares for (default all shares)
*/
void getSharedWithMe();
void getSharedWithMe(const QString &path = "");

static const QString _pathForSharesRequest;

Expand Down
28 changes: 24 additions & 4 deletions src/gui/sharemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,21 @@ void ShareManager::slotShareCreated(const QJsonDocument &reply)

void ShareManager::fetchShares(const QString &path)
{
auto *job = new OcsShareJob(_account);
auto job = new OcsShareJob(_account);
connect(job, &OcsShareJob::shareJobFinished, this, &ShareManager::slotSharesFetched);
connect(job, &OcsJob::ocsError, this, &ShareManager::slotOcsError);
job->getShares(path);
}

void ShareManager::slotSharesFetched(const QJsonDocument &reply)
void ShareManager::fetchSharedWithMe(const QString &path)
{
auto sharedWithMeJob = new OcsShareJob(_account);
connect(sharedWithMeJob, &OcsShareJob::shareJobFinished, this, &ShareManager::slotSharedWithMeFetched);
connect(sharedWithMeJob, &OcsJob::ocsError, this, &ShareManager::slotOcsError);
sharedWithMeJob->getSharedWithMe(path);
}

const QList<SharePtr> ShareManager::parseShares(const QJsonDocument &reply) const
{
qDebug() << reply;
auto tmpShares = reply.object().value("ocs").toObject().value("data").toArray();
Expand Down Expand Up @@ -570,10 +578,22 @@ void ShareManager::slotSharesFetched(const QJsonDocument &reply)
}

qCDebug(lcSharing) << "Sending " << shares.count() << "shares";
return shares;
}

void ShareManager::slotSharesFetched(const QJsonDocument &reply)
{
auto shares = parseShares(reply);
emit sharesFetched(shares);
}

QSharedPointer<UserGroupShare> ShareManager::parseUserGroupShare(const QJsonObject &data)
void ShareManager::slotSharedWithMeFetched(const QJsonDocument &reply)
{
auto shares = parseShares(reply);
emit sharedWithMeFetched(shares);
}

QSharedPointer<UserGroupShare> ShareManager::parseUserGroupShare(const QJsonObject &data) const
{
ShareePtr sharee(new Sharee(data.value("share_with").toString(),
data.value("share_with_displayname").toString(),
Expand Down Expand Up @@ -602,7 +622,7 @@ QSharedPointer<UserGroupShare> ShareManager::parseUserGroupShare(const QJsonObje
note));
}

QSharedPointer<LinkShare> ShareManager::parseLinkShare(const QJsonObject &data)
QSharedPointer<LinkShare> ShareManager::parseLinkShare(const QJsonObject &data) const
{
QUrl url;

Expand Down
17 changes: 15 additions & 2 deletions src/gui/sharemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef SHAREMANAGER_H
#define SHAREMANAGER_H

#include "accountfwd.h"

Check failure on line 18 in src/gui/sharemanager.h

View workflow job for this annotation

GitHub Actions / build

src/gui/sharemanager.h:18:10 [clang-diagnostic-error]

'accountfwd.h' file not found
#include "sharee.h"
#include "sharepermissions.h"

Expand Down Expand Up @@ -440,10 +440,21 @@
*/
void fetchShares(const QString &path);

/**
* Fetch shares with the current user for path
*
* @param path The path to get the shares for relative to the users folder on the server
*
* On success the sharedWithMeFetched signal is emitted
* In case of a server error the serverError signal is emitted
*/
void fetchSharedWithMe(const QString &path);

signals:
void shareCreated(const OCC::SharePtr &share);
void linkShareCreated(const QSharedPointer<OCC::LinkShare> &share);
void sharesFetched(const QList<OCC::SharePtr> &shares);
void sharedWithMeFetched(const QList<OCC::SharePtr> &shares);
void serverError(int code, const QString &message);

/** Emitted when creating a link share with password fails.
Expand All @@ -456,15 +467,17 @@

private slots:
void slotSharesFetched(const QJsonDocument &reply);
void slotSharedWithMeFetched(const QJsonDocument &reply);
void slotLinkShareCreated(const QJsonDocument &reply);
void slotShareCreated(const QJsonDocument &reply);
void slotOcsError(int statusCode, const QString &message);
void slotCreateE2eeShareJobFinised(int statusCode, const QString &message);

private:
QSharedPointer<LinkShare> parseLinkShare(const QJsonObject &data);
QSharedPointer<UserGroupShare> parseUserGroupShare(const QJsonObject &data);
QSharedPointer<LinkShare> parseLinkShare(const QJsonObject &data) const;
QSharedPointer<UserGroupShare> parseUserGroupShare(const QJsonObject &data) const;
SharePtr parseShare(const QJsonObject &data) const;
const QList<OCC::SharePtr> parseShares(const QJsonDocument &reply) const;

AccountPtr _account;
};
Expand Down
Loading