[Messaging] Delete empty threads after message deletion import (#3716)

* [Messaging] Delete empty threads after message deletion import

* fix
This commit is contained in:
Weiko
2024-02-02 18:13:41 +01:00
committed by GitHub
parent c56153cab1
commit 729e2dc651
12 changed files with 334 additions and 158 deletions

View File

@ -82,8 +82,8 @@ export class GmailPartialSyncService {
const gmailMessageChannel =
await this.messageChannelService.getFirstByConnectedAccountIdOrFail(
workspaceId,
connectedAccountId,
workspaceId,
);
const gmailMessageChannelId = gmailMessageChannel.id;
@ -100,24 +100,29 @@ export class GmailPartialSyncService {
accessToken,
);
await this.utils.saveMessages(
messagesToSave,
dataSourceMetadata,
workspaceDataSource,
connectedAccount,
gmailMessageChannelId,
workspaceId,
);
if (messagesToSave.length !== 0) {
await this.utils.saveMessages(
messagesToSave,
dataSourceMetadata,
workspaceDataSource,
connectedAccount,
gmailMessageChannelId,
workspaceId,
);
}
await this.utils.deleteMessages(
messagesDeleted,
gmailMessageChannelId,
workspaceId,
);
if (messagesDeleted.length !== 0) {
await this.utils.deleteMessages(
workspaceDataSource,
messagesDeleted,
gmailMessageChannelId,
workspaceId,
);
}
if (errors.length) throw new Error('Error fetching messages');
await this.connectedAccountService.saveLastSyncHistoryId(
await this.connectedAccountService.updateLastSyncHistoryId(
newHistoryId,
connectedAccount.id,
workspaceId,