Skip to content

Commit bf56440

Browse files
committed
fix(change-events): Trigger a 'disconnected' event when an account is deleted and the connection is closed
1 parent 921b8ae commit bf56440

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

lib/email-client/gmail-client.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,26 @@ class GmailClient extends BaseClient {
314314
async close() {
315315
clearTimeout(this.renewWatchTimer);
316316
this.closed = true;
317+
318+
if (this.state !== 'disconnected') {
319+
this.state = 'disconnected';
320+
await this.setStateVal();
321+
await emitChangeEvent(this.logger, this.account, 'state', this.state);
322+
}
323+
317324
return null;
318325
}
319326

320327
async delete() {
321328
clearTimeout(this.renewWatchTimer);
322329
this.closed = true;
330+
331+
if (this.state !== 'disconnected') {
332+
this.state = 'disconnected';
333+
await this.setStateVal();
334+
await emitChangeEvent(this.logger, this.account, 'state', this.state);
335+
}
336+
323337
return null;
324338
}
325339

lib/email-client/imap-client.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,12 @@ class IMAPClient extends BaseClient {
10861086
await this.redis.hSetExists(this.getAccountKey(), 'connections', this.connections.size.toString());
10871087
imapClient?.log.info({ msg: 'Connection closed', type: 'imapClient', account: this.account, disabled: imapClient.disabled });
10881088

1089+
if (this.state !== 'disconnected') {
1090+
this.state = 'disconnected';
1091+
await this.setStateVal();
1092+
await emitChangeEvent(this.logger, this.account, 'state', this.state);
1093+
}
1094+
10891095
try {
10901096
for (let [, mailbox] of this.mailboxes) {
10911097
if (mailbox.syncing) {
@@ -1254,7 +1260,6 @@ class IMAPClient extends BaseClient {
12541260
}
12551261

12561262
close() {
1257-
this.state = 'disconnected';
12581263
if (this.isClosed || this.isClosing) {
12591264
return;
12601265
}

lib/email-client/outlook-client.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,26 @@ class OutlookClient extends BaseClient {
215215
async close() {
216216
clearTimeout(this.renewWatchTimer);
217217
this.closed = true;
218+
219+
if (this.state !== 'disconnected') {
220+
this.state = 'disconnected';
221+
await this.setStateVal();
222+
await emitChangeEvent(this.logger, this.account, 'state', this.state);
223+
}
224+
218225
return null;
219226
}
220227

221228
async delete() {
222229
clearTimeout(this.renewWatchTimer);
223230
this.closed = true;
231+
232+
if (this.state !== 'disconnected') {
233+
this.state = 'disconnected';
234+
await this.setStateVal();
235+
await emitChangeEvent(this.logger, this.account, 'state', this.state);
236+
}
237+
224238
return null;
225239
}
226240

0 commit comments

Comments
 (0)