diff --git a/qml/pages/OverviewPage.qml b/qml/pages/OverviewPage.qml index 43fde30..f4cb319 100644 --- a/qml/pages/OverviewPage.qml +++ b/qml/pages/OverviewPage.qml @@ -50,7 +50,7 @@ Page { Timer { id: chatListSorterTimer - interval: 1000 + interval: 100 running: false repeat: false onTriggered: { @@ -131,6 +131,10 @@ Page { chatListSorterTimer.stop(); chatListSorterTimer.start(); } + onChatLastMessageUpdated: { + chatListSorterTimer.stop(); + chatListSorterTimer.start(); + } } Component.onCompleted: { diff --git a/src/chatlistmodel.cpp b/src/chatlistmodel.cpp index bad3d51..6e27101 100644 --- a/src/chatlistmodel.cpp +++ b/src/chatlistmodel.cpp @@ -5,7 +5,7 @@ ChatListModel::ChatListModel(TDLibWrapper *tdLibWrapper) { this->tdLibWrapper = tdLibWrapper; connect(this->tdLibWrapper, SIGNAL(newChatDiscovered(QString, QVariantMap)), this, SLOT(handleChatDiscovered(QString, QVariantMap))); - connect(this->tdLibWrapper, SIGNAL(chatLastMessageUpdated(QString, QVariantMap)), this, SLOT(handleChatLastMessageUpdated(QString, QVariantMap))); + connect(this->tdLibWrapper, SIGNAL(chatLastMessageUpdated(QString, QString, QVariantMap)), this, SLOT(handleChatLastMessageUpdated(QString, QString, QVariantMap))); connect(this->tdLibWrapper, SIGNAL(chatOrderUpdated(QString, QString)), this, SLOT(handleChatOrderUpdated(QString, QString))); } @@ -58,7 +58,7 @@ void ChatListModel::updateSorting() this->chatListMutex.lock(); qDebug() << "[ChatListModel] List sorting will be updated..."; - beginResetModel(); + emit layoutAboutToBeChanged(); std::sort(this->chatList.begin(), this->chatList.end(), compareChats); this->chatIndexMap.clear(); @@ -66,7 +66,7 @@ void ChatListModel::updateSorting() QString currentChatId = this->chatList.at(i).toMap().value("id").toString(); this->chatIndexMap.insert(currentChatId, i); } - endResetModel(); + emit layoutChanged(); this->chatListMutex.unlock(); } @@ -79,13 +79,14 @@ void ChatListModel::handleChatDiscovered(const QString &chatId, const QVariantMa this->chatListMutex.unlock(); } -void ChatListModel::handleChatLastMessageUpdated(const QString &chatId, const QVariantMap &lastMessage) +void ChatListModel::handleChatLastMessageUpdated(const QString &chatId, const QString &order, const QVariantMap &lastMessage) { this->chatListMutex.lock(); int chatIndex = this->chatIndexMap.value(chatId).toInt(); qDebug() << "[ChatListModel] Updating last message for chat " << chatId << " at index " << chatIndex; QVariantMap currentChat = this->chatList.value(chatIndex).toMap(); currentChat.insert("last_message", lastMessage); + currentChat.insert("order", order); this->chatList.replace(chatIndex, currentChat); emit dataChanged(this->index(chatIndex), this->index(chatIndex)); this->chatListMutex.unlock(); diff --git a/src/chatlistmodel.h b/src/chatlistmodel.h index 60ce5b8..b83fc1a 100644 --- a/src/chatlistmodel.h +++ b/src/chatlistmodel.h @@ -21,7 +21,7 @@ public: public slots: void handleChatDiscovered(const QString &chatId, const QVariantMap &chatInformation); - void handleChatLastMessageUpdated(const QString &chatId, const QVariantMap &lastMessage); + void handleChatLastMessageUpdated(const QString &chatId, const QString &order, const QVariantMap &lastMessage); void handleChatOrderUpdated(const QString &chatId, const QString &order); private: diff --git a/src/tdlibreceiver.cpp b/src/tdlibreceiver.cpp index 10ba42b..5329fec 100644 --- a/src/tdlibreceiver.cpp +++ b/src/tdlibreceiver.cpp @@ -141,8 +141,8 @@ void TDLibReceiver::processUpdateUnreadChatCount(const QVariantMap &receivedInfo void TDLibReceiver::processUpdateChatLastMessage(const QVariantMap &receivedInformation) { QVariantMap lastMessage = receivedInformation.value("last_message").toMap(); - qDebug() << "[TDLibReceiver] Last message of chat " << receivedInformation.value("chat_id").toString() << " updated, content: " << lastMessage.value("content").toString(); - emit chatLastMessageUpdated(receivedInformation.value("chat_id").toString(), lastMessage); + qDebug() << "[TDLibReceiver] Last message of chat " << receivedInformation.value("chat_id").toString() << " updated, order " << receivedInformation.value("order").toString() << " content: " << lastMessage.value("content").toString(); + emit chatLastMessageUpdated(receivedInformation.value("chat_id").toString(), receivedInformation.value("order").toString(), lastMessage); } void TDLibReceiver::processUpdateChatOrder(const QVariantMap &receivedInformation) diff --git a/src/tdlibreceiver.h b/src/tdlibreceiver.h index e9a8d72..99cfa68 100644 --- a/src/tdlibreceiver.h +++ b/src/tdlibreceiver.h @@ -45,7 +45,7 @@ signals: void newChatDiscovered(const QVariantMap &chatInformation); void unreadMessageCountUpdated(const QVariantMap &messageCountInformation); void unreadChatCountUpdated(const QVariantMap &chatCountInformation); - void chatLastMessageUpdated(const QString &chatId, const QVariantMap &lastMessage); + void chatLastMessageUpdated(const QString &chatId, const QString &order, const QVariantMap &lastMessage); void chatOrderUpdated(const QString &chatId, const QString &order); private: diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index e70ea6e..65bcdd8 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -45,7 +45,7 @@ TDLibWrapper::TDLibWrapper(QObject *parent) : QObject(parent) connect(this->tdLibReceiver, SIGNAL(newChatDiscovered(QVariantMap)), this, SLOT(handleNewChatDiscovered(QVariantMap))); connect(this->tdLibReceiver, SIGNAL(unreadMessageCountUpdated(QVariantMap)), this, SLOT(handleUnreadMessageCountUpdated(QVariantMap))); connect(this->tdLibReceiver, SIGNAL(unreadChatCountUpdated(QVariantMap)), this, SLOT(handleUnreadChatCountUpdated(QVariantMap))); - connect(this->tdLibReceiver, SIGNAL(chatLastMessageUpdated(QString, QVariantMap)), this, SLOT(handleChatLastMessageUpdated(QString, QVariantMap))); + connect(this->tdLibReceiver, SIGNAL(chatLastMessageUpdated(QString, QString, QVariantMap)), this, SLOT(handleChatLastMessageUpdated(QString, QString, QVariantMap))); connect(this->tdLibReceiver, SIGNAL(chatOrderUpdated(QString, QString)), this, SLOT(handleChatOrderUpdated(QString, QString))); this->tdLibReceiver->start(); @@ -277,9 +277,9 @@ void TDLibWrapper::handleUnreadChatCountUpdated(const QVariantMap &chatCountInfo } } -void TDLibWrapper::handleChatLastMessageUpdated(const QString &chatId, const QVariantMap &lastMessage) +void TDLibWrapper::handleChatLastMessageUpdated(const QString &chatId, const QString &order, const QVariantMap &lastMessage) { - emit chatLastMessageUpdated(chatId, lastMessage); + emit chatLastMessageUpdated(chatId, order, lastMessage); } void TDLibWrapper::handleChatOrderUpdated(const QString &chatId, const QString &order) diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index 58677b5..bc6a746 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -83,7 +83,7 @@ signals: void newChatDiscovered(const QString &chatId, const QVariantMap &chatInformation); void unreadMessageCountUpdated(const QVariantMap &messageCountInformation); void unreadChatCountUpdated(const QVariantMap &chatCountInformation); - void chatLastMessageUpdated(const QString &chatId, const QVariantMap &lastMessage); + void chatLastMessageUpdated(const QString &chatId, const QString &order, const QVariantMap &lastMessage); void chatOrderUpdated(const QString &chatId, const QString &order); public slots: @@ -96,7 +96,7 @@ public slots: void handleNewChatDiscovered(const QVariantMap &chatInformation); void handleUnreadMessageCountUpdated(const QVariantMap &messageCountInformation); void handleUnreadChatCountUpdated(const QVariantMap &chatCountInformation); - void handleChatLastMessageUpdated(const QString &chatId, const QVariantMap &lastMessage); + void handleChatLastMessageUpdated(const QString &chatId, const QString &order, const QVariantMap &lastMessage); void handleChatOrderUpdated(const QString &chatId, const QString &order); private: void *tdLibClient;