This commit is contained in:
pradeepkumar
2026-02-24 22:36:42 +05:30
parent d30358755e
commit 7ab5330a88
9 changed files with 390 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ import {
import { Server, Socket } from 'socket.io';
import { JwtService } from '@nestjs/jwt';
import { ConfigService } from '@nestjs/config';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { MessagesService } from './messages.service';
import { CreateMessageDto } from './dto';
import { Logger } from '@nestjs/common';
@@ -37,6 +38,7 @@ export class MessagesGateway implements OnGatewayConnection, OnGatewayDisconnect
private readonly messagesService: MessagesService,
private readonly jwtService: JwtService,
private readonly configService: ConfigService,
private readonly eventEmitter: EventEmitter2,
) {}
/**
@@ -186,6 +188,19 @@ export class MessagesGateway implements OnGatewayConnection, OnGatewayDisconnect
? participants.agentUserId
: participants.userId;
this.sendToUser(otherUserId, 'new_message', message);
// Emit push notification event
const senderProfile = message.sender?.agentProfile || message.sender?.userProfile;
const senderName = senderProfile
? `${senderProfile.firstName || ''} ${senderProfile.lastName || ''}`.trim()
: 'Someone';
this.eventEmitter.emit('notification.message', {
recipientUserId: otherUserId,
senderName,
messagePreview: data.message.content?.substring(0, 100) || '',
conversationId: data.conversationId,
});
}
return { success: true, message };