Automatically enter room when joining it

Related to #352 but needs an additional Quotient patch to works
This commit is contained in:
Carl Schwan
2021-05-07 22:37:16 +02:00
parent 1615695b21
commit 5f8795c41f
5 changed files with 20 additions and 14 deletions

View File

@@ -110,7 +110,7 @@ Q_SIGNALS:
/// Either when a new room was created, a direct chat was started /// Either when a new room was created, a direct chat was started
/// or a group chat was joined. The UI will react to this signal /// or a group chat was joined. The UI will react to this signal
/// and switch to the newly joined room. /// and switch to the newly joined room.
void roomJoined(const QString &roomName); void roomJoined(const QString &room);
/// Error occurred because of server or bug in NeoChat /// Error occurred because of server or bug in NeoChat
void globalErrorOccured(QString error, QString detail); void globalErrorOccured(QString error, QString detail);

View File

@@ -104,13 +104,13 @@ int main(int argc, char *argv[])
KDBusService service(KDBusService::Unique); KDBusService service(KDBusService::Unique);
service.connect(&service, service.connect(&service,
&KDBusService::activateRequested, &KDBusService::activateRequested,
roomManager, &RoomManager::instance(),
[](const QStringList &arguments, const QString &workingDirectory) { [](const QStringList &arguments, const QString &workingDirectory) {
Q_UNUSED(workingDirectory); Q_UNUSED(workingDirectory);
auto args = arguments; auto args = arguments;
args.removeFirst(); args.removeFirst();
for (const auto &arg : args) { for (const auto &arg : args) {
roomManager->openResource(arg); RoomManager::instance().openResource(arg);
} }
}); });
#endif #endif
@@ -131,7 +131,7 @@ int main(int argc, char *argv[])
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "Controller", &Controller::instance()); qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "Controller", &Controller::instance());
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "Clipboard", &clipboard); qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "Clipboard", &clipboard);
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "Config", config); qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "Config", config);
qmlRegisterSingletonInstance<RoomManager>("org.kde.neochat", 1, 0, "RoomManager", roomManager); qmlRegisterSingletonInstance<RoomManager>("org.kde.neochat", 1, 0, "RoomManager", &RoomManager::instance());
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "FileType", &fileTypeSingleton); qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "FileType", &fileTypeSingleton);
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "LoginHelper", login); qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "LoginHelper", login);
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "ChatBoxHelper", &chatBoxHelper); qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "ChatBoxHelper", &chatBoxHelper);
@@ -197,7 +197,7 @@ int main(int argc, char *argv[])
} }
if (parser.positionalArguments().length() > 0) { if (parser.positionalArguments().length() > 0) {
roomManager->setUrlArgument(parser.positionalArguments()[0]); RoomManager::instance().setUrlArgument(parser.positionalArguments()[0]);
} }
#ifdef HAVE_KDBUSADDONS #ifdef HAVE_KDBUSADDONS

View File

@@ -24,6 +24,7 @@
#include "csapi/notifications.h" #include "csapi/notifications.h"
#include "notificationsmanager.h" #include "notificationsmanager.h"
#include "roommanager.h"
#ifndef Q_OS_ANDROID #ifndef Q_OS_ANDROID
bool useUnityCounter() bool useUnityCounter()
@@ -288,6 +289,7 @@ void RoomListModel::updateRoom(Room *room, Room *prev)
} else { } else {
beginInsertRows(QModelIndex(), m_rooms.count(), m_rooms.count()); beginInsertRows(QModelIndex(), m_rooms.count(), m_rooms.count());
doAddRoom(newRoom); doAddRoom(newRoom);
RoomManager::instance().enterRoom(qobject_cast<NeoChatRoom *>(newRoom));
endInsertRows(); endInsertRows();
} }
} }

View File

@@ -24,6 +24,12 @@ RoomManager::RoomManager(QObject *parent)
RoomManager::~RoomManager() RoomManager::~RoomManager()
{} {}
RoomManager &RoomManager::instance()
{
static RoomManager _instance;
return _instance;
}
NeoChatRoom *RoomManager::currentRoom() const NeoChatRoom *RoomManager::currentRoom() const
{ {
return m_currentRoom; return m_currentRoom;
@@ -118,15 +124,14 @@ void RoomManager::openRoomForActiveConnection()
void RoomManager::enterRoom(NeoChatRoom *room) void RoomManager::enterRoom(NeoChatRoom *room)
{ {
if (!m_currentRoom) {
m_lastCurrentRoom = std::exchange(m_currentRoom, room);
Q_EMIT currentRoomChanged();
Q_EMIT pushRoom(room, QString());
}
m_lastCurrentRoom = std::exchange(m_currentRoom, room); m_lastCurrentRoom = std::exchange(m_currentRoom, room);
Q_EMIT currentRoomChanged(); Q_EMIT currentRoomChanged();
Q_EMIT replaceRoom(m_currentRoom, QString());
if (!m_currentRoom) {
Q_EMIT pushRoom(room, QString());
} else {
Q_EMIT replaceRoom(m_currentRoom, QString());
}
// Save last open room // Save last open room
KConfigGroup lastOpenRoomGroup(&m_config, "LastOpenRoom"); KConfigGroup lastOpenRoomGroup(&m_config, "LastOpenRoom");

View File

@@ -31,6 +31,7 @@ class RoomManager : public QObject, public UriResolverBase
public: public:
explicit RoomManager(QObject *parent = nullptr); explicit RoomManager(QObject *parent = nullptr);
virtual ~RoomManager(); virtual ~RoomManager();
static RoomManager &instance();
/// Load the last opened room or the welcome page. /// Load the last opened room or the welcome page.
Q_INVOKABLE void loadInitialRoom(); Q_INVOKABLE void loadInitialRoom();
@@ -104,5 +105,3 @@ private:
QString m_arg; QString m_arg;
KConfig m_config; KConfig m_config;
}; };
Q_GLOBAL_STATIC(RoomManager, roomManager)