reconnection issues

This commit is contained in:
Blue 2020-08-08 02:33:03 +03:00
parent 5f64321c2a
commit 3a120c773a
7 changed files with 67 additions and 30 deletions

View file

@ -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;
}

View file

@ -185,7 +185,7 @@ private slots:
void onDiscoveryInfoReceived (const QXmppDiscoveryIq& info);
private:
void cancelHistoryRequests();
void handleDisconnection();
void onReconnectTimer();
};

View file

@ -223,30 +223,40 @@ void Core::Squawk::onAccountConnectionStateChanged(Shared::ConnectionState p_sta
Account* acc = static_cast<Account*>(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<QString, QVariant>& data)