@@ -18,6 +18,7 @@ import (
18
18
"context"
19
19
"github.com/OpenIMSDK/protocol/user"
20
20
"github.com/OpenIMSDK/tools/errs"
21
+ "go.mongodb.org/mongo-driver/bson/primitive"
21
22
"time"
22
23
23
24
"github.com/OpenIMSDK/tools/mgoutil"
@@ -78,8 +79,42 @@ func (u *UserMgo) Page(ctx context.Context, pagination pagination.Pagination) (c
78
79
return mgoutil .FindPage [* relation.UserModel ](ctx , u .coll , bson.M {}, pagination )
79
80
}
80
81
81
- func (u * UserMgo ) PageFindUser (ctx context.Context , level int64 , pagination pagination.Pagination ) (count int64 , users []* relation.UserModel , err error ) {
82
- return mgoutil .FindPage [* relation.UserModel ](ctx , u .coll , bson.M {"app_manger_level" : level }, pagination )
82
+ func (u * UserMgo ) PageFindUser (ctx context.Context , level1 int64 , level2 int64 , pagination pagination.Pagination ) (count int64 , users []* relation.UserModel , err error ) {
83
+ query := bson.M {
84
+ "$or" : []bson.M {
85
+ {"app_manger_level" : level1 },
86
+ {"app_manger_level" : level2 },
87
+ },
88
+ }
89
+
90
+ return mgoutil .FindPage [* relation.UserModel ](ctx , u .coll , query , pagination )
91
+ }
92
+ func (u * UserMgo ) PageFindUserWithKeyword (ctx context.Context , level1 int64 , level2 int64 , userID string , userName string , pagination pagination.Pagination ) (count int64 , users []* relation.UserModel , err error ) {
93
+ // Initialize the base query with level conditions
94
+ query := bson.M {
95
+ "$and" : []bson.M {
96
+ {"app_manger_level" : bson.M {"$in" : []int64 {level1 , level2 }}},
97
+ },
98
+ }
99
+
100
+ // Add userID and userName conditions to the query if they are provided
101
+ if userID != "" || userName != "" {
102
+ userConditions := []bson.M {}
103
+ if userID != "" {
104
+ // Use regex for userID
105
+ regexPattern := primitive.Regex {Pattern : userID , Options : "i" } // 'i' for case-insensitive matching
106
+ userConditions = append (userConditions , bson.M {"user_id" : regexPattern })
107
+ }
108
+ if userName != "" {
109
+ // Use regex for userName
110
+ regexPattern := primitive.Regex {Pattern : userName , Options : "i" } // 'i' for case-insensitive matching
111
+ userConditions = append (userConditions , bson.M {"nickname" : regexPattern })
112
+ }
113
+ query ["$and" ] = append (query ["$and" ].([]bson.M ), bson.M {"$or" : userConditions })
114
+ }
115
+
116
+ // Perform the paginated search
117
+ return mgoutil .FindPage [* relation.UserModel ](ctx , u .coll , query , pagination )
83
118
}
84
119
85
120
func (u * UserMgo ) GetAllUserID (ctx context.Context , pagination pagination.Pagination ) (int64 , []string , error ) {
0 commit comments