chore: add new route to get favorinte and archive mailboxx messsage
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Injectable, Logger, NotFoundException } from "@nestjs/common";
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
import { MailboxInfo } from "../../mail-server/interfaces/mailboxes-response.interface";
|
||||
import { MailServerService } from "../../mail-server/services/mail-server.service";
|
||||
import { MailboxEnum } from "../../mailbox/enums/mailbox.enum";
|
||||
|
||||
@@ -9,8 +10,9 @@ export interface UserMailboxIds {
|
||||
sent: string;
|
||||
drafts: string;
|
||||
trash: string;
|
||||
junk?: string;
|
||||
archive?: string;
|
||||
junk: string;
|
||||
archive: string;
|
||||
favorite: string;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
@@ -43,6 +45,7 @@ export class MailboxResolverService {
|
||||
trash: this.findMailboxId(mailboxes.results, MailboxEnum.TRASH),
|
||||
junk: this.findMailboxId(mailboxes.results, MailboxEnum.Junk, false),
|
||||
archive: this.findMailboxId(mailboxes.results, MailboxEnum.ARCHIVE, false),
|
||||
favorite: this.findMailboxId(mailboxes.results, MailboxEnum.FAVORITE, false),
|
||||
};
|
||||
|
||||
this.cacheMailboxIds(userId, mailboxIds);
|
||||
@@ -97,6 +100,18 @@ export class MailboxResolverService {
|
||||
return this.getMailboxId(userId, "trash");
|
||||
}
|
||||
|
||||
async getJunkMailboxId(userId: string): Promise<string> {
|
||||
return this.getMailboxId(userId, "junk");
|
||||
}
|
||||
|
||||
async getArchiveMailboxId(userId: string): Promise<string> {
|
||||
return this.getMailboxId(userId, "archive");
|
||||
}
|
||||
|
||||
async getFavoriteMailboxId(userId: string): Promise<string> {
|
||||
return this.getMailboxId(userId, "favorite");
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear cache for a specific user
|
||||
*/
|
||||
@@ -146,7 +161,7 @@ export class MailboxResolverService {
|
||||
/**
|
||||
* Find mailbox ID by name
|
||||
*/
|
||||
private findMailboxId(mailboxes: any[], mailboxName: string, required: boolean = true): string {
|
||||
private findMailboxId(mailboxes: MailboxInfo[], mailboxName: string, required: boolean = true): string {
|
||||
const mailbox = mailboxes.find((mb) => mb.name === mailboxName || mb.path === mailboxName || mb.specialUse === mailboxName);
|
||||
|
||||
if (!mailbox && required) {
|
||||
|
||||
Reference in New Issue
Block a user