diff --git a/matrix/roomlistmodel.cpp b/matrix/roomlistmodel.cpp index 862d41c..e5d346b 100644 --- a/matrix/roomlistmodel.cpp +++ b/matrix/roomlistmodel.cpp @@ -9,16 +9,23 @@ RoomListModel::RoomListModel(QObject* parent) : QAbstractListModel(parent) {} RoomListModel::~RoomListModel() {} void RoomListModel::setConnection(QMatrixClient::Connection* connection) { + Q_ASSERT(connection); + + using QMatrixClient::Connection; + using QMatrixClient::Room; beginResetModel(); m_connection = connection; - m_rooms.clear(); - connect(connection, &QMatrixClient::Connection::newRoom, this, - &RoomListModel::addRoom); - for (QMatrixClient::Room* room : connection->roomMap().values()) { - connect(room, &QMatrixClient::Room::namesChanged, this, - &RoomListModel::namesChanged); - m_rooms.append(room); - } + connect(connection, &Connection::loggedOut, this, + [=] { setConnection(connection); }); +// connect(connection, &Connection::invitedRoom, this, +// &RoomListModel::updateRoom); +// connect(connection, &Connection::joinedRoom, this, +// &RoomListModel::updateRoom); +// connect(connection, &Connection::leftRoom, this, &RoomListModel::updateRoom); + connect(connection, &Connection::aboutToDeleteRoom, this, + &RoomListModel::deleteRoom); + + for (auto r : connection->roomMap()) addRoom(r); endResetModel(); } @@ -32,6 +39,15 @@ void RoomListModel::addRoom(QMatrixClient::Room* room) { endInsertRows(); } +void RoomListModel::deleteRoom(QMatrixClient::Room* room) { + const auto it = std::find(m_rooms.begin(), m_rooms.end(), room); + if (it == m_rooms.end()) return; // Already deleted, nothing to do + const int row = it - m_rooms.begin(); + beginRemoveRows(QModelIndex(), row, row); + m_rooms.erase(it); + endRemoveRows(); +} + int RoomListModel::rowCount(const QModelIndex& parent) const { if (parent.isValid()) return 0; return m_rooms.count(); diff --git a/matrix/roomlistmodel.h b/matrix/roomlistmodel.h index 177b463..f476471 100644 --- a/matrix/roomlistmodel.h +++ b/matrix/roomlistmodel.h @@ -30,6 +30,7 @@ class RoomListModel : public QAbstractListModel { void namesChanged(QMatrixClient::Room* room); void unreadMessagesChanged(QMatrixClient::Room* room); void addRoom(QMatrixClient::Room* room); + void deleteRoom(QMatrixClient::Room* room); private: QMatrixClient::Connection* m_connection = nullptr; diff --git a/qml/form/RoomForm.qml b/qml/form/RoomForm.qml index 022a282..d7f0f76 100644 --- a/qml/form/RoomForm.qml +++ b/qml/form/RoomForm.qml @@ -144,8 +144,37 @@ Item { ScrollBar.vertical: ScrollBar { /*anchors.left: messageListView.right*/ } - onAtYBeginningChanged: { - if(currentRoom && atYBeginning) currentRoom.getPreviousContent(50) + Behavior on contentY { + PropertyAnimation { easing.type: Easing.InOutCubic; duration: 200 } + } + + RoundButton { + id: goTopFab + width: height + height: !parent.atYEnd ? 64 : 0 + + anchors.verticalCenter: parent.bottom + anchors.verticalCenterOffset: -48 + anchors.horizontalCenter: parent.right + anchors.horizontalCenterOffset: -48 + + contentItem: MaterialIcon { + anchors.fill: parent + icon: "\ue313" + color: "white" + } + + opacity: hovered ? 1 : 0.5 + Material.background: Qt.lighter(Material.accent) + + onClicked: parent.positionViewAtBeginning() + + Behavior on height { + PropertyAnimation { easing.type: Easing.InOutCubic; duration: 200 } + } + Behavior on opacity { + PropertyAnimation { easing.type: Easing.InOutCubic; duration: 200 } + } } }