summary refs log tree commit diff
path: root/src/InviteesModel.cpp
diff options
context:
space:
mode:
authorMalte E <97891689+maltee1@users.noreply.github.com>2023-02-01 00:59:49 +0800
committerGitHub <noreply@github.com>2023-01-31 16:59:49 +0000
commit5ed3bfc8f82e9123db4c198b6b9701df57c968f4 (patch)
tree9cb27ca2ed00830dba9d8adcc780d1b5296dd7cc /src/InviteesModel.cpp
parentMerge pull request #1319 from Decodetalkers/menuhideonwayland (diff)
downloadnheko-5ed3bfc8f82e9123db4c198b6b9701df57c968f4.tar.xz
add user search to invite dialog (#1253)
Diffstat (limited to '')
-rw-r--r--src/InviteesModel.cpp37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/InviteesModel.cpp b/src/InviteesModel.cpp

index 52dd4e43..cf78d63e 100644 --- a/src/InviteesModel.cpp +++ b/src/InviteesModel.cpp
@@ -17,7 +17,7 @@ InviteesModel::InviteesModel(QObject *parent) } void -InviteesModel::addUser(QString mxid) +InviteesModel::addUser(QString mxid, QString displayName, QString avatarUrl) { for (const auto &invitee : qAsConst(invitees_)) if (invitee->mxid_ == mxid) @@ -25,7 +25,7 @@ InviteesModel::addUser(QString mxid) beginInsertRows(QModelIndex(), invitees_.count(), invitees_.count()); - auto invitee = new Invitee{mxid, this}; + auto invitee = new Invitee{mxid, displayName, avatarUrl, this}; auto indexOfInvitee = invitees_.count(); connect(invitee, &Invitee::userInfoLoaded, this, [this, indexOfInvitee]() { emit dataChanged(index(indexOfInvitee), index(indexOfInvitee)); @@ -85,21 +85,30 @@ InviteesModel::mxids() return mxidList; } -Invitee::Invitee(QString mxid, QObject *parent) +Invitee::Invitee(QString mxid, QString displayName, QString avatarUrl, QObject *parent) : QObject{parent} , mxid_{std::move(mxid)} { - http::client()->get_profile( - mxid_.toStdString(), [this](const mtx::responses::Profile &res, mtx::http::RequestErr err) { - if (err) { - nhlog::net()->warn("failed to retrieve profile info"); - emit userInfoLoaded(); - return; - } + // checking for empty avatarUrl will cause profiles that don't have an avatar + // to needlessly be loaded. Can we make sure we either provide both or none? + if (displayName == "" && avatarUrl == "") { + http::client()->get_profile( + mxid_.toStdString(), + [this](const mtx::responses::Profile &res, mtx::http::RequestErr err) { + if (err) { + nhlog::net()->warn("failed to retrieve profile info"); + emit userInfoLoaded(); + return; + } - displayName_ = QString::fromStdString(res.display_name); - avatarUrl_ = QString::fromStdString(res.avatar_url); + displayName_ = QString::fromStdString(res.display_name); + avatarUrl_ = QString::fromStdString(res.avatar_url); - emit userInfoLoaded(); - }); + emit userInfoLoaded(); + }); + } else { + displayName_ = displayName; + avatarUrl_ = avatarUrl; + emit userInfoLoaded(); + } }