Skip to content

Commit

Permalink
fix: search user && add user (#593)
Browse files Browse the repository at this point in the history
  • Loading branch information
icey-yu authored Oct 18, 2024
1 parent 1cccf5c commit dcd7586
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
21 changes: 5 additions & 16 deletions internal/api/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,35 +142,24 @@ func (o *Api) AddUserAccount(c *gin.Context) {
apiresp.GinError(c, err)
return
}
if _, err := o.chatClient.AddUserAccount(c, req); err != nil {
ip, err := o.GetClientIP(c)
if err != nil {
apiresp.GinError(c, err)
return
}

userInfo := &sdkws.UserInfo{
UserID: req.User.UserID,
Nickname: req.User.Nickname,
FaceURL: req.User.FaceURL,
CreateTime: time.Now().UnixMilli(),
}
imToken, err := o.imApiCaller.ImAdminTokenWithDefaultAdmin(c)
if err != nil {
apiresp.GinError(c, err)
return
}

ctx := o.WithAdminUser(mctx.WithApiToken(c, imToken))
err = o.imApiCaller.RegisterUser(ctx, []*sdkws.UserInfo{userInfo})

err = o.registerChatUser(ctx, ip, []*chat.RegisterUserInfo{req.User})
if err != nil {
apiresp.GinError(c, err)
return
}

if resp, err := o.adminClient.FindDefaultFriend(c, &admin.FindDefaultFriendReq{}); err == nil {
_ = o.imApiCaller.ImportFriend(c, req.User.UserID, resp.UserIDs)
}
if resp, err := o.adminClient.FindDefaultGroup(c, &admin.FindDefaultGroupReq{}); err == nil {
_ = o.imApiCaller.InviteToGroup(c, req.User.UserID, resp.GroupIDs)
}
apiresp.GinSuccess(c, nil)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/common/db/model/chat/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func (o *Attribute) SearchNormalUser(ctx context.Context, keyword string, forbid
{"account": bson.M{"$regex": keyword, "$options": "i"}},
{"nickname": bson.M{"$regex": keyword, "$options": "i"}},
{"phone_number": bson.M{"$regex": keyword, "$options": "i"}},
{"email": bson.M{"$regex": keyword, "$options": "i"}},
}
}
return mongoutil.FindPage[*chat.Attribute](ctx, o.coll, filter, pagination)
Expand Down

0 comments on commit dcd7586

Please sign in to comment.