diff --git a/smsapp/conversationlistmodel.cpp b/smsapp/conversationlistmodel.cpp index ade64d485..49610fa03 100644 --- a/smsapp/conversationlistmodel.cpp +++ b/smsapp/conversationlistmodel.cpp @@ -67,6 +67,7 @@ void ConversationListModel::setDeviceId(const QString& deviceId) } m_deviceId = deviceId; + Q_EMIT deviceIdChanged(); // This method still gets called *with a valid deviceID* when the device is not connected while the component is setting up // Detect that case and don't do anything. diff --git a/smsapp/conversationlistmodel.h b/smsapp/conversationlistmodel.h index 7193e6dd9..61885be9e 100644 --- a/smsapp/conversationlistmodel.h +++ b/smsapp/conversationlistmodel.h @@ -68,7 +68,7 @@ class ConversationListModel : public QStandardItemModel { Q_OBJECT - Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId) + Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged) public: ConversationListModel(QObject* parent = nullptr); @@ -92,6 +92,9 @@ public Q_SLOTS: void createRowFromMessage(const QVariantMap& message); void printDBusError(const QDBusError& error); +Q_SIGNALS: + void deviceIdChanged(); + private: /** * Get all conversations currently known by the conversationsInterface, if any diff --git a/smsapp/conversationmodel.cpp b/smsapp/conversationmodel.cpp index ee4f26e22..085746f34 100644 --- a/smsapp/conversationmodel.cpp +++ b/smsapp/conversationmodel.cpp @@ -51,7 +51,8 @@ void ConversationModel::setThreadId(const qint64& threadId) m_threadId = threadId; clear(); - if (threadId != INVALID_THREAD_ID) { + knownMessageIDs.clear(); + if (m_threadId != INVALID_THREAD_ID && m_deviceId != "") { requestMoreMessages(); } } diff --git a/smsapp/qml/ConversationList.qml b/smsapp/qml/ConversationList.qml index c405d2278..038b66f72 100644 --- a/smsapp/qml/ConversationList.qml +++ b/smsapp/qml/ConversationList.qml @@ -55,7 +55,7 @@ Kirigami.ScrollablePage readonly property QtObject device: devicesCombo.currentIndex >= 0 ? devicesModel.data(devicesModel.index(devicesCombo.currentIndex, 0), DevicesModel.DeviceRole) : null readonly property alias lastDeviceId: conversationListModel.deviceId - Component { + ConversationDisplay { id: chatView ConversationDisplay { deviceId: page.lastDeviceId @@ -122,7 +122,17 @@ Kirigami.ScrollablePage conversationId: model.conversationId, }) } - onClicked: { startChat(); } + onClicked: { + startChat(); + view.currentIndex = index + } + // Keep the currently-open chat highlighted even if this element is not focused + highlighted: chatView.conversationId == model.conversationId + } + + Component.onCompleted: { + currentIndex = -1 + focus = true } }