Add ability to fetch remote server avatars in usermodel avatar ImageResponse

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2024-10-21 01:46:56 +08:00
parent 896e61ae04
commit d479c13ac7
No known key found for this signature in database
GPG key ID: C839200C384636B0

View file

@ -1637,6 +1637,25 @@ public:
return;
}
if (id.startsWith("user-id=")) {
// Format is "image://avatars/user-id=avatar-requested-user/local-user-id:0"
const auto userIdsString = id.split('=');
const auto userIds = userIdsString.last().split("/local-account:");
const auto avatarUserId = userIds.first();
const auto accountString = userIds.last();
const auto accountState = AccountManager::instance()->account(accountString);
Q_ASSERT(accountState);
if (!accountState) {
qCWarning(lcActivity) << "Account not found:" << accountString;
return;
}
const auto avatarJob = new AvatarJob(accountState->account(), avatarUserId, requestedSize.width());
connect(avatarJob, &AvatarJob::avatarPixmap, this, [&](const QImage &avatarImg) {
handleDone(AvatarJob::makeCircularAvatar(avatarImg));
});
avatarJob->start();
return;
}
handleDone(UserModel::instance()->avatarById(id.toInt()));
}