Fix duplicate room signals.
This commit is contained in:
parent
1919f0ca8e
commit
43f02c4fa1
|
@ -6,12 +6,16 @@ import Matrique 0.1
|
||||||
import "qrc:/qml/form"
|
import "qrc:/qml/form"
|
||||||
|
|
||||||
Page {
|
Page {
|
||||||
property alias connection: roomListModel.connection
|
property var connection
|
||||||
|
|
||||||
id: page
|
id: page
|
||||||
|
|
||||||
RoomListModel {
|
RoomListModel {
|
||||||
id: roomListModel
|
id: roomListModel
|
||||||
|
|
||||||
|
connection: matriqueController.isLogin ? page.connection : undefined
|
||||||
|
|
||||||
|
onNewMessage: console.log("New message in room " + room.displayName)
|
||||||
}
|
}
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
|
@ -31,7 +35,7 @@ Page {
|
||||||
}
|
}
|
||||||
Layout.maximumWidth: 360
|
Layout.maximumWidth: 360
|
||||||
|
|
||||||
listModel: roomListModel
|
listModel: roomListModel
|
||||||
}
|
}
|
||||||
|
|
||||||
RoomForm {
|
RoomForm {
|
||||||
|
|
|
@ -101,6 +101,10 @@ ApplicationWindow {
|
||||||
connection: matriqueController.connection
|
connection: matriqueController.connection
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Setting {
|
||||||
|
id: settingPage
|
||||||
|
}
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
spacing: 0
|
spacing: 0
|
||||||
|
@ -135,8 +139,7 @@ ApplicationWindow {
|
||||||
|
|
||||||
SideNavButton {
|
SideNavButton {
|
||||||
contentItem: MaterialIcon { icon: "\ue8b8"; color: "white" }
|
contentItem: MaterialIcon { icon: "\ue8b8"; color: "white" }
|
||||||
|
page: settingPage
|
||||||
onClicked: matriqueController.logout()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SideNavButton {
|
SideNavButton {
|
||||||
|
|
|
@ -14,6 +14,8 @@ void RoomListModel::setConnection(QMatrixClient::Connection* connection) {
|
||||||
using QMatrixClient::Room;
|
using QMatrixClient::Room;
|
||||||
m_connection = connection;
|
m_connection = connection;
|
||||||
|
|
||||||
|
if (!connection->accessToken().isEmpty()) doResetModel();
|
||||||
|
|
||||||
connect(connection, &QMatrixClient::Connection::connected, this,
|
connect(connection, &QMatrixClient::Connection::connected, this,
|
||||||
&RoomListModel::doResetModel);
|
&RoomListModel::doResetModel);
|
||||||
connect(connection, &QMatrixClient::Connection::invitedRoom, this,
|
connect(connection, &QMatrixClient::Connection::invitedRoom, this,
|
||||||
|
@ -24,11 +26,10 @@ void RoomListModel::setConnection(QMatrixClient::Connection* connection) {
|
||||||
&RoomListModel::updateRoom);
|
&RoomListModel::updateRoom);
|
||||||
connect(connection, &QMatrixClient::Connection::aboutToDeleteRoom, this,
|
connect(connection, &QMatrixClient::Connection::aboutToDeleteRoom, this,
|
||||||
&RoomListModel::deleteRoom);
|
&RoomListModel::deleteRoom);
|
||||||
|
|
||||||
if (!connection->accessToken().isEmpty()) doResetModel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomListModel::doResetModel() {
|
void RoomListModel::doResetModel() {
|
||||||
|
qDebug() << "Resetting room list model.";
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_rooms.clear();
|
m_rooms.clear();
|
||||||
for (auto r : m_connection->roomMap()) doAddRoom(r);
|
for (auto r : m_connection->roomMap()) doAddRoom(r);
|
||||||
|
@ -48,18 +49,22 @@ void RoomListModel::doAddRoom(QMatrixClient::Room* r) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomListModel::connectRoomSignals(QMatrixClient::Room* room) {
|
void RoomListModel::connectRoomSignals(QMatrixClient::Room* room) {
|
||||||
|
qDebug() << "Connecting signal for room" << room->displayName();
|
||||||
|
|
||||||
connect(room, &QMatrixClient::Room::displaynameChanged, this,
|
connect(room, &QMatrixClient::Room::displaynameChanged, this,
|
||||||
[=] { namesChanged(room); });
|
[=] { namesChanged(room); });
|
||||||
connect(room, &QMatrixClient::Room::unreadMessagesChanged, this,
|
connect(room, &QMatrixClient::Room::unreadMessagesChanged, this,
|
||||||
[=] { unreadMessagesChanged(room); });
|
[=] { unreadMessagesChanged(room); });
|
||||||
connect(room, &QMatrixClient::Room::notificationCountChanged, this,
|
connect(room, &QMatrixClient::Room::notificationCountChanged, this,
|
||||||
[=] { unreadMessagesChanged(room); });
|
[=] { unreadMessagesChanged(room); });
|
||||||
// connect(room, &QMatrixClient::Room::unreadMessagesChanged, this,
|
|
||||||
// &RoomListModel::highlightCountChanged);
|
|
||||||
connect(room, &QMatrixClient::Room::joinStateChanged, this,
|
connect(room, &QMatrixClient::Room::joinStateChanged, this,
|
||||||
[=] { refresh(room); });
|
[=] { refresh(room); });
|
||||||
connect(room, &QMatrixClient::Room::avatarChanged, this,
|
connect(room, &QMatrixClient::Room::avatarChanged, this,
|
||||||
[=] { refresh(room, {AvatarRole}); });
|
[=] { refresh(room, {AvatarRole}); });
|
||||||
|
|
||||||
|
connect(
|
||||||
|
room, &QMatrixClient::Room::aboutToAddNewMessages, this,
|
||||||
|
[=](QMatrixClient::RoomEventsRange events) { emit newMessage(room); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomListModel::updateRoom(QMatrixClient::Room* room,
|
void RoomListModel::updateRoom(QMatrixClient::Room* room,
|
||||||
|
|
|
@ -51,7 +51,7 @@ class RoomListModel : public QAbstractListModel {
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void connectionChanged();
|
void connectionChanged();
|
||||||
void highlightCountChanged(QMatrixClient::Room* room);
|
void newMessage(QMatrixClient::Room* room);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ROOMLISTMODEL_H
|
#endif // ROOMLISTMODEL_H
|
||||||
|
|
Loading…
Reference in New Issue