Refactor room leaving

The old code has a small bug where the room would not be left in certain
conditions.
This commit is contained in:
Tobias Fella
2021-08-10 18:47:21 +02:00
committed by Carl Schwan
parent 21bd5fa94e
commit ecc639fb0a
2 changed files with 14 additions and 7 deletions

View File

@@ -28,6 +28,17 @@ Kirigami.ScrollablePage {
title: currentRoom.displayName
Connections {
target: RoomManager
function onCurrentRoomChanged() {
if(!RoomManager.currentRoom) {
if(pageStack.lastItem == page) {
pageStack.pop()
}
}
}
}
signal switchRoomUp()
signal switchRoomDown()

View File

@@ -215,18 +215,14 @@ void RoomManager::reset()
void RoomManager::leaveRoom(NeoChatRoom *room)
{
// close the room and open the last open room if it exist
// other open welcome page.
if(m_lastCurrentRoom && room->id() == m_lastCurrentRoom->id()) {
m_lastCurrentRoom = nullptr;
}
if (m_currentRoom && m_currentRoom->id() == room->id()) {
if (!m_lastCurrentRoom) {
Q_EMIT pushWelcomePage();
return;
}
m_currentRoom = m_lastCurrentRoom;
m_lastCurrentRoom = nullptr;
Q_EMIT currentRoomChanged();
Q_EMIT replaceRoom(m_lastCurrentRoom, QString());
}
room->forget();