Skip to content

Commit 080ddb8

Browse files
AndrewZuo01cubxxwluhaolingkubbotopenimbot
authored
fix(main): add more cases for get_users api, so it accept users in older version. feat(main): also add search functionality (#1751)
* update set pin friends * update set pin friends * update set pin friends * update set pin friends * update set pin friends * update set pin friends * fix bugs * fix bugs * debug * debug * debug * debug * debug * debug * debug * debug * debug * debug * debug * debug * Update go.mod * Update friend.go * debug * debug * debug * add pin friend test * add pin friend test * add pin friend test * add pin friend test * add pin friend test * add pin friend test * add pin friend test * add pin friend test * add pin friend test * I cannot solve todo in test.sh * update user command * update user command * update user command * update user command * update user command * update user command * update user command * update user command * update user command * update user command * update user command * update user command * update user command * update user command * Update go.mod * fix group notification * fix group notification * update openimsdk tools * update openim server remove duplicate code * update openim server remove duplicate code * update user command get * update user command get * update response of callback response error * update black ex * update join group ex * update user pb2map * update go sum * update go sum * update updateUserInfoEx * update updateUserInfoEx * update updateUserInfoEx add callback functions * fix dismiss group function * fix dismiss group function * fix dismiss group function * fix dismiss group function * update pin friend to update friend * fix go mod * fix err golangci-lint * fix UserPb2DBMap * update comments, update go.mod check for register username * update comments, update go.mod check for register username * update comments, update go.mod check for register username * update comments, update go.mod check for register username * fix callback * fix go.mod * fix debug * fix bugs * update notification * update notification * update notification * update notification * update notification * update notification * update notification * update notification * fix updateUserInfoEx * fix updateUserInfoEx * modify go.mod * fix updateUserInfoEx * fix updateUserInfoEx * fix: fix the bug * fix: fix the imAdmin permission and searchNoficitaion resp * fix updateUserInfoEx * 2023 Annual Summary Reflections and Aspirations Signed-off-by: Xinwei Xiong (cubxxw) <[email protected]> * fix: dissmissGroup and lack of keyword bug (#1678) * Update docker-start-all.sh * Update env-template.yaml * update user command notification * Update docker-start-all.sh * fix openim config mongo passwd env Signed-off-by: Xinwei Xiong (cubxxw) <[email protected]> * update user command get all notification * update user command get all notification * fix type = 0 * fix type = 0 * fix type = 0 * fix type = 0 * fix type = 0 * fix type = 0 * fix typing cause callback * add ex to usercommand * add ex to usercommand * update updatefriends * fix updatefriend map * fix updatefriend FriendsInfoUpdateNotification * fix push online and offline user, but why typing trigger callback push? * fix push online and offline user, but why typing trigger callback push? * update user command record not found and user access check * update user command get all user access check * update go.mod * fix callback name and place * fix: fix some bug * fix: group messages sync failed. * upadtae callback test * fix callback typing * fix callback typing * fix callback typing * fix callback typing * fix lint on processusercommand * fix: fix the valiable name * fix: fix the getSortedConversation api * fix: fix the mongo search error * fix: GroupApplicationAcceptedNotification (cherry picked from commit 4c3c455) * fix: GroupApplicationAcceptedNotification * fix update friends * fix pageFindUser * fix pageFindUser * fix pageFindUser * fix pageFindUser * Delete .devcontainer directory * revert * more powerful PageFindUserWithKeyword * more powerful PageFindUserWithKeyword * more powerful PageFindUserWithKeyword --------- Signed-off-by: Xinwei Xiong (cubxxw) <[email protected]> Co-authored-by: Xinwei Xiong <[email protected]> Co-authored-by: luhaoling <[email protected]> Co-authored-by: Xinwei Xiong (cubxxw) <[email protected]> Co-authored-by: Brabem <[email protected]> Co-authored-by: OpenIM Bot <[email protected]> Co-authored-by: OpenIM Robot <[email protected]> Co-authored-by: Gordon <[email protected]> Co-authored-by: withchao <[email protected]>
1 parent 64d6b04 commit 080ddb8

File tree

5 files changed

+73
-13
lines changed

5 files changed

+73
-13
lines changed

go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,6 @@ require (
156156
golang.org/x/crypto v0.14.0 // indirect
157157
gopkg.in/ini.v1 v1.67.0 // indirect
158158
)
159+
replace (
160+
github.com/OpenIMSDK/protocol v0.0.47 => github.com/AndrewZuo01/protocol v0.0.0-20240112093520-fd9c53e27b94
161+
)

internal/rpc/user/user.go

+22-6
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,20 @@ func (s *userServer) AccountCheck(ctx context.Context, req *pbuser.AccountCheckR
229229
}
230230

231231
func (s *userServer) GetPaginationUsers(ctx context.Context, req *pbuser.GetPaginationUsersReq) (resp *pbuser.GetPaginationUsersResp, err error) {
232-
total, users, err := s.PageFindUser(ctx, constant.IMOrdinaryUser, req.Pagination)
233-
if err != nil {
234-
return nil, err
232+
if req.UserID == "" && req.UserName == "" {
233+
total, users, err := s.PageFindUser(ctx, constant.IMOrdinaryUser, constant.AppOrdinaryUsers, req.Pagination)
234+
if err != nil {
235+
return nil, err
236+
}
237+
return &pbuser.GetPaginationUsersResp{Total: int32(total), Users: convert.UsersDB2Pb(users)}, err
238+
} else {
239+
total, users, err := s.PageFindUserWithKeyword(ctx, constant.IMOrdinaryUser, constant.AppOrdinaryUsers, req.UserID, req.UserName, req.Pagination)
240+
if err != nil {
241+
return nil, err
242+
}
243+
return &pbuser.GetPaginationUsersResp{Total: int32(total), Users: convert.UsersDB2Pb(users)}, err
235244
}
236-
return &pbuser.GetPaginationUsersResp{Total: int32(total), Users: convert.UsersDB2Pb(users)}, err
245+
237246
}
238247

239248
func (s *userServer) UserRegister(ctx context.Context, req *pbuser.UserRegisterReq) (resp *pbuser.UserRegisterResp, err error) {
@@ -591,31 +600,38 @@ func (s *userServer) UpdateNotificationAccountInfo(ctx context.Context, req *pbu
591600
}
592601

593602
func (s *userServer) SearchNotificationAccount(ctx context.Context, req *pbuser.SearchNotificationAccountReq) (*pbuser.SearchNotificationAccountResp, error) {
603+
// Check if user is an admin
594604
if err := authverify.CheckIMAdmin(ctx); err != nil {
595605
return nil, err
596606
}
597607

598608
var users []*relation.UserModel
599609
var err error
610+
611+
// If a keyword is provided in the request
600612
if req.Keyword != "" {
613+
// Find users by keyword
601614
users, err = s.UserDatabase.Find(ctx, []string{req.Keyword})
602615
if err != nil {
603616
return nil, err
604617
}
618+
619+
// Convert users to response format
605620
resp := s.userModelToResp(users, req.Pagination)
606621
if resp.Total != 0 {
607622
return resp, nil
608623
}
624+
625+
// Find users by nickname if no users found by keyword
609626
users, err = s.UserDatabase.FindByNickname(ctx, req.Keyword)
610627
if err != nil {
611628
return nil, err
612629
}
613630
resp = s.userModelToResp(users, req.Pagination)
614631
return resp, nil
615-
616-
return resp, nil
617632
}
618633

634+
// If no keyword, find users with notification settings
619635
users, err = s.UserDatabase.FindNotification(ctx, constant.AppNotificationAdmin)
620636
if err != nil {
621637
return nil, err

pkg/common/db/controller/user.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ type UserDatabase interface {
4848
//Update(ctx context.Context, user *relation.UserModel) (err error)
4949
// UpdateByMap update (zero value) external guarantee userID exists
5050
UpdateByMap(ctx context.Context, userID string, args map[string]any) (err error)
51+
// FindUser
52+
PageFindUser(ctx context.Context, level1 int64, level2 int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error)
53+
//FindUser with keyword
54+
PageFindUserWithKeyword(ctx context.Context, level1 int64, level2 int64, userID string, userName string, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error)
5155
// Page If not found, no error is returned
5256
Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error)
53-
// FindUser
54-
PageFindUser(ctx context.Context, level int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error)
5557
// IsExist true as long as one exists
5658
IsExist(ctx context.Context, userIDs []string) (exist bool, err error)
5759
// GetAllUserID Get all user IDs
@@ -185,8 +187,11 @@ func (u *userDatabase) Page(ctx context.Context, pagination pagination.Paginatio
185187
return u.userDB.Page(ctx, pagination)
186188
}
187189

188-
func (u *userDatabase) PageFindUser(ctx context.Context, level int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error) {
189-
return u.userDB.PageFindUser(ctx, level, pagination)
190+
func (u *userDatabase) PageFindUser(ctx context.Context, level1 int64, level2 int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error) {
191+
return u.userDB.PageFindUser(ctx, level1, level2, pagination)
192+
}
193+
func (u *userDatabase) PageFindUserWithKeyword(ctx context.Context, level1 int64, level2 int64, userID, userName string, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error) {
194+
return u.userDB.PageFindUserWithKeyword(ctx, level1, level2, userID, userName, pagination)
190195
}
191196

192197
// IsExist Does userIDs exist? As long as there is one, it will be true.

pkg/common/db/mgo/user.go

+37-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"github.com/OpenIMSDK/protocol/user"
2020
"github.com/OpenIMSDK/tools/errs"
21+
"go.mongodb.org/mongo-driver/bson/primitive"
2122
"time"
2223

2324
"github.com/OpenIMSDK/tools/mgoutil"
@@ -78,8 +79,42 @@ func (u *UserMgo) Page(ctx context.Context, pagination pagination.Pagination) (c
7879
return mgoutil.FindPage[*relation.UserModel](ctx, u.coll, bson.M{}, pagination)
7980
}
8081

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)
83118
}
84119

85120
func (u *UserMgo) GetAllUserID(ctx context.Context, pagination pagination.Pagination) (int64, []string, error) {

pkg/common/db/table/relation/user.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ type UserModelInterface interface {
5656
TakeNotification(ctx context.Context, level int64) (user []*UserModel, err error)
5757
TakeByNickname(ctx context.Context, nickname string) (user []*UserModel, err error)
5858
Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
59-
PageFindUser(ctx context.Context, level int64, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
59+
PageFindUser(ctx context.Context, level1 int64, level2 int64, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
60+
PageFindUserWithKeyword(ctx context.Context, level1 int64, level2 int64, userID, userName string, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
6061
Exist(ctx context.Context, userID string) (exist bool, err error)
6162
GetAllUserID(ctx context.Context, pagination pagination.Pagination) (count int64, userIDs []string, err error)
6263
GetUserGlobalRecvMsgOpt(ctx context.Context, userID string) (opt int, err error)

0 commit comments

Comments
 (0)