@@ -167,8 +167,8 @@ func waitForResult(ws *websocket.Conn, ctx, timeoutCtx, matchCtx context.Context
167
167
return
168
168
}
169
169
log .Println ("Match found for user: " + username )
170
- // Notify the users about the match
171
- notifyMatches (result .User , result . MatchedUser , result )
170
+ // Notify the user about the match
171
+ notifyMatches (result .User , result )
172
172
173
173
// NOTE: user and other user are already cleaned up in a separate matching algorithm process
174
174
// so no clean up is required here.
@@ -187,22 +187,15 @@ func sendTimeoutResponse(ws *websocket.Conn) {
187
187
}
188
188
}
189
189
190
- func notifyMatches (username , matchedUsername string , result models.MatchFound ) {
190
+ // Notify matches
191
+ func notifyMatches (username string , result models.MatchFound ) {
191
192
mu .Lock ()
192
193
defer mu .Unlock ()
193
194
194
- // Send message to the first user
195
+ // Send message to matched user
195
196
if userConn , userExists := activeConnections [username ]; userExists {
196
197
if err := userConn .WriteJSON (result ); err != nil {
197
198
log .Printf ("Error sending message to user %s: %v\n " , username , err )
198
199
}
199
200
}
200
-
201
- // Send message to the matched user
202
- if matchedUserConn , matchedUserExists := activeConnections [matchedUsername ]; matchedUserExists {
203
- result .User , result .MatchedUser = result .MatchedUser , result .User // Swap User and MatchedUser values
204
- if err := matchedUserConn .WriteJSON (result ); err != nil {
205
- log .Printf ("Error sending message to user %s: %v\n " , username , err )
206
- }
207
- }
208
201
}
0 commit comments