From d479c13ac7ab6942675a7c21b1e29688fe3d8a06 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 21 Oct 2024 01:46:56 +0800 Subject: [PATCH] Add ability to fetch remote server avatars in usermodel avatar ImageResponse Signed-off-by: Claudio Cambra --- src/gui/tray/usermodel.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/gui/tray/usermodel.cpp b/src/gui/tray/usermodel.cpp index 4c8a7eb49..a6013fb7c 100644 --- a/src/gui/tray/usermodel.cpp +++ b/src/gui/tray/usermodel.cpp @@ -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())); }