Now you can search in a chat...
This commit is contained in:
parent
461b724d15
commit
19a17ed3f3
17 changed files with 243 additions and 33 deletions
|
@ -332,6 +332,14 @@ Page {
|
|||
return false;
|
||||
}
|
||||
|
||||
function resetFocus() {
|
||||
if (searchInChatField.text === "") {
|
||||
chatOverviewItem.visible = true;
|
||||
}
|
||||
searchInChatField.focus = false;
|
||||
chatPage.focus = true;
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: forwardMessagesTimer
|
||||
interval: 200
|
||||
|
@ -348,6 +356,17 @@ Page {
|
|||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: searchInChatTimer
|
||||
interval: 300
|
||||
running: false
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
Debug.log("Searching for '" + searchInChatField.text + "'");
|
||||
chatModel.setSearchQuery(searchInChatField.text);
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
initializePage();
|
||||
}
|
||||
|
@ -627,6 +646,17 @@ Page {
|
|||
}
|
||||
text: chatInformation.notification_settings.mute_for > 0 ? qsTr("Unmute Chat") : qsTr("Mute Chat")
|
||||
}
|
||||
|
||||
MenuItem {
|
||||
id: searchInChatMenuItem
|
||||
visible: !chatPage.isSecretChat
|
||||
onClicked: {
|
||||
// This automatically shows the search field as well
|
||||
chatOverviewItem.visible = false;
|
||||
searchInChatField.focus = true;
|
||||
}
|
||||
text: qsTr("Search in Chat")
|
||||
}
|
||||
}
|
||||
|
||||
BackgroundItem {
|
||||
|
@ -700,6 +730,8 @@ Page {
|
|||
|
||||
Item {
|
||||
id: chatOverviewItem
|
||||
opacity: visible ? 1 : 0
|
||||
Behavior on opacity { FadeAnimation {} }
|
||||
width: parent.width - chatPictureThumbnail.width - Theme.paddingMedium
|
||||
height: chatNameText.height + chatStatusText.height
|
||||
anchors.bottom: parent.bottom
|
||||
|
@ -732,6 +764,40 @@ Page {
|
|||
maximumLineCount: 1
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
id: searchInChatItem
|
||||
visible: !chatOverviewItem.visible
|
||||
opacity: visible ? 1 : 0
|
||||
Behavior on opacity { FadeAnimation {} }
|
||||
width: parent.width - chatPictureThumbnail.width - Theme.paddingMedium
|
||||
height: searchInChatField.height
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: chatPage.isPortrait ? Theme.paddingMedium : Theme.paddingSmall
|
||||
|
||||
SearchField {
|
||||
id: searchInChatField
|
||||
visible: false
|
||||
width: visible ? parent.width : 0
|
||||
height: parent.height
|
||||
placeholderText: qsTr("Search in chat...")
|
||||
active: searchInChatItem.visible
|
||||
canHide: text === ""
|
||||
|
||||
onTextChanged: {
|
||||
searchInChatTimer.restart();
|
||||
}
|
||||
|
||||
onHideClicked: {
|
||||
resetFocus();
|
||||
}
|
||||
|
||||
EnterKey.iconSource: "image://theme/icon-m-enter-close"
|
||||
EnterKey.onClicked: {
|
||||
resetFocus();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PinnedMessageItem {
|
||||
|
|
|
@ -156,11 +156,13 @@ Page {
|
|||
}
|
||||
|
||||
function resetFocus() {
|
||||
if (chatSearchField.text === "") {
|
||||
chatSearchField.visible = false;
|
||||
pageHeader.visible = true;
|
||||
searchChatButton.visible = overviewPage.connectionState === TelegramAPI.ConnectionReady;
|
||||
}
|
||||
chatSearchField.focus = false;
|
||||
overviewPage.focus = true;
|
||||
chatSearchField.visible = false;
|
||||
pageHeader.visible = true;
|
||||
searchChatButton.visible = overviewPage.connectionState === TelegramAPI.ConnectionReady;
|
||||
}
|
||||
|
||||
Connections {
|
||||
|
@ -282,13 +284,18 @@ Page {
|
|||
Behavior on opacity { FadeAnimation {} }
|
||||
width: visible ? ( parent.width - pageStatus.width ) : 0
|
||||
height: pageHeader.height
|
||||
placeholderText: qsTr("Search a chat...")
|
||||
placeholderText: qsTr("Filter your chats...")
|
||||
active: searchHeaderItem.visible
|
||||
canHide: text === ""
|
||||
|
||||
onTextChanged: {
|
||||
searchChatTimer.restart();
|
||||
}
|
||||
|
||||
onHideClicked: {
|
||||
resetFocus();
|
||||
}
|
||||
|
||||
EnterKey.iconSource: "image://theme/icon-m-enter-close"
|
||||
EnterKey.onClicked: {
|
||||
resetFocus();
|
||||
|
|
|
@ -149,11 +149,13 @@ QVariant ChatModel::data(const QModelIndex &index, int role) const
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
void ChatModel::clear()
|
||||
void ChatModel::clear(bool contentOnly)
|
||||
{
|
||||
LOG("Clearing chat model");
|
||||
inReload = false;
|
||||
inIncrementalUpdate = false;
|
||||
searchModeActive = false;
|
||||
searchQuery.clear();
|
||||
if (!messages.isEmpty()) {
|
||||
beginResetModel();
|
||||
qDeleteAll(messages);
|
||||
|
@ -161,13 +163,16 @@ void ChatModel::clear()
|
|||
messageIndexMap.clear();
|
||||
endResetModel();
|
||||
}
|
||||
if (!chatInformation.isEmpty()) {
|
||||
chatInformation.clear();
|
||||
emit smallPhotoChanged();
|
||||
}
|
||||
if (chatId) {
|
||||
chatId = 0;
|
||||
emit chatIdChanged();
|
||||
|
||||
if (!contentOnly) {
|
||||
if (!chatInformation.isEmpty()) {
|
||||
chatInformation.clear();
|
||||
emit smallPhotoChanged();
|
||||
}
|
||||
if (chatId) {
|
||||
chatId = 0;
|
||||
emit chatIdChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -181,6 +186,7 @@ void ChatModel::initialize(const QVariantMap &chatInformation)
|
|||
this->chatId = chatId;
|
||||
this->messages.clear();
|
||||
this->messageIndexMap.clear();
|
||||
this->searchQuery.clear();
|
||||
endResetModel();
|
||||
emit chatIdChanged();
|
||||
emit smallPhotoChanged();
|
||||
|
@ -190,15 +196,21 @@ void ChatModel::initialize(const QVariantMap &chatInformation)
|
|||
void ChatModel::triggerLoadMoreHistory()
|
||||
{
|
||||
if (!this->inIncrementalUpdate && !messages.isEmpty()) {
|
||||
LOG("Trigger loading older history...");
|
||||
this->inIncrementalUpdate = true;
|
||||
this->tdLibWrapper->getChatHistory(chatId, messages.first()->messageId);
|
||||
if (searchModeActive) {
|
||||
LOG("Trigger loading older found messages...");
|
||||
this->inIncrementalUpdate = true;
|
||||
this->tdLibWrapper->searchChatMessages(chatId, searchQuery, messages.first()->messageId);
|
||||
} else {
|
||||
LOG("Trigger loading older history...");
|
||||
this->inIncrementalUpdate = true;
|
||||
this->tdLibWrapper->getChatHistory(chatId, messages.first()->messageId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ChatModel::triggerLoadMoreFuture()
|
||||
{
|
||||
if (!this->inIncrementalUpdate && !messages.isEmpty()) {
|
||||
if (!this->inIncrementalUpdate && !messages.isEmpty() && !searchModeActive) {
|
||||
LOG("Trigger loading newer future...");
|
||||
this->inIncrementalUpdate = true;
|
||||
this->tdLibWrapper->getChatHistory(chatId, messages.last()->messageId, -49);
|
||||
|
@ -214,9 +226,8 @@ QVariantMap ChatModel::getMessage(int index)
|
|||
{
|
||||
if (index >= 0 && index < messages.size()) {
|
||||
return messages.at(index)->messageData;
|
||||
} else {
|
||||
return QVariantMap();
|
||||
}
|
||||
return QVariantMap();
|
||||
}
|
||||
|
||||
int ChatModel::getLastReadMessageIndex()
|
||||
|
@ -240,6 +251,20 @@ int ChatModel::getLastReadMessageIndex()
|
|||
}
|
||||
}
|
||||
|
||||
void ChatModel::setSearchQuery(const QString newSearchQuery)
|
||||
{
|
||||
if (this->searchQuery != newSearchQuery) {
|
||||
this->clear(true);
|
||||
this->searchQuery = newSearchQuery;
|
||||
this->searchModeActive = !this->searchQuery.isEmpty();
|
||||
if (this->searchModeActive) {
|
||||
this->tdLibWrapper->searchChatMessages(this->chatId, this->searchQuery);
|
||||
} else {
|
||||
this->tdLibWrapper->getChatHistory(chatId, this->chatInformation.value(LAST_READ_INBOX_MESSAGE_ID).toLongLong());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QVariantMap ChatModel::smallPhoto() const
|
||||
{
|
||||
return chatInformation.value(PHOTO).toMap().value(SMALL).toMap();
|
||||
|
@ -253,6 +278,7 @@ qlonglong ChatModel::getChatId() const
|
|||
void ChatModel::handleMessagesReceived(const QVariantList &messages, int totalCount)
|
||||
{
|
||||
LOG("Receiving new messages :)" << messages.size());
|
||||
LOG("Received while search mode is" << searchModeActive);
|
||||
|
||||
if (messages.size() == 0) {
|
||||
LOG("No additional messages loaded, notifying chat UI...");
|
||||
|
@ -269,6 +295,7 @@ void ChatModel::handleMessagesReceived(const QVariantList &messages, int totalCo
|
|||
if (this->isMostRecentMessageLoaded() || this->inIncrementalUpdate) {
|
||||
QList<MessageData*> messagesToBeAdded;
|
||||
QListIterator<QVariant> messagesIterator(messages);
|
||||
|
||||
while (messagesIterator.hasNext()) {
|
||||
const QVariantMap messageData = messagesIterator.next().toMap();
|
||||
const qlonglong messageId = messageData.value(ID).toLongLong();
|
||||
|
@ -288,7 +315,11 @@ void ChatModel::handleMessagesReceived(const QVariantList &messages, int totalCo
|
|||
if (!messagesToBeAdded.isEmpty() && (messagesToBeAdded.size() + messages.size()) < 10 && !inReload) {
|
||||
LOG("Only a few messages received in first call, loading more...");
|
||||
this->inReload = true;
|
||||
this->tdLibWrapper->getChatHistory(chatId, messagesToBeAdded.first()->messageId, 0);
|
||||
if (this->searchModeActive) {
|
||||
this->tdLibWrapper->searchChatMessages(chatId, searchQuery, messagesToBeAdded.first()->messageId);
|
||||
} else {
|
||||
this->tdLibWrapper->getChatHistory(chatId, messagesToBeAdded.first()->messageId, 0);
|
||||
}
|
||||
} else {
|
||||
LOG("Messages loaded, notifying chat UI...");
|
||||
this->inReload = false;
|
||||
|
|
|
@ -37,13 +37,14 @@ public:
|
|||
virtual int rowCount(const QModelIndex&) const override;
|
||||
virtual QVariant data(const QModelIndex &index, int role) const override;
|
||||
|
||||
Q_INVOKABLE void clear();
|
||||
Q_INVOKABLE void clear(bool contentOnly = false);
|
||||
Q_INVOKABLE void initialize(const QVariantMap &chatInformation);
|
||||
Q_INVOKABLE void triggerLoadMoreHistory();
|
||||
Q_INVOKABLE void triggerLoadMoreFuture();
|
||||
Q_INVOKABLE QVariantMap getChatInformation();
|
||||
Q_INVOKABLE QVariantMap getMessage(int index);
|
||||
Q_INVOKABLE int getLastReadMessageIndex();
|
||||
Q_INVOKABLE void setSearchQuery(const QString newSearchQuery);
|
||||
|
||||
QVariantMap smallPhoto() const;
|
||||
qlonglong getChatId() const;
|
||||
|
@ -92,6 +93,8 @@ private:
|
|||
qlonglong chatId;
|
||||
bool inReload;
|
||||
bool inIncrementalUpdate;
|
||||
bool searchModeActive;
|
||||
QString searchQuery;
|
||||
};
|
||||
|
||||
#endif // CHATMODEL_H
|
||||
|
|
|
@ -925,6 +925,20 @@ void TDLibWrapper::importContacts(const QVariantList &contacts)
|
|||
this->sendRequest(requestObject);
|
||||
}
|
||||
|
||||
void TDLibWrapper::searchChatMessages(const qlonglong &chatId, const QString &query, const qlonglong fromMessageId)
|
||||
{
|
||||
LOG("Searching for messages" << chatId << query);
|
||||
QVariantMap requestObject;
|
||||
requestObject.insert(_TYPE, "searchChatMessages");
|
||||
requestObject.insert("chat_id", chatId);
|
||||
requestObject.insert("query", query);
|
||||
requestObject.insert("from_message_id", fromMessageId);
|
||||
requestObject.insert("offset", 0);
|
||||
requestObject.insert("limit", 100);
|
||||
requestObject.insert(_EXTRA, "searchChatMessages");
|
||||
this->sendRequest(requestObject);
|
||||
}
|
||||
|
||||
void TDLibWrapper::searchEmoji(const QString &queryString)
|
||||
{
|
||||
LOG("Searching emoji" << queryString);
|
||||
|
|
|
@ -178,6 +178,7 @@ public:
|
|||
Q_INVOKABLE void getSecretChat(qlonglong secretChatId);
|
||||
Q_INVOKABLE void closeSecretChat(qlonglong secretChatId);
|
||||
Q_INVOKABLE void importContacts(const QVariantList &contacts);
|
||||
Q_INVOKABLE void searchChatMessages(const qlonglong &chatId, const QString &query, const qlonglong fromMessageId = 0);
|
||||
|
||||
// Others (candidates for extraction ;))
|
||||
Q_INVOKABLE void searchEmoji(const QString &queryString);
|
||||
|
|
|
@ -391,6 +391,14 @@
|
|||
<source>Close Chat</source>
|
||||
<translation>Chat schließen</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in Chat</source>
|
||||
<translation>Im Chat suchen</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in chat...</source>
|
||||
<translation>Im Chat suchen...</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ChatSelectionPage</name>
|
||||
|
@ -1027,8 +1035,8 @@
|
|||
<translation>Neuer Chat</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search a chat...</source>
|
||||
<translation>Einen Chat suchen...</translation>
|
||||
<source>Filter your chats...</source>
|
||||
<translation>Ihre Chats filtern...</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
|
|
|
@ -391,6 +391,14 @@
|
|||
<source>Close Chat</source>
|
||||
<translation>Close Chat</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in Chat</source>
|
||||
<translation>Search in Chat</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in chat...</source>
|
||||
<translation>Search in chat...</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ChatSelectionPage</name>
|
||||
|
@ -1027,8 +1035,8 @@
|
|||
<translation>New Chat</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search a chat...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<source>Filter your chats...</source>
|
||||
<translation>Filter your chats...</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
|
|
|
@ -381,6 +381,14 @@
|
|||
<source>Close Chat</source>
|
||||
<translation>Cerrar charla</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in Chat</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in chat...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ChatSelectionPage</name>
|
||||
|
@ -1016,7 +1024,7 @@
|
|||
<translation>Nueva charla</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search a chat...</source>
|
||||
<source>Filter your chats...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
|
|
|
@ -391,6 +391,14 @@
|
|||
<source>Close Chat</source>
|
||||
<translation>Sulje keskustelu</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in Chat</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in chat...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ChatSelectionPage</name>
|
||||
|
@ -1028,7 +1036,7 @@
|
|||
<translation>Uusi keskustelu</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search a chat...</source>
|
||||
<source>Filter your chats...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
|
|
|
@ -381,6 +381,14 @@
|
|||
<source>Close Chat</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in Chat</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in chat...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ChatSelectionPage</name>
|
||||
|
@ -1016,7 +1024,7 @@
|
|||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search a chat...</source>
|
||||
<source>Filter your chats...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
|
|
|
@ -391,6 +391,14 @@
|
|||
<source>Close Chat</source>
|
||||
<translation>Chiudi chat</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in Chat</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in chat...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ChatSelectionPage</name>
|
||||
|
@ -1027,7 +1035,7 @@
|
|||
<translation>Nuova chat</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search a chat...</source>
|
||||
<source>Filter your chats...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
|
|
|
@ -401,6 +401,14 @@
|
|||
<source>Close Chat</source>
|
||||
<translation>Zamknij czat</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in Chat</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in chat...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ChatSelectionPage</name>
|
||||
|
@ -1038,7 +1046,7 @@
|
|||
<translation>Nowy czat</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search a chat...</source>
|
||||
<source>Filter your chats...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
|
|
|
@ -401,6 +401,14 @@
|
|||
<source>Close Chat</source>
|
||||
<translation>Закрыть чат</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in Chat</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in chat...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ChatSelectionPage</name>
|
||||
|
@ -1038,7 +1046,7 @@
|
|||
<translation>Новый Чат</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search a chat...</source>
|
||||
<source>Filter your chats...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
|
|
|
@ -391,6 +391,14 @@
|
|||
<source>Close Chat</source>
|
||||
<translation>Stäng chatten</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in Chat</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in chat...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ChatSelectionPage</name>
|
||||
|
@ -1027,7 +1035,7 @@
|
|||
<translation>Ny chatt</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search a chat...</source>
|
||||
<source>Filter your chats...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
|
|
|
@ -381,6 +381,14 @@
|
|||
<source>Close Chat</source>
|
||||
<translation>关闭对话</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in Chat</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in chat...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ChatSelectionPage</name>
|
||||
|
@ -1016,7 +1024,7 @@
|
|||
<translation>新对话</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search a chat...</source>
|
||||
<source>Filter your chats...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
|
|
|
@ -391,6 +391,14 @@
|
|||
<source>Close Chat</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in Chat</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search in chat...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ChatSelectionPage</name>
|
||||
|
@ -1027,7 +1035,7 @@
|
|||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Search a chat...</source>
|
||||
<source>Filter your chats...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
|
|
Loading…
Reference in a new issue