feat: Add real-time socket event emissions for connection requests and responses via MessagesGateway.
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { Module, forwardRef } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { NotificationsService } from './notifications.service';
|
||||
import { NotificationsController } from './notifications.controller';
|
||||
import { EmailModule } from '../email';
|
||||
import { MessagesModule } from '../messages/messages.module';
|
||||
|
||||
@Module({
|
||||
imports: [ConfigModule, EmailModule],
|
||||
imports: [ConfigModule, EmailModule, forwardRef(() => MessagesModule)],
|
||||
controllers: [NotificationsController],
|
||||
providers: [NotificationsService],
|
||||
exports: [NotificationsService],
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
|
||||
import { Inject, Injectable, Logger, OnModuleInit, forwardRef } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Prisma } from '@prisma/client';
|
||||
@@ -7,6 +7,7 @@ import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { EmailService } from '../email/email.service';
|
||||
import { MessagesGateway } from '../messages/messages.gateway';
|
||||
|
||||
interface FcmToken {
|
||||
token: string;
|
||||
@@ -29,6 +30,8 @@ export class NotificationsService implements OnModuleInit {
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly configService: ConfigService,
|
||||
private readonly emailService: EmailService,
|
||||
@Inject(forwardRef(() => MessagesGateway))
|
||||
private readonly messagesGateway: MessagesGateway,
|
||||
) {}
|
||||
|
||||
onModuleInit() {
|
||||
@@ -430,6 +433,13 @@ export class NotificationsService implements OnModuleInit {
|
||||
// Connection requests are always sent to agents
|
||||
const actionUrl = '/agent/network';
|
||||
|
||||
// Send real-time socket event so agent sees it instantly
|
||||
this.messagesGateway.sendToUser(event.recipientUserId, 'connection_request', {
|
||||
type: 'connection_request',
|
||||
connectionRequestId: event.connectionRequestId,
|
||||
senderName: event.senderName,
|
||||
});
|
||||
|
||||
await this.createAndSendNotification(
|
||||
event.recipientUserId,
|
||||
'request',
|
||||
@@ -456,6 +466,14 @@ export class NotificationsService implements OnModuleInit {
|
||||
const prefix = await this.getRoutePrefix(event.recipientUserId);
|
||||
const actionUrl = isAccepted ? `${prefix}/message` : `${prefix}/profiles`;
|
||||
|
||||
// Send real-time socket event so user sees response instantly
|
||||
this.messagesGateway.sendToUser(event.recipientUserId, 'connection_response', {
|
||||
type: 'connection_response',
|
||||
status: event.status,
|
||||
connectionRequestId: event.connectionRequestId,
|
||||
agentName: event.agentName,
|
||||
});
|
||||
|
||||
await this.createAndSendNotification(
|
||||
event.recipientUserId,
|
||||
'connection',
|
||||
|
||||
Reference in New Issue
Block a user