From 3a120c773a9c1db16c544303b24331cd27e8326a Mon Sep 17 00:00:00 2001 From: blue Date: Sat, 8 Aug 2020 02:33:03 +0300 Subject: [PATCH] reconnection issues --- CHANGELOG.md | 8 ++++++ core/account.cpp | 11 +++++--- core/account.h | 2 +- core/squawk.cpp | 54 ++++++++++++++++++++++--------------- ui/models/item.cpp | 5 ++-- ui/widgets/conversation.cpp | 16 +++++++++++ ui/widgets/conversation.h | 1 + 7 files changed, 67 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c1d31c..3e1ebd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## Squawk 0.2.0 (Unreleased) +### Bug fixes +- carbon copies switches on again after reconnection +- requesting the history of the current chat after reconnection +- global availability (in drop down list) gets restored after reconnection +- status icon in active chat changes when presence of the pen pal changes + + ## Squawk 0.1.5 (Jul 29, 2020) ### Bug fixes - error with sending attached files to the conference diff --git a/core/account.cpp b/core/account.cpp index 0c8c272..094fd3c 100644 --- a/core/account.cpp +++ b/core/account.cpp @@ -183,7 +183,6 @@ void Core::Account::connect() reconnectTimer->stop(); } if (state == Shared::ConnectionState::disconnected) { - qDebug() << presence.availableStatusType(); client.connectToServer(config, presence); } else { qDebug("An attempt to connect an account which is already connected, skipping"); @@ -219,6 +218,7 @@ void Core::Account::onClientStateChange(QXmppClient::State st) Shared::ConnectionState os = state; state = Shared::ConnectionState::connected; if (os == Shared::ConnectionState::connecting) { + qDebug() << "running service discovery for account" << name; dm->requestItems(getServer()); dm->requestInfo(getServer()); } @@ -238,9 +238,8 @@ void Core::Account::onClientStateChange(QXmppClient::State st) } break; case QXmppClient::DisconnectedState: { - cancelHistoryRequests(); - pendingVCardRequests.clear(); if (state != Shared::ConnectionState::disconnected) { + handleDisconnection(); state = Shared::ConnectionState::disconnected; emit connectionStateChanged(state); } else { @@ -887,15 +886,18 @@ void Core::Account::onDiscoveryItemsReceived(const QXmppDiscoveryIq& items) void Core::Account::onDiscoveryInfoReceived(const QXmppDiscoveryIq& info) { + qDebug() << "Discovery info received for account" << name; if (info.from() == getServer()) { if (info.features().contains("urn:xmpp:carbons:2")) { + qDebug() << "Enabling carbon copies for account" << name; cm->setCarbonsEnabled(true); } } } -void Core::Account::cancelHistoryRequests() +void Core::Account::handleDisconnection() { + cm->setCarbonsEnabled(false); rh->handleOffline(); archiveQueries.clear(); pendingVCardRequests.clear(); @@ -903,6 +905,7 @@ void Core::Account::cancelHistoryRequests() for (const QString& jid : pendingVCardRequests) { emit receivedVCard(jid, vCard); //need to show it better in the future, like with an error } + pendingVCardRequests.clear(); ownVCardRequestInProgress = false; } diff --git a/core/account.h b/core/account.h index d7ca113..49c7ca9 100644 --- a/core/account.h +++ b/core/account.h @@ -185,7 +185,7 @@ private slots: void onDiscoveryInfoReceived (const QXmppDiscoveryIq& info); private: - void cancelHistoryRequests(); + void handleDisconnection(); void onReconnectTimer(); }; diff --git a/core/squawk.cpp b/core/squawk.cpp index 9bb2f14..1689d71 100644 --- a/core/squawk.cpp +++ b/core/squawk.cpp @@ -223,30 +223,40 @@ void Core::Squawk::onAccountConnectionStateChanged(Shared::ConnectionState p_sta Account* acc = static_cast(sender()); emit changeAccount(acc->getName(), {{"state", QVariant::fromValue(p_state)}}); - switch (p_state) { - case Shared::ConnectionState::disconnected: { - bool equals = true; - for (Accounts::const_iterator itr = accounts.begin(), end = accounts.end(); itr != end; itr++) { - if ((*itr)->getState() != Shared::ConnectionState::disconnected) { - equals = false; - } - } - if (equals && state != Shared::Availability::offline) { - state = Shared::Availability::offline; - emit stateChanged(state); - } - } - break; - case Shared::ConnectionState::connected: #ifdef WITH_KWALLET - if (acc->getPasswordType() == Shared::AccountPassword::kwallet && kwallet.supportState() == PSE::KWallet::success) { - kwallet.requestWritePassword(acc->getName(), acc->getPassword(), true); - } -#endif - break; - default: - break; + if (p_state == Shared::ConnectionState::connected) { + if (acc->getPasswordType() == Shared::AccountPassword::kwallet && kwallet.supportState() == PSE::KWallet::success) { + kwallet.requestWritePassword(acc->getName(), acc->getPassword(), true); + } } +#endif + + Accounts::const_iterator itr = accounts.begin(); + bool es = true; + bool ea = true; + Shared::ConnectionState cs = (*itr)->getState(); + Shared::Availability av = (*itr)->getAvailability(); + itr++; + for (Accounts::const_iterator end = accounts.end(); itr != end; itr++) { + Account* item = *itr; + if (item->getState() != cs) { + es = false; + } + if (item->getAvailability() != av) { + ea = false; + } + } + + if (es) { + if (cs == Shared::ConnectionState::disconnected) { + state = Shared::Availability::offline; + emit stateChanged(state); + } else if (ea) { + state = av; + emit stateChanged(state); + } + } + } void Core::Squawk::onAccountAddContact(const QString& jid, const QString& group, const QMap& data) diff --git a/ui/models/item.cpp b/ui/models/item.cpp index c5d6e2a..e006ad0 100644 --- a/ui/models/item.cpp +++ b/ui/models/item.cpp @@ -215,9 +215,8 @@ void Models::Item::_removeChild(int index) void Models::Item::changed(int col) { - if (parent != nullptr) { - emit childChanged(this, row(), col); - } + + emit childChanged(this, row(), col); } void Models::Item::toOfflineState() diff --git a/ui/widgets/conversation.cpp b/ui/widgets/conversation.cpp index 60b0210..fd87d9f 100644 --- a/ui/widgets/conversation.cpp +++ b/ui/widgets/conversation.cpp @@ -54,6 +54,8 @@ Conversation::Conversation(bool muc, Models::Account* acc, const QString pJid, c { m_ui->setupUi(this); + connect(acc, &Models::Account::childChanged, this, &Conversation::onAccountChanged); + filesLayout = new FlowLayout(m_ui->filesPanel, 0); m_ui->filesPanel->setLayout(filesLayout); @@ -121,6 +123,20 @@ Conversation::~Conversation() { } +void Conversation::onAccountChanged(Models::Item* item, int row, int col) +{ + if (item == account) { + if (col == 2 && account->getState() == Shared::ConnectionState::connected) { + if (!requestingHistory) { + requestingHistory = true; + line->showBusyIndicator(); + emit requestArchive(""); + scroll = down; + } + } + } +} + void Conversation::applyVisualEffects() { DropShadowEffect *e1 = new DropShadowEffect; diff --git a/ui/widgets/conversation.h b/ui/widgets/conversation.h index e5ac53a..ea87607 100644 --- a/ui/widgets/conversation.h +++ b/ui/widgets/conversation.h @@ -121,6 +121,7 @@ protected slots: void onBadgeClose(); void onClearButton(); void onTextEditDocSizeChanged(const QSizeF& size); + void onAccountChanged(Models::Item* item, int row, int col); public: const bool isMuc;