add user search to invite dialog (#1253)

This commit is contained in:
Malte E 2023-02-01 00:59:49 +08:00 committed by GitHub
parent 3abb49c4a2
commit 5ed3bfc8f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 437 additions and 99 deletions

View file

@ -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");
// 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);
emit userInfoLoaded();
return;
}
displayName_ = QString::fromStdString(res.display_name);
avatarUrl_ = QString::fromStdString(res.avatar_url);
emit userInfoLoaded();
});
});
} else {
displayName_ = displayName;
avatarUrl_ = avatarUrl;
emit userInfoLoaded();
}
}