Add action to user detail dialog to search for their messages in room
In other messaging applications (e.g. Discord) this is possible through text modifiers like "from:@user". We don't support that, and I'm not super keen on implementing yet-another-parsing-thing, so an action in the user detail dialog should work for now. Very useful to sift through large rooms but when you only care about a specific person's messages (maybe your own?)
This commit is contained in:
@@ -274,6 +274,20 @@ Kirigami.Dialog {
|
||||
}
|
||||
}
|
||||
|
||||
FormCard.FormButtonDelegate {
|
||||
text: i18nc("@action:button %1 is the name of the user.", "Search room for %1's messages", root.room ? root.room.member(root.user.id).htmlSafeDisplayName : QmlUtils.escapeString(root.user.displayName))
|
||||
icon.name: "search-symbolic"
|
||||
onClicked: {
|
||||
pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'RoomSearchPage'), {
|
||||
room: root.room,
|
||||
senderId: root.user.id
|
||||
}, {
|
||||
title: i18nc("@action:title", "Search")
|
||||
});
|
||||
root.close();
|
||||
}
|
||||
}
|
||||
|
||||
FormCard.FormButtonDelegate {
|
||||
text: i18n("Copy link")
|
||||
icon.name: "username-copy"
|
||||
|
||||
@@ -23,11 +23,17 @@ SearchPage {
|
||||
*/
|
||||
required property NeoChatRoom room
|
||||
|
||||
/**
|
||||
* @brief If set, limits the search to events from a specific user id.
|
||||
*/
|
||||
property string senderId
|
||||
|
||||
title: i18nc("@action:title", "Search Messages")
|
||||
|
||||
model: SearchModel {
|
||||
id: searchModel
|
||||
room: root.room
|
||||
senderId: root.senderId
|
||||
}
|
||||
|
||||
modelDelegate: EventDelegate {
|
||||
|
||||
@@ -51,6 +51,9 @@ void SearchModel::search()
|
||||
filter.notRooms = QStringList();
|
||||
filter.rooms = QStringList{m_room->id()};
|
||||
filter.containsUrl = false;
|
||||
if (!m_senderId.isEmpty()) {
|
||||
filter.senders = {m_senderId};
|
||||
}
|
||||
|
||||
SearchJob::RoomEventsCriteria criteria{
|
||||
.searchTerm = m_searchText,
|
||||
@@ -112,4 +115,15 @@ void SearchModel::setSearching(bool searching)
|
||||
Q_EMIT searchingChanged();
|
||||
}
|
||||
|
||||
QString SearchModel::senderId() const
|
||||
{
|
||||
return m_senderId;
|
||||
}
|
||||
|
||||
void SearchModel::setSenderId(const QString &sender)
|
||||
{
|
||||
m_senderId = sender;
|
||||
Q_EMIT senderIdChanged();
|
||||
}
|
||||
|
||||
#include "moc_searchmodel.cpp"
|
||||
|
||||
@@ -37,6 +37,11 @@ class SearchModel : public MessageModel
|
||||
*/
|
||||
Q_PROPERTY(bool searching READ searching NOTIFY searchingChanged)
|
||||
|
||||
/**
|
||||
* @brief If set, limits the search to this specific sender.
|
||||
*/
|
||||
Q_PROPERTY(QString senderId READ senderId WRITE setSenderId NOTIFY senderIdChanged)
|
||||
|
||||
public:
|
||||
explicit SearchModel(QObject *parent = nullptr);
|
||||
|
||||
@@ -45,6 +50,9 @@ public:
|
||||
|
||||
bool searching() const;
|
||||
|
||||
QString senderId() const;
|
||||
void setSenderId(const QString &sender);
|
||||
|
||||
/**
|
||||
* @brief Number of rows in the model.
|
||||
*
|
||||
@@ -61,6 +69,7 @@ Q_SIGNALS:
|
||||
void searchTextChanged();
|
||||
void roomChanged();
|
||||
void searchingChanged();
|
||||
void senderIdChanged();
|
||||
|
||||
private:
|
||||
std::optional<std::reference_wrapper<const Quotient::RoomEvent>> getEventForIndex(QModelIndex index) const override;
|
||||
@@ -71,4 +80,5 @@ private:
|
||||
std::optional<Quotient::SearchJob::ResultRoomEvents> m_result = std::nullopt;
|
||||
Quotient::SearchJob *m_job = nullptr;
|
||||
bool m_searching = false;
|
||||
QString m_senderId;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user