NeoChatConnection signals
Move the signal connects to a function and call from both constructors
This commit is contained in:
@@ -36,6 +36,17 @@ using namespace Qt::StringLiterals;
|
|||||||
|
|
||||||
NeoChatConnection::NeoChatConnection(QObject *parent)
|
NeoChatConnection::NeoChatConnection(QObject *parent)
|
||||||
: Connection(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) {
|
connect(this, &NeoChatConnection::accountDataChanged, this, [this](const QString &type) {
|
||||||
if (type == QLatin1String("org.kde.neochat.account_label")) {
|
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)
|
void NeoChatConnection::logout(bool serverSideLogout)
|
||||||
{
|
{
|
||||||
SettingsGroup(QStringLiteral("Accounts")).remove(userId());
|
SettingsGroup(QStringLiteral("Accounts")).remove(userId());
|
||||||
|
|||||||
@@ -124,4 +124,6 @@ Q_SIGNALS:
|
|||||||
private:
|
private:
|
||||||
bool m_isOnline = true;
|
bool m_isOnline = true;
|
||||||
void setIsOnline(bool isOnline);
|
void setIsOnline(bool isOnline);
|
||||||
|
|
||||||
|
void connectSignals();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user