Skip to content

Commit

Permalink
Do not try to (repeatedly) fetch profile pictures when not available
Browse files Browse the repository at this point in the history
The server has a capability to indicate that profile pictures (avatars)
are not available. Previously, the client would try to fetch them no
matter what, and even retry when the server responded with a 404. Now
we take the server capability into account, and do not try to fetch
those when not available.

Fixes: #8758
  • Loading branch information
erikjv committed Oct 6, 2021
1 parent 934d2aa commit ba3cd71
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
24 changes: 18 additions & 6 deletions src/gui/connectionvalidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,25 @@ void ConnectionValidator::slotUserFetched(const QJsonDocument &json)
if (!displayName.isEmpty()) {
_account->setDavDisplayName(displayName);
}

auto capabilities = _account->capabilities();
// We should have received the capabilities by now. Check that assumption in a debug build. If
// it's not the case, the code below will assume that they are not available.
Q_ASSERT(capabilities.isValid());

// Ugh, #ifdefs are gross.
#ifndef TOKEN_AUTH_ONLY
AvatarJob *job = new AvatarJob(_account, _account->davUser(), 128, this);
job->setTimeout(20 * 1000);
QObject::connect(job, &AvatarJob::avatarPixmap, this, &ConnectionValidator::slotAvatarImage);
job->start();
#else
reportResult(Connected);
if (capabilities.isValid() && capabilities.avatarsAvailable()) {
AvatarJob *job = new AvatarJob(_account, _account->davUser(), 128, this);
job->setTimeout(20 * 1000);
QObject::connect(job, &AvatarJob::avatarPixmap, this, &ConnectionValidator::slotAvatarImage);
job->start();
// reportResult will be called when the avatar has been received by `slotAvatarImage`
} else {
#endif
reportResult(Connected);
#ifndef TOKEN_AUTH_ONLY
}
#endif
}

Expand Down
10 changes: 7 additions & 3 deletions src/gui/shareusergroupwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,13 @@ void ShareUserLine::loadAvatar()
* Currently only regular users can have avatars.
*/
if (_share->getShareWith()->type() == Sharee::User) {
AvatarJob *job = new AvatarJob(_share->account(), _share->getShareWith()->shareWith(), avatarSize, this);
connect(job, &AvatarJob::avatarPixmap, this, &ShareUserLine::slotAvatarLoaded);
job->start();
auto account = _share->account();
auto capabilities = account->capabilities();
if (capabilities.isValid() && capabilities.avatarsAvailable()) {
AvatarJob *job = new AvatarJob(account, _share->getShareWith()->shareWith(), avatarSize, this);
connect(job, &AvatarJob::avatarPixmap, this, &ShareUserLine::slotAvatarLoaded);
job->start();
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/libsync/capabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ bool Capabilities::versioningEnabled() const
return _capabilities.value(QStringLiteral("files")).toMap().value(QStringLiteral("versioning")).toBool();
}

bool Capabilities::avatarsAvailable() const
{
// true by default for older servers, because turning off profile pictures was introduced in later versions
return _fileSharingPublicCapabilities.value(QStringLiteral("profile_picture"), true).toBool();
}

QStringList Capabilities::blacklistedFiles() const
{
return _capabilities.value(QStringLiteral("files")).toMap().value(QStringLiteral("blacklisted_files")).toStringList();
Expand All @@ -243,4 +249,5 @@ bool TusSupport::isValid() const
{
return !version.isNull();
}
}

} // namespace OCC
3 changes: 3 additions & 0 deletions src/libsync/capabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ class OWNCLOUDSYNC_EXPORT Capabilities
/** Is versioning available? */
bool versioningEnabled() const;

/** Are avatars (profile pictures) available? */
bool avatarsAvailable() const;

private:
QVariantMap _capabilities;
QVariantMap _fileSharingCapabilities;
Expand Down

0 comments on commit ba3cd71

Please sign in to comment.