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();
+ }
}
|