@@ -12,7 +12,7 @@ import (
1212)
1313
1414// Find the first matching user from the front on the queue, based on topics, then difficulty.
15- func findMatchingUsers (tx * redis.Tx , currentUsername string , ctx context.Context ) (* models.MatchFound , error ) {
15+ func findMatchingUser (tx * redis.Tx , currentUsername string , ctx context.Context ) (* models.MatchFound , error ) {
1616 currentUser , err := databases .GetUserDetails (tx , currentUsername , ctx )
1717 if err != nil {
1818 return nil , err
@@ -153,14 +153,23 @@ func doTopicMatching(tx *redis.Tx, ctx context.Context, currentUser *models.Matc
153153
154154 // Iterate through the queue to find a match, so a user in the queue the longest is more likely to be matched.
155155 var foundUsers []string
156- for _ , otherUser := range potentialMatches {
157- if otherUser == currentUser .Username {
156+ for _ , otherUsername := range potentialMatches {
157+ if otherUsername == currentUser .Username {
158158 continue
159159 }
160160
161+ // Include users without any difficulty selected
162+ otherUser , err := databases .GetUserDetails (tx , otherUsername , ctx )
163+ if err != nil {
164+ return nil , err
165+ }
166+ if len (otherUser .Topics ) == 0 {
167+ foundUsers = append (foundUsers , otherUsername )
168+ }
169+
161170 // other user has matching topic
162- if _ , ok := sameTopicUsers [otherUser ]; ok {
163- foundUsers = append (foundUsers , otherUser )
171+ if _ , ok := sameTopicUsers [otherUsername ]; ok {
172+ foundUsers = append (foundUsers , otherUsername )
164173 break
165174 }
166175 }
@@ -181,14 +190,23 @@ func doDifficultyMatching(tx *redis.Tx, ctx context.Context, currentUser *models
181190
182191 // Iterate through the queue to find a match, so a user in the queue the longest is more likely to be matched.
183192 var foundUsers []string
184- for _ , otherUser := range potentialMatches {
185- if otherUser == currentUser .Username {
193+ for _ , otherUsername := range potentialMatches {
194+ if otherUsername == currentUser .Username {
186195 continue
187196 }
188197
189- // other user has matching difficulty
190- if _ , ok := sameDifficultyUsers [otherUser ]; ok {
191- foundUsers = append (foundUsers , otherUser )
198+ // Include users without any difficulty selected
199+ otherUser , err := databases .GetUserDetails (tx , otherUsername , ctx )
200+ if err != nil {
201+ return nil , err
202+ }
203+ if len (otherUser .Topics ) == 0 {
204+ foundUsers = append (foundUsers , otherUsername )
205+ }
206+
207+ // other user has matching difficulty or has no difficulty
208+ if _ , ok := sameDifficultyUsers [otherUsername ]; ok {
209+ foundUsers = append (foundUsers , otherUsername )
192210 break
193211 }
194212 }
0 commit comments