chore: websocket
This commit is contained in:
@@ -6,6 +6,8 @@ import { EmailMessage } from "../../../common/enums/message.enum";
|
||||
import { MailServerService } from "../../mail-server/services/mail-server.service";
|
||||
import { MessageListQueryDto, SearchMessagesQueryDto } from "../DTO/email-query.dto";
|
||||
import { SendEmailDto, UpdateDraftDto } from "../DTO/send-email.dto";
|
||||
import { EmailGateway } from "../email.gateway";
|
||||
import { EmailDeletePayload, EmailMovePayload, EmailStatusUpdatePayload } from "../interfaces/email-events.interface";
|
||||
|
||||
@Injectable()
|
||||
export class EmailService {
|
||||
@@ -14,6 +16,7 @@ export class EmailService {
|
||||
constructor(
|
||||
private readonly mailServerService: MailServerService,
|
||||
private readonly mailboxResolverService: MailboxResolverService,
|
||||
private readonly emailGateway: EmailGateway,
|
||||
// private readonly userService: UsersService,
|
||||
) {}
|
||||
|
||||
@@ -131,6 +134,16 @@ export class EmailService {
|
||||
const inboxMailboxId = await this.mailboxResolverService.getInboxMailboxId(userId);
|
||||
const result = await firstValueFrom(this.mailServerService.messages.deleteMessage(userId, inboxMailboxId, messageId));
|
||||
|
||||
// Emit WebSocket notification
|
||||
const payload: EmailDeletePayload = {
|
||||
messageId,
|
||||
userId,
|
||||
mailboxId: inboxMailboxId,
|
||||
mailboxName: "Inbox",
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
await this.emailGateway.notifyMessageDeleted(payload);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: EmailMessage.MESSAGE_DELETED_SUCCESSFULLY,
|
||||
@@ -148,6 +161,16 @@ export class EmailService {
|
||||
const inboxMailboxId = await this.mailboxResolverService.getInboxMailboxId(userId);
|
||||
const result = await firstValueFrom(this.mailServerService.messages.updateMessage(userId, inboxMailboxId, messageId, { seen: true }));
|
||||
|
||||
// Emit WebSocket notification
|
||||
const payload: EmailStatusUpdatePayload = {
|
||||
messageId,
|
||||
userId,
|
||||
status: "read",
|
||||
mailboxId: inboxMailboxId,
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
await this.emailGateway.notifyMessageStatusUpdate(payload);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: EmailMessage.MESSAGE_MARKED_AS_SEEN_SUCCESSFULLY,
|
||||
@@ -380,6 +403,18 @@ export class EmailService {
|
||||
}),
|
||||
);
|
||||
|
||||
// Emit WebSocket notification
|
||||
const payload: EmailMovePayload = {
|
||||
messageId,
|
||||
userId,
|
||||
fromMailboxId: inboxMailboxId,
|
||||
toMailboxId: archiveMailboxId,
|
||||
fromMailboxName: "Inbox",
|
||||
toMailboxName: "Archive",
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
await this.emailGateway.notifyMessageMoved(payload);
|
||||
|
||||
this.logger.log(`Message ${messageId} moved to archive successfully`);
|
||||
|
||||
return {
|
||||
@@ -409,6 +444,18 @@ export class EmailService {
|
||||
}),
|
||||
);
|
||||
|
||||
// Emit WebSocket notification
|
||||
const payload: EmailMovePayload = {
|
||||
messageId,
|
||||
userId,
|
||||
fromMailboxId: inboxMailboxId,
|
||||
toMailboxId: favoriteMailboxId,
|
||||
fromMailboxName: "Inbox",
|
||||
toMailboxName: "Favorite",
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
await this.emailGateway.notifyMessageMoved(payload);
|
||||
|
||||
this.logger.log(`Message ${messageId} moved to favorite successfully`);
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user