chore: change the draft flow
This commit is contained in:
Generated
-10
@@ -186,9 +186,6 @@ importers:
|
|||||||
'@types/supertest':
|
'@types/supertest':
|
||||||
specifier: ^6.0.3
|
specifier: ^6.0.3
|
||||||
version: 6.0.3
|
version: 6.0.3
|
||||||
'@types/web-push':
|
|
||||||
specifier: ^3.6.4
|
|
||||||
version: 3.6.4
|
|
||||||
'@typescript-eslint/eslint-plugin':
|
'@typescript-eslint/eslint-plugin':
|
||||||
specifier: ^8.35.1
|
specifier: ^8.35.1
|
||||||
version: 8.35.1(@typescript-eslint/parser@8.35.1(eslint@9.30.1(jiti@2.4.2))(typescript@5.8.3))(eslint@9.30.1(jiti@2.4.2))(typescript@5.8.3)
|
version: 8.35.1(@typescript-eslint/parser@8.35.1(eslint@9.30.1(jiti@2.4.2))(typescript@5.8.3))(eslint@9.30.1(jiti@2.4.2))(typescript@5.8.3)
|
||||||
@@ -2046,9 +2043,6 @@ packages:
|
|||||||
'@types/validator@13.15.2':
|
'@types/validator@13.15.2':
|
||||||
resolution: {integrity: sha512-y7pa/oEJJ4iGYBxOpfAKn5b9+xuihvzDVnC/OSvlVnGxVg0pOqmjiMafiJ1KVNQEaPZf9HsEp5icEwGg8uIe5Q==}
|
resolution: {integrity: sha512-y7pa/oEJJ4iGYBxOpfAKn5b9+xuihvzDVnC/OSvlVnGxVg0pOqmjiMafiJ1KVNQEaPZf9HsEp5icEwGg8uIe5Q==}
|
||||||
|
|
||||||
'@types/web-push@3.6.4':
|
|
||||||
resolution: {integrity: sha512-GnJmSr40H3RAnj0s34FNTcJi1hmWFV5KXugE0mYWnYhgTAHLJ/dJKAwDmvPJYMke0RplY2XE9LnM4hqSqKIjhQ==}
|
|
||||||
|
|
||||||
'@types/yargs-parser@21.0.3':
|
'@types/yargs-parser@21.0.3':
|
||||||
resolution: {integrity: sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==}
|
resolution: {integrity: sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==}
|
||||||
|
|
||||||
@@ -8838,10 +8832,6 @@ snapshots:
|
|||||||
|
|
||||||
'@types/validator@13.15.2': {}
|
'@types/validator@13.15.2': {}
|
||||||
|
|
||||||
'@types/web-push@3.6.4':
|
|
||||||
dependencies:
|
|
||||||
'@types/node': 22.16.0
|
|
||||||
|
|
||||||
'@types/yargs-parser@21.0.3': {}
|
'@types/yargs-parser@21.0.3': {}
|
||||||
|
|
||||||
'@types/yargs@17.0.33':
|
'@types/yargs@17.0.33':
|
||||||
|
|||||||
@@ -480,6 +480,15 @@ export class EmailService {
|
|||||||
const draftsMailboxId = await this.mailboxResolverService.getDraftsMailboxId(wildduckUserId);
|
const draftsMailboxId = await this.mailboxResolverService.getDraftsMailboxId(wildduckUserId);
|
||||||
const existingDraft = await firstValueFrom(this.mailServerService.messages.getMessage(wildduckUserId, draftsMailboxId, messageId));
|
const existingDraft = await firstValueFrom(this.mailServerService.messages.getMessage(wildduckUserId, draftsMailboxId, messageId));
|
||||||
|
|
||||||
|
// Delete the existing draft first to avoid incrementing the count
|
||||||
|
try {
|
||||||
|
await firstValueFrom(this.mailServerService.messages.deleteMessage(wildduckUserId, draftsMailboxId, messageId));
|
||||||
|
this.logger.log(`Existing draft message ${messageId} deleted before update`);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.warn(`Failed to delete existing draft message ${messageId}: ${error instanceof Error ? error.message : String(error)}`);
|
||||||
|
// Continue with update even if deletion fails
|
||||||
|
}
|
||||||
|
|
||||||
const draftData: SendEmailDto = {
|
const draftData: SendEmailDto = {
|
||||||
from: updateDraftDto.from || { address: existingDraft.from?.address || "" },
|
from: updateDraftDto.from || { address: existingDraft.from?.address || "" },
|
||||||
to: updateDraftDto.to || [],
|
to: updateDraftDto.to || [],
|
||||||
@@ -496,10 +505,8 @@ export class EmailService {
|
|||||||
ip: updateDraftDto.ip,
|
ip: updateDraftDto.ip,
|
||||||
isDraft: true,
|
isDraft: true,
|
||||||
uploadOnly: true,
|
uploadOnly: true,
|
||||||
draft: {
|
// Remove the draft reference since we deleted the original
|
||||||
mailbox: draftsMailboxId,
|
// This will create a new draft instead of trying to update the deleted one
|
||||||
id: messageId,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const user = await this.userRepository.findOne({ wildduckUserId, deletedAt: null }, { populate: ["business"] });
|
const user = await this.userRepository.findOne({ wildduckUserId, deletedAt: null }, { populate: ["business"] });
|
||||||
@@ -539,11 +546,24 @@ export class EmailService {
|
|||||||
//==============================================
|
//==============================================
|
||||||
async sendDraft(wildduckUserId: string, userId: string, messageId: number) {
|
async sendDraft(wildduckUserId: string, userId: string, messageId: number) {
|
||||||
const draftsMailboxId = await this.mailboxResolverService.getDraftsMailboxId(wildduckUserId);
|
const draftsMailboxId = await this.mailboxResolverService.getDraftsMailboxId(wildduckUserId);
|
||||||
|
|
||||||
|
// Get message details before sending (for notification)
|
||||||
|
const message = await firstValueFrom(this.mailServerService.messages.getMessage(wildduckUserId, draftsMailboxId, messageId));
|
||||||
|
|
||||||
|
// Submit the draft for delivery
|
||||||
const result = await firstValueFrom(
|
const result = await firstValueFrom(
|
||||||
this.mailServerService.messages.submitDraft(wildduckUserId, draftsMailboxId, messageId, { deleteFiles: false }),
|
this.mailServerService.messages.submitDraft(wildduckUserId, draftsMailboxId, messageId, { deleteFiles: false }),
|
||||||
);
|
);
|
||||||
|
|
||||||
const message = await firstValueFrom(this.mailServerService.messages.getMessage(wildduckUserId, draftsMailboxId, messageId));
|
// Delete the draft from drafts folder after successful submission
|
||||||
|
// This ensures the draft count decreases properly
|
||||||
|
try {
|
||||||
|
await firstValueFrom(this.mailServerService.messages.deleteMessage(wildduckUserId, draftsMailboxId, messageId));
|
||||||
|
this.logger.log(`Draft message ${messageId} deleted from drafts folder after sending`);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.warn(`Failed to delete draft message ${messageId} from drafts folder: ${error instanceof Error ? error.message : String(error)}`);
|
||||||
|
// Don't fail the entire operation if deletion fails
|
||||||
|
}
|
||||||
|
|
||||||
await this.emailNotificationService.notifyEmailSentFromDraft({
|
await this.emailNotificationService.notifyEmailSentFromDraft({
|
||||||
wildduckUserId,
|
wildduckUserId,
|
||||||
|
|||||||
Reference in New Issue
Block a user