diff --git a/src/controller.cpp b/src/controller.cpp index 5278c23d9..788c9c98a 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -382,20 +382,6 @@ void Controller::joinRoom(const QString &alias) RoomManager::instance().joinRoom(m_connection, alias, QStringList{knownServer}); } -void Controller::openOrCreateDirectChat(User *user) -{ - const auto existing = activeConnection()->directChats(); - - if (existing.contains(user)) { - const auto &room = static_cast(activeConnection()->room(existing.value(user))); - if (room) { - RoomManager::instance().enterRoom(room); - return; - } - } - activeConnection()->requestDirectChat(user); -} - QString Controller::formatByteSize(double size, int precision) const { return QLocale().formattedDataSize(size, precision); diff --git a/src/controller.h b/src/controller.h index 6e9ea5297..3fadc8ddc 100644 --- a/src/controller.h +++ b/src/controller.h @@ -126,13 +126,6 @@ public: */ Q_INVOKABLE void joinRoom(const QString &alias); - /** - * @brief Join a direct chat with the given user. - * - * If a direct chat with the user doesn't exist one is created and then joined. - */ - Q_INVOKABLE void openOrCreateDirectChat(Quotient::User *user); - [[nodiscard]] bool supportSystemTray() const; /** diff --git a/src/neochatconnection.cpp b/src/neochatconnection.cpp index 9d4f3c0d2..0c8d8e4bb 100644 --- a/src/neochatconnection.cpp +++ b/src/neochatconnection.cpp @@ -220,4 +220,18 @@ void NeoChatConnection::createSpace(const QString &name, const QString &topic, c }); } +void NeoChatConnection::openOrCreateDirectChat(User *user) +{ + const auto existing = directChats(); + + if (existing.contains(user)) { + const auto room = static_cast(this->room(existing.value(user))); + if (room) { + RoomManager::instance().enterRoom(room); + return; + } + } + requestDirectChat(user); +} + #include "moc_neochatconnection.cpp" diff --git a/src/neochatconnection.h b/src/neochatconnection.h index 82a8ecae0..6dd41cb07 100644 --- a/src/neochatconnection.h +++ b/src/neochatconnection.h @@ -61,6 +61,13 @@ public: */ Q_INVOKABLE void createSpace(const QString &name, const QString &topic, const QString &parent = {}, bool setChildParent = false); + /** + * @brief Join a direct chat with the given user. + * + * If a direct chat with the user doesn't exist one is created and then joined. + */ + Q_INVOKABLE void openOrCreateDirectChat(Quotient::User *user); + Q_SIGNALS: void labelChanged(); }; diff --git a/src/qml/UserDetailDialog.qml b/src/qml/UserDetailDialog.qml index a5d58f4b8..3135315fa 100644 --- a/src/qml/UserDetailDialog.qml +++ b/src/qml/UserDetailDialog.qml @@ -190,7 +190,7 @@ Kirigami.Dialog { text: i18n("Open a private chat") icon.name: "document-send" onTriggered: { - Controller.openOrCreateDirectChat(root.user.object); + root.room.connection.openOrCreateDirectChat(root.user.object) root.close() } }