Activate window that already has the room open if possible

This commit is contained in:
Nicolas Werner 2022-05-07 19:03:58 +02:00
parent 62bf1b253e
commit 87070289fd
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
5 changed files with 22 additions and 9 deletions

View file

@ -82,7 +82,7 @@ Page {
minimumHeight: 150
palette: Nheko.colors
color: Nheko.colors.window
title: room.roomName
title: room.plainRoomName
modality: Qt.NonModal
flags: Qt.Window | Qt.WindowCloseButtonHint | Qt.WindowTitleHint

View file

@ -152,16 +152,26 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QObject *parent)
this,
[this](const QString &roomid, const QString &eventid) {
Q_UNUSED(eventid)
view_manager_->rooms()->setCurrentRoom(roomid);
MainWindow::instance()->requestActivate();
auto exWin = MainWindow::instance()->windowForRoom(roomid);
if (exWin) {
exWin->requestActivate();
} else {
view_manager_->rooms()->setCurrentRoom(roomid);
MainWindow::instance()->requestActivate();
}
});
connect(&notificationsManager,
&NotificationsManager::sendNotificationReply,
this,
[this](const QString &roomid, const QString &eventid, const QString &body) {
view_manager_->rooms()->setCurrentRoom(roomid);
view_manager_->queueReply(roomid, eventid, body);
MainWindow::instance()->requestActivate();
auto exWin = MainWindow::instance()->windowForRoom(roomid);
if (exWin) {
exWin->requestActivate();
} else {
view_manager_->rooms()->setCurrentRoom(roomid);
MainWindow::instance()->requestActivate();
}
});
connect(

View file

@ -445,8 +445,8 @@ MainWindow::removePerRoomWindow(const QString &room, QWindow *window)
{
roomWindows_.remove(room, window);
}
const QWindow *
MainWindow::windowForRoom(const QString &room) const
QWindow *
MainWindow::windowForRoom(const QString &room)
{
auto currMainWindowRoom = ChatPage::instance()->timelineManager()->rooms()->currentRoom();
if ((currMainWindowRoom && currMainWindowRoom->roomId() == room) ||

View file

@ -61,7 +61,7 @@ public:
Q_INVOKABLE void addPerRoomWindow(const QString &room, QWindow *window);
Q_INVOKABLE void removePerRoomWindow(const QString &room, QWindow *window);
const QWindow *windowForRoom(const QString &room) const;
QWindow *windowForRoom(const QString &room);
QString focusedRoom() const;
protected:

View file

@ -222,7 +222,10 @@ void
TimelineViewManager::showEvent(const QString &room_id, const QString &event_id)
{
if (auto room = rooms_->getRoomById(room_id)) {
if (rooms_->currentRoom() != room) {
auto exWin = MainWindow::instance()->windowForRoom(room_id);
if (exWin) {
exWin->requestActivate();
} else if (rooms_->currentRoom() != room) {
rooms_->setCurrentRoom(room_id);
MainWindow::instance()->requestActivate();
nhlog::ui()->info("Activated room {}", room_id.toStdString());