When clicking on the account switcher on the bottom of the sidebar
automatically go to the last-used chat from that account Fix #356
This commit is contained in:
@@ -7,6 +7,8 @@
|
|||||||
#include "neochatconfig.h"
|
#include "neochatconfig.h"
|
||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
#include <KConfigGroup>
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
#include <csapi/joining.h>
|
#include <csapi/joining.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -15,7 +17,9 @@ RoomManager::RoomManager(QObject *parent)
|
|||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_currentRoom(nullptr)
|
, m_currentRoom(nullptr)
|
||||||
, m_lastCurrentRoom(nullptr)
|
, m_lastCurrentRoom(nullptr)
|
||||||
{}
|
, m_config(KConfig("data", KConfig::SimpleConfig, QStandardPaths::AppDataLocation))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
RoomManager::~RoomManager()
|
RoomManager::~RoomManager()
|
||||||
{}
|
{}
|
||||||
@@ -77,14 +81,36 @@ void RoomManager::loadInitialRoom()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!NeoChatConfig::self()->openRoom().isEmpty()) {
|
openRoomForActiveConnection();
|
||||||
|
|
||||||
|
connect(&Controller::instance(), &Controller::activeConnectionChanged,
|
||||||
|
this, &RoomManager::openRoomForActiveConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RoomManager::openRoomForActiveConnection()
|
||||||
|
{
|
||||||
|
// Read from last open room
|
||||||
|
KConfigGroup lastOpenRoomGroup(&m_config, "LastOpenRoom");
|
||||||
|
QString roomId = lastOpenRoomGroup.readEntry(Controller::instance().activeConnection()->userId(), QString());
|
||||||
|
|
||||||
|
// TODO remove legacy check at some point.
|
||||||
|
if (roomId.isEmpty()) {
|
||||||
|
roomId = NeoChatConfig::self()->openRoom();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!roomId.isEmpty()) {
|
||||||
// Here we can cast because the controller has been configured to
|
// Here we can cast because the controller has been configured to
|
||||||
// return NeoChatRoom instead of simple Quotient::Room
|
// return NeoChatRoom instead of simple Quotient::Room
|
||||||
const auto room = qobject_cast<NeoChatRoom *>(
|
const auto room = qobject_cast<NeoChatRoom *>(
|
||||||
Controller::instance().activeConnection()->room(NeoChatConfig::self()->openRoom()));
|
Controller::instance().activeConnection()->room(roomId));
|
||||||
m_lastCurrentRoom = std::exchange(m_currentRoom, room);
|
|
||||||
Q_EMIT currentRoomChanged();
|
if (room) {
|
||||||
Q_EMIT pushRoom(room, QString());
|
m_lastCurrentRoom = std::exchange(m_currentRoom, room);
|
||||||
|
Q_EMIT currentRoomChanged();
|
||||||
|
Q_EMIT pushRoom(room, QString());
|
||||||
|
} else {
|
||||||
|
Q_EMIT pushWelcomePage();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Q_EMIT pushWelcomePage();
|
Q_EMIT pushWelcomePage();
|
||||||
}
|
}
|
||||||
@@ -102,8 +128,10 @@ void RoomManager::enterRoom(NeoChatRoom *room)
|
|||||||
Q_EMIT currentRoomChanged();
|
Q_EMIT currentRoomChanged();
|
||||||
Q_EMIT replaceRoom(m_currentRoom, QString());
|
Q_EMIT replaceRoom(m_currentRoom, QString());
|
||||||
|
|
||||||
NeoChatConfig::self()->setOpenRoom(room->id());
|
// Save last open room
|
||||||
NeoChatConfig::self()->save();
|
KConfigGroup lastOpenRoomGroup(&m_config, "LastOpenRoom");
|
||||||
|
lastOpenRoomGroup.writeEntry(Controller::instance().activeConnection()->userId(), room->id());
|
||||||
|
lastOpenRoomGroup.config()->sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomManager::openWindow(NeoChatRoom *room)
|
void RoomManager::openWindow(NeoChatRoom *room)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <uriresolver.h>
|
#include <uriresolver.h>
|
||||||
|
#include <KConfig>
|
||||||
|
|
||||||
class NeoChatRoom;
|
class NeoChatRoom;
|
||||||
|
|
||||||
@@ -96,9 +97,12 @@ Q_SIGNALS:
|
|||||||
void warning(const QString &title, const QString &message);
|
void warning(const QString &title, const QString &message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void openRoomForActiveConnection();
|
||||||
|
|
||||||
NeoChatRoom *m_currentRoom;
|
NeoChatRoom *m_currentRoom;
|
||||||
NeoChatRoom *m_lastCurrentRoom;
|
NeoChatRoom *m_lastCurrentRoom;
|
||||||
QString m_arg;
|
QString m_arg;
|
||||||
|
KConfig m_config;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_GLOBAL_STATIC(RoomManager, roomManager)
|
Q_GLOBAL_STATIC(RoomManager, roomManager)
|
||||||
|
|||||||
Reference in New Issue
Block a user