@@ -4,11 +4,10 @@ import {
44 transferToTopicQueue ,
55 removeUserFromKey ,
66 transferToDifficultyQueue ,
7+ removeUserFromQueues ,
78} from "../model/userModel" ;
89import { User } from "../types" ;
910import { sendToQueue } from "./rabbitMqService" ;
10- import { notifyMatch } from "../app" ;
11-
1211/**
1312 * Check match in queue, if there is a match, we will remove that user from the queue, and return
1413 * a response to rabbit.
@@ -63,12 +62,8 @@ export const processOldUsers = async (): Promise<void> => {
6362 status : "matched" ,
6463 match : match ,
6564 } ) ;
66- console . log (
67- `Notifying match for OLD users: ${ match . _id } and ${ user . _id } ` ,
68- ) ;
69- notifyMatch ( match . _id , user . _id , { user1 : match , user2 : user } ) ;
70- return ;
71- // continue;
65+
66+ continue ;
7267 }
7368
7469 // Transfer to difficulty queue if there is no match
@@ -98,24 +93,29 @@ export const processOldUsers = async (): Promise<void> => {
9893} ;
9994
10095// Process a new user and attempt matching
101- export const processNewUser = async ( user : User ) : Promise < void > => {
102- const match = await checkMatch ( `topic:${ user . topic } ` ) ;
96+ export const processNewMessage = async ( user : User ) : Promise < void > => {
97+ if ( user . type == "match" ) {
98+ const match = await checkMatch ( `topic:${ user . topic } ` ) ;
10399
104- // match found
105- if ( match ) {
106- await sendToQueue ( match . _id , {
107- status : "matched" ,
108- match : user ,
109- } ) ;
110- await sendToQueue ( user . _id , {
111- status : "matched" ,
112- match : match ,
113- } ) ;
114- // Call notifyMatch here
115- notifyMatch ( match . _id , user . _id , { user1 : match , user2 : user } ) ;
116- } else {
117- // Add to the topic queue if no match
118- await transferToTopicQueue ( user ) ;
100+ // match found
101+ if ( match ) {
102+ await sendToQueue ( match . _id , {
103+ status : "matched" ,
104+ match : user ,
105+ } ) ;
106+ await sendToQueue ( user . _id , {
107+ status : "matched" ,
108+ match : match ,
109+ } ) ;
110+ } else {
111+ // Add to the topic queue if no match
112+ await transferToTopicQueue ( user ) ;
113+ }
114+ } else if ( user . type == "cancel" ) {
115+ //handle cancel request
116+ console . log ( `Cancellation request received for user: ${ user . _id } ` ) ;
117+ // Remove the user from topic and difficulty queues
118+ await removeUserFromQueues ( user . _id ) ;
119119 }
120120} ;
121121
0 commit comments