chore: add logic to add to favorite and archive
This commit is contained in:
@@ -365,4 +365,62 @@ export class EmailService {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
//==============================================
|
||||
async moveMessageToArchive(userId: string, messageId: number) {
|
||||
this.logger.log(`Moving message ${messageId} to archive for user: ${userId}`);
|
||||
|
||||
try {
|
||||
const inboxMailboxId = await this.mailboxResolverService.getInboxMailboxId(userId);
|
||||
const archiveMailboxId = await this.mailboxResolverService.getArchiveMailboxId(userId);
|
||||
|
||||
const result = await firstValueFrom(
|
||||
this.mailServerService.messages.updateMessage(userId, inboxMailboxId, messageId, {
|
||||
moveTo: archiveMailboxId,
|
||||
}),
|
||||
);
|
||||
|
||||
this.logger.log(`Message ${messageId} moved to archive successfully`);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: EmailMessage.MESSAGE_MOVED_TO_ARCHIVE_SUCCESSFULLY,
|
||||
result,
|
||||
};
|
||||
} catch (error) {
|
||||
this.logger.error(
|
||||
`Failed to move message ${messageId} to archive for user ${userId}: ${error instanceof Error ? error.message : "Unknown error"}`,
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
//==============================================
|
||||
async moveMessageToFavorite(userId: string, messageId: number) {
|
||||
this.logger.log(`Moving message ${messageId} to favorite for user: ${userId}`);
|
||||
|
||||
try {
|
||||
const inboxMailboxId = await this.mailboxResolverService.getInboxMailboxId(userId);
|
||||
const favoriteMailboxId = await this.mailboxResolverService.getFavoriteMailboxId(userId);
|
||||
|
||||
const result = await firstValueFrom(
|
||||
this.mailServerService.messages.updateMessage(userId, inboxMailboxId, messageId, {
|
||||
moveTo: favoriteMailboxId,
|
||||
}),
|
||||
);
|
||||
|
||||
this.logger.log(`Message ${messageId} moved to favorite successfully`);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: EmailMessage.MESSAGE_MOVED_TO_FAVORITE_SUCCESSFULLY,
|
||||
result,
|
||||
};
|
||||
} catch (error) {
|
||||
this.logger.error(
|
||||
`Failed to move message ${messageId} to favorite for user ${userId}: ${error instanceof Error ? error.message : "Unknown error"}`,
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user