diff --git a/qml/Room.qml b/qml/Room.qml index 6926d82..819a269 100644 --- a/qml/Room.qml +++ b/qml/Room.qml @@ -6,12 +6,16 @@ import Matrique 0.1 import "qrc:/qml/form" Page { - property alias connection: roomListModel.connection + property var connection id: page RoomListModel { id: roomListModel + + connection: matriqueController.isLogin ? page.connection : undefined + + onNewMessage: console.log("New message in room " + room.displayName) } RowLayout { @@ -31,7 +35,7 @@ Page { } Layout.maximumWidth: 360 - listModel: roomListModel + listModel: roomListModel } RoomForm { diff --git a/qml/main.qml b/qml/main.qml index 53bbfb8..1472d7b 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -101,6 +101,10 @@ ApplicationWindow { connection: matriqueController.connection } + Setting { + id: settingPage + } + RowLayout { anchors.fill: parent spacing: 0 @@ -135,8 +139,7 @@ ApplicationWindow { SideNavButton { contentItem: MaterialIcon { icon: "\ue8b8"; color: "white" } - - onClicked: matriqueController.logout() + page: settingPage } SideNavButton { diff --git a/src/roomlistmodel.cpp b/src/roomlistmodel.cpp index cb904e1..f3e27c5 100644 --- a/src/roomlistmodel.cpp +++ b/src/roomlistmodel.cpp @@ -14,6 +14,8 @@ void RoomListModel::setConnection(QMatrixClient::Connection* connection) { using QMatrixClient::Room; m_connection = connection; + if (!connection->accessToken().isEmpty()) doResetModel(); + connect(connection, &QMatrixClient::Connection::connected, this, &RoomListModel::doResetModel); connect(connection, &QMatrixClient::Connection::invitedRoom, this, @@ -24,11 +26,10 @@ void RoomListModel::setConnection(QMatrixClient::Connection* connection) { &RoomListModel::updateRoom); connect(connection, &QMatrixClient::Connection::aboutToDeleteRoom, this, &RoomListModel::deleteRoom); - - if (!connection->accessToken().isEmpty()) doResetModel(); } void RoomListModel::doResetModel() { + qDebug() << "Resetting room list model."; beginResetModel(); m_rooms.clear(); for (auto r : m_connection->roomMap()) doAddRoom(r); @@ -48,18 +49,22 @@ void RoomListModel::doAddRoom(QMatrixClient::Room* r) { } void RoomListModel::connectRoomSignals(QMatrixClient::Room* room) { + qDebug() << "Connecting signal for room" << room->displayName(); + connect(room, &QMatrixClient::Room::displaynameChanged, this, [=] { namesChanged(room); }); connect(room, &QMatrixClient::Room::unreadMessagesChanged, this, [=] { unreadMessagesChanged(room); }); connect(room, &QMatrixClient::Room::notificationCountChanged, this, [=] { unreadMessagesChanged(room); }); - // connect(room, &QMatrixClient::Room::unreadMessagesChanged, this, - // &RoomListModel::highlightCountChanged); connect(room, &QMatrixClient::Room::joinStateChanged, this, [=] { refresh(room); }); connect(room, &QMatrixClient::Room::avatarChanged, this, [=] { refresh(room, {AvatarRole}); }); + + connect( + room, &QMatrixClient::Room::aboutToAddNewMessages, this, + [=](QMatrixClient::RoomEventsRange events) { emit newMessage(room); }); } void RoomListModel::updateRoom(QMatrixClient::Room* room, diff --git a/src/roomlistmodel.h b/src/roomlistmodel.h index 2667450..a35c661 100644 --- a/src/roomlistmodel.h +++ b/src/roomlistmodel.h @@ -51,7 +51,7 @@ class RoomListModel : public QAbstractListModel { signals: void connectionChanged(); - void highlightCountChanged(QMatrixClient::Room* room); + void newMessage(QMatrixClient::Room* room); }; #endif // ROOMLISTMODEL_H