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 { ConfigModule } from '@nestjs/config';
|
||||||
import { NotificationsService } from './notifications.service';
|
import { NotificationsService } from './notifications.service';
|
||||||
import { NotificationsController } from './notifications.controller';
|
import { NotificationsController } from './notifications.controller';
|
||||||
import { EmailModule } from '../email';
|
import { EmailModule } from '../email';
|
||||||
|
import { MessagesModule } from '../messages/messages.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [ConfigModule, EmailModule],
|
imports: [ConfigModule, EmailModule, forwardRef(() => MessagesModule)],
|
||||||
controllers: [NotificationsController],
|
controllers: [NotificationsController],
|
||||||
providers: [NotificationsService],
|
providers: [NotificationsService],
|
||||||
exports: [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 { ConfigService } from '@nestjs/config';
|
||||||
import { OnEvent } from '@nestjs/event-emitter';
|
import { OnEvent } from '@nestjs/event-emitter';
|
||||||
import { Prisma } from '@prisma/client';
|
import { Prisma } from '@prisma/client';
|
||||||
@@ -7,6 +7,7 @@ import * as fs from 'fs';
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { PrismaService } from '../prisma/prisma.service';
|
import { PrismaService } from '../prisma/prisma.service';
|
||||||
import { EmailService } from '../email/email.service';
|
import { EmailService } from '../email/email.service';
|
||||||
|
import { MessagesGateway } from '../messages/messages.gateway';
|
||||||
|
|
||||||
interface FcmToken {
|
interface FcmToken {
|
||||||
token: string;
|
token: string;
|
||||||
@@ -29,6 +30,8 @@ export class NotificationsService implements OnModuleInit {
|
|||||||
private readonly prisma: PrismaService,
|
private readonly prisma: PrismaService,
|
||||||
private readonly configService: ConfigService,
|
private readonly configService: ConfigService,
|
||||||
private readonly emailService: EmailService,
|
private readonly emailService: EmailService,
|
||||||
|
@Inject(forwardRef(() => MessagesGateway))
|
||||||
|
private readonly messagesGateway: MessagesGateway,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
onModuleInit() {
|
onModuleInit() {
|
||||||
@@ -430,6 +433,13 @@ export class NotificationsService implements OnModuleInit {
|
|||||||
// Connection requests are always sent to agents
|
// Connection requests are always sent to agents
|
||||||
const actionUrl = '/agent/network';
|
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(
|
await this.createAndSendNotification(
|
||||||
event.recipientUserId,
|
event.recipientUserId,
|
||||||
'request',
|
'request',
|
||||||
@@ -456,6 +466,14 @@ export class NotificationsService implements OnModuleInit {
|
|||||||
const prefix = await this.getRoutePrefix(event.recipientUserId);
|
const prefix = await this.getRoutePrefix(event.recipientUserId);
|
||||||
const actionUrl = isAccepted ? `${prefix}/message` : `${prefix}/profiles`;
|
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(
|
await this.createAndSendNotification(
|
||||||
event.recipientUserId,
|
event.recipientUserId,
|
||||||
'connection',
|
'connection',
|
||||||
|
|||||||
Reference in New Issue
Block a user