From 4f56fe365af98b338b51710b9911abf8021e0afe Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Fri, 25 Oct 2024 17:35:06 +0300 Subject: [PATCH] fix(account-state): Only swiths to disconnected if the account was previously connected --- lib/email-client/gmail-client.js | 4 ++-- lib/email-client/imap-client.js | 2 +- lib/email-client/outlook-client.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/email-client/gmail-client.js b/lib/email-client/gmail-client.js index 8f2e395f..fccb84fa 100644 --- a/lib/email-client/gmail-client.js +++ b/lib/email-client/gmail-client.js @@ -315,7 +315,7 @@ class GmailClient extends BaseClient { clearTimeout(this.renewWatchTimer); this.closed = true; - if (this.state !== 'disconnected') { + if (['init', 'connecting', 'syncing', 'connected'].includes(this.state)) { this.state = 'disconnected'; await this.setStateVal(); await emitChangeEvent(this.logger, this.account, 'state', this.state); @@ -328,7 +328,7 @@ class GmailClient extends BaseClient { clearTimeout(this.renewWatchTimer); this.closed = true; - if (this.state !== 'disconnected') { + if (['init', 'connecting', 'syncing', 'connected'].includes(this.state)) { this.state = 'disconnected'; await this.setStateVal(); await emitChangeEvent(this.logger, this.account, 'state', this.state); diff --git a/lib/email-client/imap-client.js b/lib/email-client/imap-client.js index cbb3645a..c26b6551 100644 --- a/lib/email-client/imap-client.js +++ b/lib/email-client/imap-client.js @@ -1086,7 +1086,7 @@ class IMAPClient extends BaseClient { await this.redis.hSetExists(this.getAccountKey(), 'connections', this.connections.size.toString()); imapClient?.log.info({ msg: 'Connection closed', type: 'imapClient', account: this.account, disabled: imapClient.disabled }); - if (this.state !== 'disconnected') { + if (['init', 'connecting', 'syncing', 'connected'].includes(this.state)) { this.state = 'disconnected'; await this.setStateVal(); await emitChangeEvent(this.logger, this.account, 'state', this.state); diff --git a/lib/email-client/outlook-client.js b/lib/email-client/outlook-client.js index eea3c0ab..9df26f31 100644 --- a/lib/email-client/outlook-client.js +++ b/lib/email-client/outlook-client.js @@ -216,7 +216,7 @@ class OutlookClient extends BaseClient { clearTimeout(this.renewWatchTimer); this.closed = true; - if (this.state !== 'disconnected') { + if (['init', 'connecting', 'syncing', 'connected'].includes(this.state)) { this.state = 'disconnected'; await this.setStateVal(); await emitChangeEvent(this.logger, this.account, 'state', this.state); @@ -229,7 +229,7 @@ class OutlookClient extends BaseClient { clearTimeout(this.renewWatchTimer); this.closed = true; - if (this.state !== 'disconnected') { + if (['init', 'connecting', 'syncing', 'connected'].includes(this.state)) { this.state = 'disconnected'; await this.setStateVal(); await emitChangeEvent(this.logger, this.account, 'state', this.state);