Change the behaviour when clicking on a space
- When click on a space the space home page is shown, unless the current room is also a member of the new space - When changing to friends or global the first is entered - The global now only contains rooms that are not part of a space - Global is now home
This commit is contained in:
@@ -361,7 +361,7 @@ QVariant RoomListModel::data(const QModelIndex &index, int role) const
|
|||||||
return room->isSpace();
|
return room->isSpace();
|
||||||
}
|
}
|
||||||
if (role == IsChildSpaceRole) {
|
if (role == IsChildSpaceRole) {
|
||||||
return SpaceHierarchyCache::instance().isChildSpace(room->id());
|
return SpaceHierarchyCache::instance().isChild(room->id());
|
||||||
}
|
}
|
||||||
if (role == ReplacementIdRole) {
|
if (role == ReplacementIdRole) {
|
||||||
return room->successorId();
|
return room->successorId();
|
||||||
|
|||||||
@@ -106,7 +106,10 @@ bool SortFilterRoomListModel::filterAcceptsRow(int source_row, const QModelIndex
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_activeSpaceId.isEmpty()) {
|
if (m_activeSpaceId.isEmpty()) {
|
||||||
return acceptRoom;
|
if (!SpaceHierarchyCache::instance().isChild(sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::RoomIdRole).toString())) {
|
||||||
|
return acceptRoom;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
const auto &rooms = SpaceHierarchyCache::instance().getRoomListForSpace(m_activeSpaceId, false);
|
const auto &rooms = SpaceHierarchyCache::instance().getRoomListForSpace(m_activeSpaceId, false);
|
||||||
return std::find(rooms.begin(), rooms.end(), sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::RoomIdRole).toString())
|
return std::find(rooms.begin(), rooms.end(), sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::RoomIdRole).toString())
|
||||||
|
|||||||
@@ -105,6 +105,8 @@ Kirigami.Page {
|
|||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
|
|
||||||
connection: root.connection
|
connection: root.connection
|
||||||
|
|
||||||
|
onSpacesUpdated: sortFilterRoomListModel.invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
Kirigami.Separator {
|
Kirigami.Separator {
|
||||||
@@ -204,12 +206,24 @@ Kirigami.Page {
|
|||||||
sourceModel: root.roomListModel
|
sourceModel: root.roomListModel
|
||||||
roomSortOrder: SortFilterRoomListModel.Categories
|
roomSortOrder: SortFilterRoomListModel.Categories
|
||||||
onLayoutChanged: {
|
onLayoutChanged: {
|
||||||
|
layoutTimer.restart()
|
||||||
listView.currentIndex = sortFilterRoomListModel.mapFromSource(itemSelection.currentIndex).row
|
listView.currentIndex = sortFilterRoomListModel.mapFromSource(itemSelection.currentIndex).row
|
||||||
}
|
}
|
||||||
activeSpaceId: spaceDrawer.selectedSpaceId
|
activeSpaceId: spaceDrawer.selectedSpaceId
|
||||||
mode: spaceDrawer.showDirectChats ? SortFilterRoomListModel.DirectChats : SortFilterRoomListModel.Rooms
|
mode: spaceDrawer.showDirectChats ? SortFilterRoomListModel.DirectChats : SortFilterRoomListModel.Rooms
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HACK: This is the only way to guarantee the correct choice when
|
||||||
|
// there are multiple property changes that invalidate the filter. I.e.
|
||||||
|
// in this case activeSpaceId followed by mode.
|
||||||
|
Timer {
|
||||||
|
id: layoutTimer
|
||||||
|
interval: 100
|
||||||
|
onTriggered: if (spaceDrawer.showDirectChats || spaceDrawer.selectedSpaceId.length < 1) {
|
||||||
|
RoomManager.enterRoom(listView.itemAtIndex(0).currentRoom)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
section {
|
section {
|
||||||
property: "category"
|
property: "category"
|
||||||
delegate: root.collapsed ? foldButton : sectionHeader
|
delegate: root.collapsed ? foldButton : sectionHeader
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ QQC2.Control {
|
|||||||
|
|
||||||
property bool showDirectChats: false
|
property bool showDirectChats: false
|
||||||
|
|
||||||
|
signal spacesUpdated()
|
||||||
|
|
||||||
contentItem: Loader {
|
contentItem: Loader {
|
||||||
id: sidebarColumn
|
id: sidebarColumn
|
||||||
z: 0
|
z: 0
|
||||||
@@ -83,9 +85,9 @@ QQC2.Control {
|
|||||||
Layout.maximumHeight: width - Kirigami.Units.smallSpacing
|
Layout.maximumHeight: width - Kirigami.Units.smallSpacing
|
||||||
Layout.topMargin: Kirigami.Units.smallSpacing / 2
|
Layout.topMargin: Kirigami.Units.smallSpacing / 2
|
||||||
|
|
||||||
text: i18n("All Rooms")
|
text: i18n("Home")
|
||||||
contentItem: Kirigami.Icon {
|
contentItem: Kirigami.Icon {
|
||||||
source: "globe"
|
source: "user-home-symbolic"
|
||||||
}
|
}
|
||||||
|
|
||||||
checked: root.selectedSpaceId === "" && root.showDirectChats === false
|
checked: root.selectedSpaceId === "" && root.showDirectChats === false
|
||||||
@@ -145,6 +147,7 @@ QQC2.Control {
|
|||||||
sourceModel: RoomListModel {
|
sourceModel: RoomListModel {
|
||||||
connection: root.connection
|
connection: root.connection
|
||||||
}
|
}
|
||||||
|
onLayoutChanged: root.spacesUpdated()
|
||||||
}
|
}
|
||||||
onCountChanged: {
|
onCountChanged: {
|
||||||
if (!root.connection.room(root.selectedSpaceId)) {
|
if (!root.connection.room(root.selectedSpaceId)) {
|
||||||
@@ -169,6 +172,9 @@ QQC2.Control {
|
|||||||
|
|
||||||
onSelected: {
|
onSelected: {
|
||||||
root.showDirectChats = false
|
root.showDirectChats = false
|
||||||
|
if (!SpaceHierarchyCache.isSpaceChild(roomId, RoomManager.currentRoom.id) || root.selectedSpaceId == roomId) {
|
||||||
|
RoomManager.enterSpaceHome(currentRoom)
|
||||||
|
}
|
||||||
root.selectedSpaceId = roomId
|
root.selectedSpaceId = roomId
|
||||||
}
|
}
|
||||||
checked: root.selectedSpaceId === roomId
|
checked: root.selectedSpaceId === roomId
|
||||||
|
|||||||
@@ -74,6 +74,11 @@ void SpaceHierarchyCache::removeSpaceFromHierarchy(Quotient::Room *room)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SpaceHierarchyCache::isSpaceChild(const QString &spaceId, const QString &roomId)
|
||||||
|
{
|
||||||
|
return getRoomListForSpace(spaceId, false).contains(roomId);
|
||||||
|
}
|
||||||
|
|
||||||
QList<QString> &SpaceHierarchyCache::getRoomListForSpace(const QString &spaceId, bool updateCache)
|
QList<QString> &SpaceHierarchyCache::getRoomListForSpace(const QString &spaceId, bool updateCache)
|
||||||
{
|
{
|
||||||
if (updateCache) {
|
if (updateCache) {
|
||||||
@@ -82,11 +87,11 @@ QList<QString> &SpaceHierarchyCache::getRoomListForSpace(const QString &spaceId,
|
|||||||
return m_spaceHierarchy[spaceId];
|
return m_spaceHierarchy[spaceId];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SpaceHierarchyCache::isChildSpace(const QString &spaceId) const
|
bool SpaceHierarchyCache::isChild(const QString &roomId) const
|
||||||
{
|
{
|
||||||
const auto childrens = m_spaceHierarchy.values();
|
const auto childrens = m_spaceHierarchy.values();
|
||||||
for (const auto &children : childrens) {
|
for (const auto &children : childrens) {
|
||||||
if (children.contains(spaceId)) {
|
if (children.contains(roomId)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,15 +44,24 @@ public:
|
|||||||
return &instance();
|
return &instance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Whether the given room is a member of the given space.
|
||||||
|
*/
|
||||||
|
Q_INVOKABLE bool isSpaceChild(const QString &spaceId, const QString &roomId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the list of child rooms for the given space ID.
|
* @brief Return the list of child rooms for the given space ID.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] QList<QString> &getRoomListForSpace(const QString &spaceId, bool updateCache);
|
[[nodiscard]] QList<QString> &getRoomListForSpace(const QString &spaceId, bool updateCache);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns whether the space is a child space of any other space.
|
* @brief Returns whether the room is a child space of any space.
|
||||||
|
*
|
||||||
|
* @note We need to do this from the hierarchy as it is not guaranteed that the
|
||||||
|
* child knows it's in a space. See
|
||||||
|
* https://spec.matrix.org/v1.8/client-server-api/#managing-roomsspaces-included-in-a-space
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] bool isChildSpace(const QString &spaceId) const;
|
[[nodiscard]] bool isChild(const QString &roomId) const;
|
||||||
|
|
||||||
NeoChatConnection *connection() const;
|
NeoChatConnection *connection() const;
|
||||||
void setConnection(NeoChatConnection *connection);
|
void setConnection(NeoChatConnection *connection);
|
||||||
|
|||||||
Reference in New Issue
Block a user