diff --git a/src/neochatconnection.cpp b/src/neochatconnection.cpp index 7c12fae99..8f9be784c 100644 --- a/src/neochatconnection.cpp +++ b/src/neochatconnection.cpp @@ -36,6 +36,17 @@ using namespace Qt::StringLiterals; NeoChatConnection::NeoChatConnection(QObject *parent) : Connection(parent) +{ + connectSignals(); +} + +NeoChatConnection::NeoChatConnection(const QUrl &server, QObject *parent) + : Connection(server, parent) +{ + connectSignals(); +} + +void NeoChatConnection::connectSignals() { connect(this, &NeoChatConnection::accountDataChanged, this, [this](const QString &type) { if (type == QLatin1String("org.kde.neochat.account_label")) { @@ -88,44 +99,6 @@ NeoChatConnection::NeoChatConnection(QObject *parent) }); } -NeoChatConnection::NeoChatConnection(const QUrl &server, QObject *parent) - : Connection(server, parent) -{ - connect(this, &NeoChatConnection::accountDataChanged, this, [this](const QString &type) { - if (type == QLatin1String("org.kde.neochat.account_label")) { - Q_EMIT labelChanged(); - } - }); - connect(this, &NeoChatConnection::directChatsListChanged, this, [this](DirectChatsMap additions, DirectChatsMap removals) { - Q_EMIT directChatInvitesChanged(); - for (const auto &chatId : additions) { - if (const auto chat = room(chatId)) { - connect(chat, &Room::unreadStatsChanged, this, [this]() { - Q_EMIT directChatNotificationsChanged(); - }); - } - } - for (const auto &chatId : removals) { - if (const auto chat = room(chatId)) { - disconnect(chat, &Room::unreadStatsChanged, this, nullptr); - } - } - }); - connect(this, &NeoChatConnection::joinedRoom, this, [this](Room *room) { - if (room->isDirectChat()) { - connect(room, &Room::unreadStatsChanged, this, [this]() { - Q_EMIT directChatNotificationsChanged(); - }); - } - }); - connect(this, &NeoChatConnection::leftRoom, this, [this](Room *room, Room *prev) { - Q_UNUSED(room) - if (prev && prev->isDirectChat()) { - Q_EMIT directChatInvitesChanged(); - } - }); -} - void NeoChatConnection::logout(bool serverSideLogout) { SettingsGroup(QStringLiteral("Accounts")).remove(userId()); diff --git a/src/neochatconnection.h b/src/neochatconnection.h index 4760fff95..2857aa76f 100644 --- a/src/neochatconnection.h +++ b/src/neochatconnection.h @@ -124,4 +124,6 @@ Q_SIGNALS: private: bool m_isOnline = true; void setIsOnline(bool isOnline); + + void connectSignals(); };