diff --git a/resources/qml/dialogs/InviteDialog.qml b/resources/qml/dialogs/InviteDialog.qml index 3105576d..1f3a909a 100644 --- a/resources/qml/dialogs/InviteDialog.qml +++ b/resources/qml/dialogs/InviteDialog.qml @@ -17,15 +17,16 @@ ApplicationWindow { property InviteesModel invitees property var friendsCompleter property var profile - minimumWidth: 500 + minimumWidth: 300 Component.onCompleted: { friendsCompleter = TimelineManager.completerFor("user", "friends") + width = 600 } - function addInvite(mxid) { + function addInvite(mxid, displayName, avatarUrl) { if (mxid.match("@.+?:.{3,}")) { - invitees.addUser(mxid); + invitees.addUser(mxid, displayName, avatarUrl); if (mxid == inviteeEntry.text) inviteeEntry.clear(); } else @@ -34,7 +35,7 @@ ApplicationWindow { function cleanUpAndClose() { if (inviteeEntry.isValidMxid) - addInvite(inviteeEntry.text); + addInvite(inviteeEntry.text, "", ""); invitees.accept(); close(); @@ -61,13 +62,40 @@ ApplicationWindow { anchors.fill: parent anchors.margins: Nheko.paddingMedium spacing: Nheko.paddingMedium + Flow { + layoutDirection: Qt.LeftToRight + Layout.fillWidth: true + Layout.preferredHeight: implicitHeight + spacing: 4 + Repeater { + id: inviteesRepeater + model: invitees + delegate: ItemDelegate { + onClicked: invitees.removeUser(model.mxid) + id: inviteeButton + visible: !inviteesList.visible + contentItem: Label { + anchors.centerIn: parent + id: inviteeUserid + text: model.displayName + color: inviteeButton.hovered ? Nheko.colors.highlightedText: Nheko.colors.text + maximumLineCount: 1 + } + background: Rectangle { + border.color: Nheko.colors.text + color: inviteeButton.hovered ? Nheko.colors.highlight : Nheko.colors.window + border.width: 1 + radius: inviteeButton.height / 2 + } + } + } + } Label { - text: qsTr("User ID to invite") + text: qsTr("User to invite") Layout.fillWidth: true color: Nheko.colors.text } - RowLayout { spacing: Nheko.paddingMedium @@ -81,7 +109,7 @@ ApplicationWindow { Layout.fillWidth: true onAccepted: { if (isValidMxid) - addInvite(text); + addInvite(text, "", ""); } Component.onCompleted: forceActiveFocus() @@ -123,7 +151,7 @@ ApplicationWindow { Layout.preferredWidth: inviteDialogRoot.width/2 Layout.alignment: Qt.AlignTop Layout.preferredHeight: layout3.implicitHeight + Nheko.paddingSmall * 2 - onClicked: addInvite(inviteeEntry.text) + onClicked: addInvite(inviteeEntry.text, profile? profile.displayName : "", profile? profile.avatarUrl : "") background: Rectangle { color: del3.hovered ? Nheko.colors.dark : inviteDialogRoot.color clip: true @@ -174,7 +202,7 @@ ApplicationWindow { id: del2 width: ListView.view.width height: layout2.implicitHeight + Nheko.paddingSmall * 2 - onClicked: addInvite(model.userid) + onClicked: addInvite(model.userid, model.displayName, model.avatarUrl) background: Rectangle { color: del2.hovered ? Nheko.colors.dark : inviteDialogRoot.color } @@ -221,6 +249,7 @@ ApplicationWindow { Layout.fillHeight: true model: invitees clip: true + visible: inviteDialogRoot.width >= 500 delegate: ItemDelegate { id: del diff --git a/src/InviteesModel.cpp b/src/InviteesModel.cpp index 8e30847c..fe30e70a 100644 --- a/src/InviteesModel.cpp +++ b/src/InviteesModel.cpp @@ -16,7 +16,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) @@ -24,7 +24,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)); @@ -84,21 +84,28 @@ 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"); + 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(); + } } diff --git a/src/InviteesModel.h b/src/InviteesModel.h index 004f37ca..8e1251f6 100644 --- a/src/InviteesModel.h +++ b/src/InviteesModel.h @@ -14,7 +14,10 @@ class Invitee final : public QObject Q_OBJECT public: - Invitee(QString mxid, QObject *parent = nullptr); + Invitee(QString mxid, + QString displayName = "", + QString avatarUrl = "", + QObject *parent = nullptr); signals: void userInfoLoaded(); @@ -43,7 +46,7 @@ public: InviteesModel(QObject *parent = nullptr); - Q_INVOKABLE void addUser(QString mxid); + Q_INVOKABLE void addUser(QString mxid, QString displayName = "", QString avatarUrl = ""); Q_INVOKABLE void removeUser(QString mxid); [[nodiscard]] QHash roleNames() const override; diff --git a/src/UserDirectoryModel.cpp b/src/UserDirectoryModel.cpp index 5a014704..fb318e8a 100644 --- a/src/UserDirectoryModel.cpp +++ b/src/UserDirectoryModel.cpp @@ -77,11 +77,11 @@ UserDirectoryModel::data(const QModelIndex &index, int role) const void UserDirectoryModel::displaySearchResults(std::vector results) { - results_ = results; if (results_.empty()) { nhlog::net()->error("mtxclient helper thread yielded empty chunk!"); return; } beginInsertRows(QModelIndex(), 0, static_cast(results_.size()) - 1); + results_ = results; endInsertRows(); }