From e1acf5d324615e8c61c469883a6a42933c8f76bc Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Thu, 10 Jun 2021 20:13:12 -0400 Subject: make lint --- src/InviteesModel.cpp | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/InviteesModel.cpp (limited to 'src/InviteesModel.cpp') diff --git a/src/InviteesModel.cpp b/src/InviteesModel.cpp new file mode 100644 index 00000000..849c5281 --- /dev/null +++ b/src/InviteesModel.cpp @@ -0,0 +1,77 @@ +#include "InviteesModel.h" + +#include "Cache.h" +#include "Logging.h" +#include "MatrixClient.h" +#include "mtx/responses/profile.hpp" + +InviteesModel::InviteesModel(QObject *parent) + : QAbstractListModel{parent} +{} + +void +InviteesModel::addUser(QString mxid) +{ + beginInsertRows(QModelIndex(), invitees_.count(), invitees_.count()); + + auto invitee = new Invitee{mxid, this}; + connect(invitee, &Invitee::userInfoLoaded, this, [this]() { + emit dataChanged(QModelIndex{}, QModelIndex{}); + }); + + invitees_.push_back(invitee); + + endInsertRows(); +} + +QHash +InviteesModel::roleNames() const +{ + return {{Mxid, "mxid"}, {DisplayName, "displayName"}, {AvatarUrl, "avatarUrl"}}; +} + +QVariant +InviteesModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid() || index.row() >= (int)invitees_.size() || index.row() < 0) + return {}; + + switch (role) { + case Mxid: + return invitees_[index.row()]->mxid_; + case DisplayName: + return invitees_[index.row()]->displayName_; + case AvatarUrl: + return invitees_[index.row()]->avatarUrl_; + default: + return {}; + } +} + +QStringList +InviteesModel::mxids() +{ + QStringList mxidList; + for (int i = 0; i < invitees_.length(); ++i) + mxidList.push_back(invitees_[i]->mxid_); + return mxidList; +} + +Invitee::Invitee(const QString &mxid, QObject *parent) + : QObject{parent} + , mxid_{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 own profile info"); + return; + } + + displayName_ = QString::fromStdString(res.display_name); + avatarUrl_ = QString::fromStdString(res.avatar_url); + + emit userInfoLoaded(); + }); +} -- cgit 1.5.1 From f0c88fc47435bda93a55271eb830bf80dc88443f Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Fri, 11 Jun 2021 19:18:04 -0400 Subject: Get member info loading working --- src/InviteesModel.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/InviteesModel.cpp') diff --git a/src/InviteesModel.cpp b/src/InviteesModel.cpp index 849c5281..0081c7df 100644 --- a/src/InviteesModel.cpp +++ b/src/InviteesModel.cpp @@ -16,12 +16,10 @@ InviteesModel::addUser(QString mxid) auto invitee = new Invitee{mxid, this}; connect(invitee, &Invitee::userInfoLoaded, this, [this]() { - emit dataChanged(QModelIndex{}, QModelIndex{}); + endInsertRows(); }); invitees_.push_back(invitee); - - endInsertRows(); } QHash -- cgit 1.5.1 From c566a6254138037d8916bedf9660a66f2d65187f Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Fri, 11 Jun 2021 20:48:28 -0400 Subject: Clean up code --- resources/qml/InviteDialog.qml | 13 ------------- src/InviteesModel.cpp | 4 +--- 2 files changed, 1 insertion(+), 16 deletions(-) (limited to 'src/InviteesModel.cpp') diff --git a/resources/qml/InviteDialog.qml b/resources/qml/InviteDialog.qml index 9ace3246..d8e176e6 100644 --- a/resources/qml/InviteDialog.qml +++ b/resources/qml/InviteDialog.qml @@ -172,19 +172,6 @@ ApplicationWindow { } } } -// delegate: RowLayout { -// spacing: 10 - -// Avatar { -// url: model.avatarUrl -// width: 20 -// height: width -// } - -// Label { -// text: model.displayName + " (" + model.mxid + ")" -// } -// } } } diff --git a/src/InviteesModel.cpp b/src/InviteesModel.cpp index 0081c7df..1da7baf4 100644 --- a/src/InviteesModel.cpp +++ b/src/InviteesModel.cpp @@ -15,9 +15,7 @@ InviteesModel::addUser(QString mxid) beginInsertRows(QModelIndex(), invitees_.count(), invitees_.count()); auto invitee = new Invitee{mxid, this}; - connect(invitee, &Invitee::userInfoLoaded, this, [this]() { - endInsertRows(); - }); + connect(invitee, &Invitee::userInfoLoaded, this, [this]() { endInsertRows(); }); invitees_.push_back(invitee); } -- cgit 1.5.1 From d2d5229ede5124ba6cf9e85790dcd564faad00db Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Sat, 17 Jul 2021 13:31:38 -0400 Subject: make lint --- resources/qml/InviteDialog.qml | 44 ++++++++++++++++++++++++-------- resources/qml/RoomMembers.qml | 4 +++ resources/qml/TimelineView.qml | 1 + src/ChatPage.cpp | 49 +++++++++++++++++++----------------- src/InviteesModel.cpp | 4 +++ src/InviteesModel.h | 4 +++ src/timeline/TimelineViewManager.cpp | 6 ++--- 7 files changed, 75 insertions(+), 37 deletions(-) (limited to 'src/InviteesModel.cpp') diff --git a/resources/qml/InviteDialog.qml b/resources/qml/InviteDialog.qml index 2932e398..ae74d3da 100644 --- a/resources/qml/InviteDialog.qml +++ b/resources/qml/InviteDialog.qml @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2021 Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + import QtQuick 2.12 import QtQuick.Controls 2.12 import QtQuick.Layouts 1.12 @@ -11,14 +15,11 @@ ApplicationWindow { property InviteesModel invitees function addInvite() { - if (inviteeEntry.text.match("@.+?:.{3,}")) - { + if (inviteeEntry.text.match("@.+?:.{3,}")) { invitees.addUser(inviteeEntry.text); inviteeEntry.clear(); - } - else - { - warningLabel.show() + } else { + warningLabel.show(); } } @@ -57,19 +58,29 @@ ApplicationWindow { placeholderText: qsTr("@joe:matrix.org", "Example user id. The name 'joe' can be localized however you want.") Layout.fillWidth: true - onAccepted: if (text !== "") addInvite() + onAccepted: { + if (text !== "") { + addInvite(); + } + } Component.onCompleted: forceActiveFocus() Shortcut { sequence: "Ctrl+Enter" onActivated: invitees.accept() } + } Button { text: qsTr("Add") - onClicked: if (inviteeEntry.text !== "") addInvite() + onClicked: { + if (inviteeEntry.text !== "") { + addInvite(); + } + } } + } Label { @@ -85,26 +96,28 @@ ApplicationWindow { visible: false opacity: 0 state: "hidden" - states: [ State { name: "shown" + PropertyChanges { target: warningLabel opacity: 1 visible: true } + }, State { name: "hidden" + PropertyChanges { target: warningLabel opacity: 0 visible: false } + } ] - transitions: [ Transition { from: "shown" @@ -122,7 +135,9 @@ ApplicationWindow { target: warningLabel property: "visible" } + } + } ] @@ -134,6 +149,7 @@ ApplicationWindow { running: false onTriggered: warningLabel.state = "hidden" } + } ListView { @@ -174,9 +190,13 @@ ApplicationWindow { Layout.fillHeight: true Layout.fillWidth: true } + } + } + } + } footer: DialogButtonBox { @@ -194,7 +214,9 @@ ApplicationWindow { Button { text: qsTr("Cancel") DialogButtonBox.buttonRole: DialogButtonBox.DestructiveRole - onClicked: inviteDialogRoot.close(); + onClicked: inviteDialogRoot.close() } + } + } diff --git a/resources/qml/RoomMembers.qml b/resources/qml/RoomMembers.qml index 8addd704..44b917b1 100644 --- a/resources/qml/RoomMembers.qml +++ b/resources/qml/RoomMembers.qml @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2021 Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + import QtQuick 2.12 import QtQuick.Controls 2.12 import QtQuick.Layouts 1.12 diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index d515b9b4..148a5817 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -157,6 +157,7 @@ Item { Layout.alignment: Qt.AlignHCenter enabled: false } + MatrixText { text: parent.roomName font.pixelSize: 24 diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 8b4cfeef..70fd32fd 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -117,29 +117,32 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) connect(this, &ChatPage::loggedOut, this, &ChatPage::logout); // TODO: once this signal is moved, reenable this -// connect(view_manager_, &TimelineViewManager::inviteUsers, this, [this](QStringList users) { -// const auto room_id = currentRoom().toStdString(); - -// for (int ii = 0; ii < users.size(); ++ii) { -// QTimer::singleShot(ii * 500, this, [this, room_id, ii, users]() { -// const auto user = users.at(ii); - -// http::client()->invite_user( -// room_id, -// user.toStdString(), -// [this, user](const mtx::responses::RoomInvite &, -// mtx::http::RequestErr err) { -// if (err) { -// emit showNotification( -// tr("Failed to invite user: %1").arg(user)); -// return; -// } - -// emit showNotification(tr("Invited user: %1").arg(user)); -// }); -// }); -// } -// }); + // connect(view_manager_, &TimelineViewManager::inviteUsers, this, [this](QStringList + // users) { + // const auto room_id = currentRoom().toStdString(); + + // for (int ii = 0; ii < users.size(); ++ii) { + // QTimer::singleShot(ii * 500, this, [this, room_id, ii, users]() { + // const auto user = users.at(ii); + + // http::client()->invite_user( + // room_id, + // user.toStdString(), + // [this, user](const mtx::responses::RoomInvite &, + // mtx::http::RequestErr err) { + // if (err) { + // emit showNotification( + // tr("Failed to invite user: + // %1").arg(user)); + // return; + // } + + // emit showNotification(tr("Invited user: + // %1").arg(user)); + // }); + // }); + // } + // }); connect( view_manager_, diff --git a/src/InviteesModel.cpp b/src/InviteesModel.cpp index 1da7baf4..59054690 100644 --- a/src/InviteesModel.cpp +++ b/src/InviteesModel.cpp @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2021 Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + #include "InviteesModel.h" #include "Cache.h" diff --git a/src/InviteesModel.h b/src/InviteesModel.h index 4bcc4e9d..ac9208a0 100644 --- a/src/InviteesModel.h +++ b/src/InviteesModel.h @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2021 Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + #ifndef INVITEESMODEL_H #define INVITEESMODEL_H diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index 08b88efd..8daa2124 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -430,10 +430,10 @@ TimelineViewManager::openImageOverlayInternal(QString eventId, QImage img) }); } -//void -//TimelineViewManager::openInviteUsersDialog() +// void +// TimelineViewManager::openInviteUsersDialog() //{ - // TODO: move this somewhere where it will actually work (probably Rooms) +// TODO: move this somewhere where it will actually work (probably Rooms) // MainWindow::instance()->openInviteUsersDialog( // [this](const QStringList &invitees) { emit inviteUsers(invitees); }); //} -- cgit 1.5.1 From 4384554587c3e9327382f2f9cbc36e893fbe4dab Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Mon, 19 Jul 2021 12:31:20 -0400 Subject: Only invite if there is something/someone to invite --- resources/qml/InviteDialog.qml | 81 +++--------------------------------------- src/InviteesModel.cpp | 2 ++ src/InviteesModel.h | 3 ++ 3 files changed, 9 insertions(+), 77 deletions(-) (limited to 'src/InviteesModel.cpp') diff --git a/resources/qml/InviteDialog.qml b/resources/qml/InviteDialog.qml index 02cb5e07..94a95861 100644 --- a/resources/qml/InviteDialog.qml +++ b/resources/qml/InviteDialog.qml @@ -18,13 +18,11 @@ ApplicationWindow { if (inviteeEntry.text.match("@.+?:.{3,}")) { invitees.addUser(inviteeEntry.text); inviteeEntry.clear(); - } else { - warningLabel.show(); } } function cleanUpAndClose() { - if (inviteeEntry.text !== "") + if (inviteeEntry.text.match("@.+?:.{3,}")) addInvite(); invitees.accept(); close(); @@ -79,80 +77,8 @@ ApplicationWindow { Button { text: qsTr("Add") - onClicked: { - if (inviteeEntry.text !== "") { - addInvite(); - } - } - } - - } - - Label { - id: warningLabel - - function show() { - state = "shown"; - warningLabelTimer.start(); - } - - text: qsTr("Please enter a valid username (e.g. @joe:matrix.org).") - color: "red" - visible: false - opacity: 0 - state: "hidden" - states: [ - State { - name: "shown" - - PropertyChanges { - target: warningLabel - opacity: 1 - visible: true - } - - }, - State { - name: "hidden" - - PropertyChanges { - target: warningLabel - opacity: 0 - visible: false - } - - } - ] - transitions: [ - Transition { - from: "shown" - to: "hidden" - reversible: true - - SequentialAnimation { - NumberAnimation { - target: warningLabel - property: "opacity" - duration: 500 - } - - PropertyAction { - target: warningLabel - property: "visible" - } - - } - - } - ] - - Timer { - id: warningLabelTimer - - interval: 2000 - repeat: false - running: false - onTriggered: warningLabel.state = "hidden" + enabled: inviteeEntry.text.match("@.+?:.{3,}") + onClicked: addInvite() } } @@ -210,6 +136,7 @@ ApplicationWindow { Button { text: qsTr("Invite") DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole + enabled: invitees.count > 0 onClicked: cleanUpAndClose() } diff --git a/src/InviteesModel.cpp b/src/InviteesModel.cpp index 59054690..9b64f57c 100644 --- a/src/InviteesModel.cpp +++ b/src/InviteesModel.cpp @@ -22,6 +22,8 @@ InviteesModel::addUser(QString mxid) connect(invitee, &Invitee::userInfoLoaded, this, [this]() { endInsertRows(); }); invitees_.push_back(invitee); + + emit countChanged(); } QHash diff --git a/src/InviteesModel.h b/src/InviteesModel.h index ac9208a0..a4e19ebb 100644 --- a/src/InviteesModel.h +++ b/src/InviteesModel.h @@ -30,6 +30,8 @@ class InviteesModel : public QAbstractListModel { Q_OBJECT + Q_PROPERTY(int count READ rowCount NOTIFY countChanged) + public: enum Roles { @@ -52,6 +54,7 @@ public: signals: void accept(); + void countChanged(); private: QVector invitees_; -- cgit 1.5.1 From 77c636f3d3f0bc11c2fc5e6cc90ee58bd42ab5f9 Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Tue, 20 Jul 2021 19:20:55 -0400 Subject: Insert user before loading avatar/display name --- src/InviteesModel.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/InviteesModel.cpp') diff --git a/src/InviteesModel.cpp b/src/InviteesModel.cpp index 9b64f57c..7bc2b2d4 100644 --- a/src/InviteesModel.cpp +++ b/src/InviteesModel.cpp @@ -19,10 +19,12 @@ InviteesModel::addUser(QString mxid) beginInsertRows(QModelIndex(), invitees_.count(), invitees_.count()); auto invitee = new Invitee{mxid, this}; - connect(invitee, &Invitee::userInfoLoaded, this, [this]() { endInsertRows(); }); + auto indexOfInvitee = invitees_.count(); + connect(invitee, &Invitee::userInfoLoaded, this, [this, indexOfInvitee]() { emit dataChanged(index(indexOfInvitee), index(indexOfInvitee)); }); invitees_.push_back(invitee); + endInsertRows(); emit countChanged(); } -- cgit 1.5.1 From efda94ca50c3942d0eb3165ce30490edd4823462 Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Tue, 20 Jul 2021 19:21:04 -0400 Subject: Modify message to be more accurate --- src/InviteesModel.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/InviteesModel.cpp') diff --git a/src/InviteesModel.cpp b/src/InviteesModel.cpp index 7bc2b2d4..f73fddd9 100644 --- a/src/InviteesModel.cpp +++ b/src/InviteesModel.cpp @@ -69,7 +69,8 @@ Invitee::Invitee(const QString &mxid, QObject *parent) mxid_.toStdString(), [this](const mtx::responses::Profile &res, mtx::http::RequestErr err) { if (err) { - nhlog::net()->warn("failed to retrieve own profile info"); + nhlog::net()->warn("failed to retrieve profile info"); + emit userInfoLoaded(); return; } -- cgit 1.5.1 From 6458614ea11d6ce25936e7ca1ac550eedfa9942a Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Tue, 20 Jul 2021 19:41:12 -0400 Subject: make lint --- src/InviteesModel.cpp | 6 ++++-- src/timeline/TimelineModel.cpp | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src/InviteesModel.cpp') diff --git a/src/InviteesModel.cpp b/src/InviteesModel.cpp index f73fddd9..27b2116f 100644 --- a/src/InviteesModel.cpp +++ b/src/InviteesModel.cpp @@ -18,9 +18,11 @@ InviteesModel::addUser(QString mxid) { beginInsertRows(QModelIndex(), invitees_.count(), invitees_.count()); - auto invitee = new Invitee{mxid, this}; + auto invitee = new Invitee{mxid, this}; auto indexOfInvitee = invitees_.count(); - connect(invitee, &Invitee::userInfoLoaded, this, [this, indexOfInvitee]() { emit dataChanged(index(indexOfInvitee), index(indexOfInvitee)); }); + connect(invitee, &Invitee::userInfoLoaded, this, [this, indexOfInvitee]() { + emit dataChanged(index(indexOfInvitee), index(indexOfInvitee)); + }); invitees_.push_back(invitee); diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index e431e1ac..66d931fd 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -327,7 +327,8 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj this->isSpace_ = create->content.type == mtx::events::state::room_type::space; this->isEncrypted_ = cache::isRoomEncrypted(room_id_.toStdString()); - // this connection will simplify adding the plainRoomNameChanged() signal everywhere that it needs to be + // this connection will simplify adding the plainRoomNameChanged() signal everywhere that it + // needs to be connect(this, &TimelineModel::roomNameChanged, this, &TimelineModel::plainRoomNameChanged); connect( -- cgit 1.5.1