From 19dbbb2c6cffdf0697635f08acf3af9138aed7b9 Mon Sep 17 00:00:00 2001 From: Jedi18 Date: Tue, 16 Feb 2021 00:47:17 +0530 Subject: add rooms model, add room delegate for completer --- src/timeline/InputBar.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/timeline/InputBar.cpp') diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 08cbd15b..49fa5249 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -23,6 +23,7 @@ #include "TimelineViewManager.h" #include "UserSettingsPage.h" #include "UsersModel.h" +#include "RoomsModel.h" #include "Utils.h" #include "dialogs/PreviewUploadOverlay.h" #include "emoji/EmojiModel.h" @@ -186,6 +187,11 @@ InputBar::completerFor(QString completerName) auto proxy = new CompletionProxyModel(emojiModel); emojiModel->setParent(proxy); return proxy; + } else if (completerName == "room") { + auto roomModel = new RoomsModel(); + auto proxy = new CompletionProxyModel(roomModel); + roomModel->setParent(proxy); + return proxy; } return nullptr; } -- cgit 1.5.1 From 0b6c82dfffd20a264dd54ee838a33a7e157adb59 Mon Sep 17 00:00:00 2001 From: Jedi18 Date: Wed, 17 Feb 2021 19:51:35 +0530 Subject: added bool to choose between showing only rooms with aliases and all of the rooms --- src/RoomsModel.cpp | 23 +++++++++++++++-------- src/RoomsModel.h | 6 +++--- src/timeline/InputBar.cpp | 4 ++-- 3 files changed, 20 insertions(+), 13 deletions(-) (limited to 'src/timeline/InputBar.cpp') diff --git a/src/RoomsModel.cpp b/src/RoomsModel.cpp index 6ace8ef7..213d84df 100644 --- a/src/RoomsModel.cpp +++ b/src/RoomsModel.cpp @@ -3,18 +3,26 @@ #include "Cache_p.h" #include "CompletionModelRoles.h" -RoomsModel::RoomsModel(QObject *parent) +RoomsModel::RoomsModel(bool showOnlyRoomWithAliases, QObject *parent) : QAbstractListModel(parent) + , showOnlyRoomWithAliases_(showOnlyRoomWithAliases) { - rooms_ = cache::joinedRooms(); - roomInfos = cache::getRoomInfo(rooms_); + std::vector rooms_ = cache::joinedRooms(); + roomInfos = cache::getRoomInfo(rooms_); for (const auto &r : rooms_) { auto roomAliasesList = cache::client()->getRoomAliases(r); - if (roomAliasesList) { - roomAliases.push_back(QString::fromStdString(roomAliasesList->alias)); + if (showOnlyRoomWithAliases_) { + if (roomAliasesList) { + roomids.push_back(QString::fromStdString(r)); + roomAliases.push_back( + QString::fromStdString(roomAliasesList->alias)); + } + } else { roomids.push_back(QString::fromStdString(r)); + roomAliases.push_back( + roomAliasesList ? QString::fromStdString(roomAliasesList->alias) : ""); } } } @@ -43,14 +51,13 @@ RoomsModel::data(const QModelIndex &index, int role) const case Roles::RoomAlias: return roomAliases[index.row()]; case CompletionModel::SearchRole2: - return roomAliases[index.row()]; + case Roles::RoomName: + return QString::fromStdString(roomInfos.at(roomids[index.row()]).name); case Roles::AvatarUrl: return QString::fromStdString( roomInfos.at(roomids[index.row()]).avatar_url); case Roles::RoomID: return roomids[index.row()]; - case Roles::RoomName: - return QString::fromStdString(roomInfos.at(roomids[index.row()]).name); } } return {}; diff --git a/src/RoomsModel.h b/src/RoomsModel.h index 88cb5c68..0e006448 100644 --- a/src/RoomsModel.h +++ b/src/RoomsModel.h @@ -16,18 +16,18 @@ public: RoomName, }; - RoomsModel(QObject *parent = nullptr); + RoomsModel(bool showOnlyRoomWithAliases = false, QObject *parent = nullptr); QHash roleNames() const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override { (void)parent; - return (int)roomAliases.size(); + return (int)roomids.size(); } QVariant data(const QModelIndex &index, int role) const override; private: - std::vector rooms_; std::vector roomids; std::vector roomAliases; std::map roomInfos; + bool showOnlyRoomWithAliases_; }; diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 49fa5249..5ef38ac7 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -19,11 +19,11 @@ #include "MainWindow.h" #include "MatrixClient.h" #include "Olm.h" +#include "RoomsModel.h" #include "TimelineModel.h" #include "TimelineViewManager.h" #include "UserSettingsPage.h" #include "UsersModel.h" -#include "RoomsModel.h" #include "Utils.h" #include "dialogs/PreviewUploadOverlay.h" #include "emoji/EmojiModel.h" @@ -188,7 +188,7 @@ InputBar::completerFor(QString completerName) emojiModel->setParent(proxy); return proxy; } else if (completerName == "room") { - auto roomModel = new RoomsModel(); + auto roomModel = new RoomsModel(true); auto proxy = new CompletionProxyModel(roomModel); roomModel->setParent(proxy); return proxy; -- cgit 1.5.1 From 345dc1e61fa51764fb4897903cf6be7579d66558 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 25 Feb 2021 00:50:17 +0100 Subject: Fix text input restoring after edits --- resources/qml/MessageInput.qml | 2 -- src/timeline/InputBar.cpp | 41 ++++++++++++++++++++++------------------- src/timeline/InputBar.h | 2 +- src/timeline/TimelineModel.h | 2 ++ 4 files changed, 25 insertions(+), 22 deletions(-) (limited to 'src/timeline/InputBar.cpp') diff --git a/resources/qml/MessageInput.qml b/resources/qml/MessageInput.qml index 9bb01471..5a543ac9 100644 --- a/resources/qml/MessageInput.qml +++ b/resources/qml/MessageInput.qml @@ -177,7 +177,6 @@ Rectangle { } } TimelineManager.timeline.input.send(); - messageInput.clear(); event.accepted = true; } else if (event.key == Qt.Key_Tab) { event.accepted = true; @@ -334,7 +333,6 @@ Rectangle { ToolTip.text: qsTr("Send") onClicked: { TimelineManager.timeline.input.send(); - messageInput.clear(); } } diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 5ef38ac7..b1580f97 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -122,6 +122,20 @@ InputBar::insertMimeData(const QMimeData *md) } } +void +InputBar::setText(QString newText) +{ + if (history_.empty()) + history_.push_front(newText); + else + history_.front() = newText; + history_index_ = 0; + + if (history_.size() == INPUT_HISTORY_SIZE) + history_.pop_back(); + + emit textChanged(newText); +} void InputBar::updateState(int selectionStart_, int selectionEnd_, int cursorPosition_, QString text_) { @@ -202,6 +216,10 @@ InputBar::send() if (text().trimmed().isEmpty()) return; + nhlog::ui()->debug("Send: {}", text().toStdString()); + + auto wasEdit = !room->edit().isEmpty(); + if (text().startsWith('/')) { int command_end = text().indexOf(' '); if (command_end == -1) @@ -217,12 +235,10 @@ InputBar::send() message(text()); } - nhlog::ui()->debug("Send: {}", text().toStdString()); - - if (history_.size() == INPUT_HISTORY_SIZE) - history_.pop_back(); - history_.push_front(""); - history_index_ = 0; + if (!wasEdit) { + history_.push_front(""); + setText(""); + } } void @@ -278,12 +294,10 @@ InputBar::message(QString msg, MarkdownOverride useMarkdown) if (!room->reply().isEmpty()) { text.relations.relations.push_back( {mtx::common::RelationType::InReplyTo, room->reply().toStdString()}); - room->resetReply(); } text.relations.relations.push_back( {mtx::common::RelationType::Replace, room->edit().toStdString()}); - room->resetEdit(); } else if (!room->reply().isEmpty()) { auto related = room->relatedInfo(room->reply()); @@ -313,7 +327,6 @@ InputBar::message(QString msg, MarkdownOverride useMarkdown) text.relations.relations.push_back( {mtx::common::RelationType::InReplyTo, related.related_event}); - room->resetReply(); } room->sendMessageEvent(text, mtx::events::EventType::RoomMessage); @@ -336,12 +349,10 @@ InputBar::emote(QString msg) if (!room->reply().isEmpty()) { emote.relations.relations.push_back( {mtx::common::RelationType::InReplyTo, room->reply().toStdString()}); - room->resetReply(); } if (!room->edit().isEmpty()) { emote.relations.relations.push_back( {mtx::common::RelationType::Replace, room->edit().toStdString()}); - room->resetEdit(); } room->sendMessageEvent(emote, mtx::events::EventType::RoomMessage); @@ -372,12 +383,10 @@ InputBar::image(const QString &filename, if (!room->reply().isEmpty()) { image.relations.relations.push_back( {mtx::common::RelationType::InReplyTo, room->reply().toStdString()}); - room->resetReply(); } if (!room->edit().isEmpty()) { image.relations.relations.push_back( {mtx::common::RelationType::Replace, room->edit().toStdString()}); - room->resetEdit(); } room->sendMessageEvent(image, mtx::events::EventType::RoomMessage); @@ -403,12 +412,10 @@ InputBar::file(const QString &filename, if (!room->reply().isEmpty()) { file.relations.relations.push_back( {mtx::common::RelationType::InReplyTo, room->reply().toStdString()}); - room->resetReply(); } if (!room->edit().isEmpty()) { file.relations.relations.push_back( {mtx::common::RelationType::Replace, room->edit().toStdString()}); - room->resetEdit(); } room->sendMessageEvent(file, mtx::events::EventType::RoomMessage); @@ -435,12 +442,10 @@ InputBar::audio(const QString &filename, if (!room->reply().isEmpty()) { audio.relations.relations.push_back( {mtx::common::RelationType::InReplyTo, room->reply().toStdString()}); - room->resetReply(); } if (!room->edit().isEmpty()) { audio.relations.relations.push_back( {mtx::common::RelationType::Replace, room->edit().toStdString()}); - room->resetEdit(); } room->sendMessageEvent(audio, mtx::events::EventType::RoomMessage); @@ -466,12 +471,10 @@ InputBar::video(const QString &filename, if (!room->reply().isEmpty()) { video.relations.relations.push_back( {mtx::common::RelationType::InReplyTo, room->reply().toStdString()}); - room->resetReply(); } if (!room->edit().isEmpty()) { video.relations.relations.push_back( {mtx::common::RelationType::Replace, room->edit().toStdString()}); - room->resetEdit(); } room->sendMessageEvent(video, mtx::events::EventType::RoomMessage); diff --git a/src/timeline/InputBar.h b/src/timeline/InputBar.h index 696a0dd9..4cb6da7b 100644 --- a/src/timeline/InputBar.h +++ b/src/timeline/InputBar.h @@ -41,7 +41,7 @@ public slots: QString text() const; QString previousText(); QString nextText(); - void setText(QString newText) { emit textChanged(newText); } + void setText(QString newText); void send(); void paste(bool fromMouse); diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index c4df300f..e02539bb 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -355,4 +355,6 @@ TimelineModel::sendMessageEvent(const T &content, mtx::events::EventType eventTy msgCopy.content = content; msgCopy.type = eventType; emit newMessageToSend(msgCopy); + resetReply(); + resetEdit(); } -- cgit 1.5.1