diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-10-06 21:59:59 +0200 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-10-06 22:02:26 +0200 |
commit | f1c1f18f815d93583f524a89e4c2f5f954b07b43 (patch) | |
tree | d52c3f944128da91b586d742e31c3c93cc4ce8d1 /src | |
parent | Basic thread filtering (diff) | |
download | nheko-f1c1f18f815d93583f524a89e4c2f5f954b07b43.tar.xz |
Add a slow way to search a room
Diffstat (limited to 'src')
-rw-r--r-- | src/timeline/EventStore.cpp | 1 | ||||
-rw-r--r-- | src/timeline/TimelineFilter.cpp | 26 | ||||
-rw-r--r-- | src/timeline/TimelineFilter.h | 12 | ||||
-rw-r--r-- | src/timeline/TimelineModel.cpp | 19 | ||||
-rw-r--r-- | src/timeline/TimelineModel.h | 7 |
5 files changed, 41 insertions, 24 deletions
diff --git a/src/timeline/EventStore.cpp b/src/timeline/EventStore.cpp index 0b7a7b1b..de813196 100644 --- a/src/timeline/EventStore.cpp +++ b/src/timeline/EventStore.cpp @@ -898,6 +898,7 @@ EventStore::fetchMore() mtx::http::MessagesOpts opts; opts.room_id = room_id_; opts.from = cache::client()->previousBatchToken(room_id_); + opts.limit = 80; nhlog::ui()->debug("Paginating room {}, token {}", opts.room_id, opts.from); diff --git a/src/timeline/TimelineFilter.cpp b/src/timeline/TimelineFilter.cpp index 82bc7dd3..15d2590c 100644 --- a/src/timeline/TimelineFilter.cpp +++ b/src/timeline/TimelineFilter.cpp @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2022 Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + #include "TimelineFilter.h" #include "Logging.h" @@ -20,6 +24,17 @@ TimelineFilter::setThreadId(const QString &t) } void +TimelineFilter::setContentFilter(const QString &c) +{ + nhlog::ui()->debug("Filtering by content '{}'", c.toStdString()); + if (this->contentFilter != c) { + this->contentFilter = c; + invalidateFilter(); + } + emit contentFilterChanged(); +} + +void TimelineFilter::setSource(TimelineModel *s) { if (auto orig = this->source(); orig != s) { @@ -62,11 +77,20 @@ TimelineFilter::currentIndex() const bool TimelineFilter::filterAcceptsRow(int source_row, const QModelIndex &) const { - if (threadId.isEmpty()) + if (threadId.isEmpty() && contentFilter.isEmpty()) return true; if (auto s = sourceModel()) { auto idx = s->index(source_row, 0); + if (!contentFilter.isEmpty() && !s->data(idx, TimelineModel::Body) + .toString() + .contains(contentFilter, Qt::CaseInsensitive)) { + return false; + } + + if (threadId.isEmpty()) + return true; + return s->data(idx, TimelineModel::EventId) == threadId || s->data(idx, TimelineModel::ThreadId) == threadId; } else { diff --git a/src/timeline/TimelineFilter.h b/src/timeline/TimelineFilter.h index 5c71a89a..3b04650e 100644 --- a/src/timeline/TimelineFilter.h +++ b/src/timeline/TimelineFilter.h @@ -16,6 +16,8 @@ class TimelineFilter : public QSortFilterProxyModel Q_OBJECT Q_PROPERTY(QString filterByThread READ filterByThread WRITE setThreadId NOTIFY threadIdChanged) + Q_PROPERTY(QString filterByContent READ filterByContent WRITE setContentFilter NOTIFY + contentFilterChanged) Q_PROPERTY(TimelineModel *source READ source WRITE setSource NOTIFY sourceChanged) Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) @@ -23,15 +25,23 @@ public: explicit TimelineFilter(QObject *parent = nullptr); QString filterByThread() const { return threadId; } + QString filterByContent() const { return contentFilter; } TimelineModel *source() const; int currentIndex() const; void setThreadId(const QString &t); + void setContentFilter(const QString &t); void setSource(TimelineModel *t); void setCurrentIndex(int idx); + Q_INVOKABLE QVariant dataByIndex(int i, int role = Qt::DisplayRole) const + { + return data(index(i, 0), role); + } + signals: void threadIdChanged(); + void contentFilterChanged(); void sourceChanged(); void currentIndexChanged(); @@ -39,5 +49,5 @@ protected: bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; private: - QString threadId; + QString threadId, contentFilter; }; diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 6c967633..3ce854a4 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -481,12 +481,9 @@ TimelineModel::roleNames() const {IsOnlyEmoji, "isOnlyEmoji"}, {Body, "body"}, {FormattedBody, "formattedBody"}, - {PreviousMessageUserId, "previousMessageUserId"}, {IsSender, "isSender"}, {UserId, "userId"}, {UserName, "userName"}, - {PreviousMessageDay, "previousMessageDay"}, - {PreviousMessageIsStateEvent, "previousMessageIsStateEvent"}, {Day, "day"}, {Timestamp, "timestamp"}, {Url, "url"}, @@ -804,22 +801,6 @@ TimelineModel::data(const QModelIndex &index, int role) const if (!event) return ""; - if (role == PreviousMessageDay || role == PreviousMessageUserId || - role == PreviousMessageIsStateEvent) { - int prevIdx = rowCount() - index.row() - 2; - if (prevIdx < 0) - return {}; - auto tempEv = events.get(prevIdx); - if (!tempEv) - return {}; - if (role == PreviousMessageUserId) - return data(*tempEv, UserId); - else if (role == PreviousMessageDay) - return data(*tempEv, Day); - else - return data(*tempEv, IsStateEvent); - } - return data(*event, role); } diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index 3a862cc9..ee84486e 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -214,12 +214,9 @@ public: IsOnlyEmoji, Body, FormattedBody, - PreviousMessageUserId, IsSender, UserId, UserName, - PreviousMessageDay, - PreviousMessageIsStateEvent, Day, Timestamp, Url, @@ -257,6 +254,10 @@ public: QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant data(const mtx::events::collections::TimelineEvents &event, int role) const; Q_INVOKABLE QVariant dataById(const QString &id, int role, const QString &relatedTo); + Q_INVOKABLE QVariant dataByIndex(int i, int role = Qt::DisplayRole) const + { + return data(index(i), role); + } bool canFetchMore(const QModelIndex &) const override; void fetchMore(const QModelIndex &) override; |