From 61f83212b23171d575e417e302c10687d7a4aa0f Mon Sep 17 00:00:00 2001
From: luhaoling <2198702716@qq.com>
Date: Wed, 3 Jan 2024 15:39:31 +0800
Subject: [PATCH 01/17] fix: fix the bug
---
go.mod | 2 +-
internal/rpc/user/user.go | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/go.mod b/go.mod
index 393e742de..9b47aebe6 100644
--- a/go.mod
+++ b/go.mod
@@ -4,7 +4,7 @@ go 1.19
require (
firebase.google.com/go v3.13.0+incompatible
- github.com/OpenIMSDK/protocol v0.0.42
+ github.com/OpenIMSDK/protocol v0.0.43
github.com/OpenIMSDK/tools v0.0.21
github.com/bwmarrin/snowflake v0.3.0 // indirect
github.com/dtm-labs/rockscache v0.1.1
diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go
index 5a79fbc91..824b8a9bb 100644
--- a/internal/rpc/user/user.go
+++ b/internal/rpc/user/user.go
@@ -558,7 +558,7 @@ func (s *userServer) userModelToResp(users []*relation.UserModel) *pbuser.Search
accounts := make([]*pbuser.NotificationAccountInfo, 0)
var total int64
for _, v := range users {
- if v.AppMangerLevel == constant.AppNotificationAdmin || v.AppMangerLevel == constant.AppAdmin {
+ if v.AppMangerLevel == constant.AppNotificationAdmin && !utils.IsContain(v.UserID, config.Config.IMAdmin.UserID) {
temp := &pbuser.NotificationAccountInfo{
UserID: v.UserID,
FaceURL: v.FaceURL,
From 16bc053d0951be9e1d231d08322e62f7423cc576 Mon Sep 17 00:00:00 2001
From: luhaoling <2198702716@qq.com>
Date: Wed, 3 Jan 2024 18:11:02 +0800
Subject: [PATCH 02/17] fix: fix the imAdmin permission and searchNoficitaion
resp
---
internal/rpc/user/user.go | 2 +-
pkg/authverify/token.go | 10 ++++++++--
pkg/common/db/controller/user.go | 7 +++++++
pkg/common/db/mgo/user.go | 4 ++++
pkg/common/db/table/relation/user.go | 1 +
pkg/rpcclient/user.go | 3 +++
6 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go
index 824b8a9bb..51403d631 100644
--- a/internal/rpc/user/user.go
+++ b/internal/rpc/user/user.go
@@ -515,7 +515,7 @@ func (s *userServer) SearchNotificationAccount(ctx context.Context, req *pbuser.
return resp, nil
}
- _, users, err := s.UserDatabase.Page(ctx, req.Pagination)
+ users, err := s.UserDatabase.FindNotification(ctx, constant.AppNotificationAdmin)
if err != nil {
return nil, err
}
diff --git a/pkg/authverify/token.go b/pkg/authverify/token.go
index d9aa0dbb1..4c71224ee 100644
--- a/pkg/authverify/token.go
+++ b/pkg/authverify/token.go
@@ -38,6 +38,9 @@ func CheckAccessV3(ctx context.Context, ownerUserID string) (err error) {
if utils.IsContain(opUserID, config.Config.Manager.UserID) {
return nil
}
+ if utils.IsContain(opUserID, config.Config.IMAdmin.UserID) {
+ return nil
+ }
if opUserID == ownerUserID {
return nil
}
@@ -45,13 +48,16 @@ func CheckAccessV3(ctx context.Context, ownerUserID string) (err error) {
}
func IsAppManagerUid(ctx context.Context) bool {
- return utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.Manager.UserID)
+ return utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.Manager.UserID) || utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.IMAdmin.UserID)
}
func CheckAdmin(ctx context.Context) error {
if utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.Manager.UserID) {
return nil
}
+ if utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.IMAdmin.UserID) {
+ return nil
+ }
return errs.ErrNoPermission.Wrap(fmt.Sprintf("user %s is not admin userID", mcontext.GetOpUserID(ctx)))
}
func CheckIMAdmin(ctx context.Context) error {
@@ -69,7 +75,7 @@ func ParseRedisInterfaceToken(redisToken any) (*tokenverify.Claims, error) {
}
func IsManagerUserID(opUserID string) bool {
- return utils.IsContain(opUserID, config.Config.Manager.UserID)
+ return utils.IsContain(opUserID, config.Config.Manager.UserID) || utils.IsContain(opUserID, config.Config.IMAdmin.UserID)
}
func WsVerifyToken(token, userID string, platformID int) error {
diff --git a/pkg/common/db/controller/user.go b/pkg/common/db/controller/user.go
index 72bdf6b06..a109b81ef 100644
--- a/pkg/common/db/controller/user.go
+++ b/pkg/common/db/controller/user.go
@@ -40,6 +40,8 @@ type UserDatabase interface {
Find(ctx context.Context, userIDs []string) (users []*relation.UserModel, err error)
// Find userInfo By Nickname
FindByNickname(ctx context.Context, nickname string) (users []*relation.UserModel, err error)
+ // Find notificationAccounts
+ FindNotification(ctx context.Context, level int64) (users []*relation.UserModel, err error)
// Create Insert multiple external guarantees that the userID is not repeated and does not exist in the db
Create(ctx context.Context, users []*relation.UserModel) (err error)
// Update update (non-zero value) external guarantee userID exists
@@ -140,6 +142,11 @@ func (u *userDatabase) FindByNickname(ctx context.Context, nickname string) (use
return u.userDB.TakeByNickname(ctx, nickname)
}
+// Find notificationAccouts
+func (u *userDatabase) FindNotification(ctx context.Context, level int64) (users []*relation.UserModel, err error) {
+ return u.userDB.TakeNotification(ctx, level)
+}
+
// Create Insert multiple external guarantees that the userID is not repeated and does not exist in the db.
func (u *userDatabase) Create(ctx context.Context, users []*relation.UserModel) (err error) {
return u.tx.Transaction(ctx, func(ctx context.Context) error {
diff --git a/pkg/common/db/mgo/user.go b/pkg/common/db/mgo/user.go
index 0ca711ad8..27ca264dd 100644
--- a/pkg/common/db/mgo/user.go
+++ b/pkg/common/db/mgo/user.go
@@ -65,6 +65,10 @@ func (u *UserMgo) Take(ctx context.Context, userID string) (user *relation.UserM
return mgoutil.FindOne[*relation.UserModel](ctx, u.coll, bson.M{"user_id": userID})
}
+func (u *UserMgo) TakeNotification(ctx context.Context, level int64) (user []*relation.UserModel, err error) {
+ return mgoutil.Find[*relation.UserModel](ctx, u.coll, bson.M{"app_manger_level": level})
+}
+
func (u *UserMgo) TakeByNickname(ctx context.Context, nickname string) (user []*relation.UserModel, err error) {
return mgoutil.Find[*relation.UserModel](ctx, u.coll, bson.M{"nickname": nickname})
}
diff --git a/pkg/common/db/table/relation/user.go b/pkg/common/db/table/relation/user.go
index 8917ba55f..fc116adc2 100644
--- a/pkg/common/db/table/relation/user.go
+++ b/pkg/common/db/table/relation/user.go
@@ -53,6 +53,7 @@ type UserModelInterface interface {
UpdateByMap(ctx context.Context, userID string, args map[string]any) (err error)
Find(ctx context.Context, userIDs []string) (users []*UserModel, err error)
Take(ctx context.Context, userID string) (user *UserModel, err error)
+ TakeNotification(ctx context.Context, level int64) (user []*UserModel, err error)
TakeByNickname(ctx context.Context, nickname string) (user []*UserModel, err error)
Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
Exist(ctx context.Context, userID string) (exist bool, err error)
diff --git a/pkg/rpcclient/user.go b/pkg/rpcclient/user.go
index de633ee30..451914cd3 100644
--- a/pkg/rpcclient/user.go
+++ b/pkg/rpcclient/user.go
@@ -64,6 +64,9 @@ func NewUserRpcClient(client discoveryregistry.SvcDiscoveryRegistry) UserRpcClie
// GetUsersInfo retrieves information for multiple users based on their user IDs.
func (u *UserRpcClient) GetUsersInfo(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error) {
+ if len(userIDs) == 0 {
+ return []*sdkws.UserInfo{}, nil
+ }
resp, err := u.Client.GetDesignateUsers(ctx, &user.GetDesignateUsersReq{
UserIDs: userIDs,
})
From 7bb44b8b88c1d10492e3752c1b02970c815402ab Mon Sep 17 00:00:00 2001
From: "Xinwei Xiong (cubxxw)" <3293172751nss@gmail.com>
Date: Thu, 4 Jan 2024 15:40:14 +0800
Subject: [PATCH 03/17] 2023 Annual Summary Reflections and Aspirations
Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>
---
scripts/docker-start-all.sh | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/scripts/docker-start-all.sh b/scripts/docker-start-all.sh
index 3c83b02bb..85954a677 100755
--- a/scripts/docker-start-all.sh
+++ b/scripts/docker-start-all.sh
@@ -21,6 +21,25 @@ set -o pipefail
#fixme This scripts is the total startup scripts
#fixme The full name of the shell scripts that needs to be started is placed in the need_to_start_server_shell array
+# Fixed ports inside the docker startup container
+export OPENIM_WS_PORT=10001
+export API_OPENIM_PORT=10002
+export API_PROM_PORT=20100
+export USER_PROM_PORT=20110
+export FRIEND_PROM_PORT=20120
+export MESSAGE_PROM_PORT=20130
+export MSG_GATEWAY_PROM_PORT=20140
+export GROUP_PROM_PORT=20150
+export AUTH_PROM_PORT=20160
+export PUSH_PROM_PORT=20170
+export CONVERSATION_PROM_PORT=20230
+export RTC_PROM_PORT=21300
+export THIRD_PROM_PORT=21301
+export MSG_TRANSFER_PROM_PORT=21400
+export MSG_TRANSFER_PROM_PORT=21401
+export MSG_TRANSFER_PROM_PORT=21402
+export MSG_TRANSFER_PROM_PORT=21403
+
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/install/common.sh"
From d446bdb9437063f04302a5026926ec7d237781f5 Mon Sep 17 00:00:00 2001
From: Brabem <69128477+luhaoling@users.noreply.github.com>
Date: Thu, 4 Jan 2024 17:24:51 +0800
Subject: [PATCH 04/17] fix: dissmissGroup and lack of keyword bug (#1678)
---
go.mod | 2 +-
internal/rpc/group/group.go | 50 ++++++++++++++++++++++++++++++++-----
2 files changed, 45 insertions(+), 7 deletions(-)
diff --git a/go.mod b/go.mod
index f1b3239c3..f10e123a0 100644
--- a/go.mod
+++ b/go.mod
@@ -4,7 +4,7 @@ go 1.19
require (
firebase.google.com/go v3.13.0+incompatible
- github.com/OpenIMSDK/protocol v0.0.43
+ github.com/OpenIMSDK/protocol v0.0.44
github.com/OpenIMSDK/tools v0.0.21
github.com/bwmarrin/snowflake v0.3.0 // indirect
github.com/dtm-labs/rockscache v0.1.1
diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go
index ba129d7e9..b1ea0aa03 100644
--- a/internal/rpc/group/group.go
+++ b/internal/rpc/group/group.go
@@ -476,13 +476,42 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbgroup.GetGro
func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbgroup.GetGroupMemberListReq) (*pbgroup.GetGroupMemberListResp, error) {
resp := &pbgroup.GetGroupMemberListResp{}
- total, members, err := s.db.PageGetGroupMember(ctx, req.GroupID, req.Pagination)
+ var (
+ total int64
+ members []*relationtb.GroupMemberModel
+ err error
+ )
+ if req.Keyword == "" {
+ total, members, err = s.db.PageGetGroupMember(ctx, req.GroupID, req.Pagination)
+ } else {
+ members, err = s.db.FindGroupMemberAll(ctx, req.GroupID)
+ }
if err != nil {
return nil, err
}
if err := s.PopulateGroupMember(ctx, members...); err != nil {
return nil, err
}
+ if req.Keyword != "" {
+ groupMembers := make([]*relationtb.GroupMemberModel, 0)
+ for _, member := range members {
+ if member.UserID == req.Keyword {
+ groupMembers = append(groupMembers, member)
+ total++
+ continue
+ }
+ if member.Nickname == req.Keyword {
+ groupMembers = append(groupMembers, member)
+ total++
+ continue
+ }
+ }
+
+ GMembers := utils.Paginate(groupMembers, int(req.Pagination.GetPageNumber()), int(req.Pagination.GetShowNumber()))
+ resp.Members = utils.Batch(convert.Db2PbGroupMember, GMembers)
+ resp.Total = uint32(total)
+ return resp, nil
+ }
resp.Total = uint32(total)
resp.Members = utils.Batch(convert.Db2PbGroupMember, members)
return resp, nil
@@ -1042,20 +1071,29 @@ func (s *groupServer) TransferGroupOwner(ctx context.Context, req *pbgroup.Trans
func (s *groupServer) GetGroups(ctx context.Context, req *pbgroup.GetGroupsReq) (*pbgroup.GetGroupsResp, error) {
resp := &pbgroup.GetGroupsResp{}
var (
- groups []*relationtb.GroupModel
- err error
+ group []*relationtb.GroupModel
+ err error
)
if req.GroupID != "" {
- groups, err = s.db.FindGroup(ctx, []string{req.GroupID})
- resp.Total = uint32(len(groups))
+ group, err = s.db.FindGroup(ctx, []string{req.GroupID})
+ resp.Total = uint32(len(group))
} else {
var total int64
- total, groups, err = s.db.SearchGroup(ctx, req.GroupName, req.Pagination)
+ total, group, err = s.db.SearchGroup(ctx, req.GroupName, req.Pagination)
resp.Total = uint32(total)
}
if err != nil {
return nil, err
}
+
+ var groups []*relationtb.GroupModel
+ for _, v := range group {
+ if v.Status == constant.GroupStatusDismissed {
+ resp.Total--
+ continue
+ }
+ groups = append(groups, v)
+ }
groupIDs := utils.Slice(groups, func(e *relationtb.GroupModel) string {
return e.GroupID
})
From b19d1f1726b32a7c704817d2a3d7a9e7ecbf9aa2 Mon Sep 17 00:00:00 2001
From: Xinwei Xiong <3293172751@qq.com>
Date: Thu, 4 Jan 2024 17:39:32 +0800
Subject: [PATCH 05/17] Update docker-start-all.sh
---
scripts/docker-start-all.sh | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/scripts/docker-start-all.sh b/scripts/docker-start-all.sh
index 85954a677..d3eb67979 100755
--- a/scripts/docker-start-all.sh
+++ b/scripts/docker-start-all.sh
@@ -35,10 +35,6 @@ export PUSH_PROM_PORT=20170
export CONVERSATION_PROM_PORT=20230
export RTC_PROM_PORT=21300
export THIRD_PROM_PORT=21301
-export MSG_TRANSFER_PROM_PORT=21400
-export MSG_TRANSFER_PROM_PORT=21401
-export MSG_TRANSFER_PROM_PORT=21402
-export MSG_TRANSFER_PROM_PORT=21403
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/install/common.sh"
@@ -55,4 +51,4 @@ sleep 5
"${OPENIM_ROOT}"/scripts/check-all.sh
-tail -f ${LOG_FILE}
\ No newline at end of file
+tail -f ${LOG_FILE}
From 58ab340d1ea1293370ce2b301ad226b47f8f5c58 Mon Sep 17 00:00:00 2001
From: OpenIM Bot <124379614+kubbot@users.noreply.github.com>
Date: Thu, 4 Jan 2024 17:42:57 +0800
Subject: [PATCH 06/17] Update env-template.yaml
---
deployments/templates/env-template.yaml | 6 ------
1 file changed, 6 deletions(-)
diff --git a/deployments/templates/env-template.yaml b/deployments/templates/env-template.yaml
index 1772af644..d501bbbc4 100644
--- a/deployments/templates/env-template.yaml
+++ b/deployments/templates/env-template.yaml
@@ -187,18 +187,12 @@ CHAT_IMAGE_VERSION=${CHAT_IMAGE_VERSION}
# Port for the OpenIM chat API.
# Default: OPENIM_CHAT_API_PORT=10008
-# !!! TODO: Do not change the chat port https://github.com/openimsdk/chat/issues/365
OPENIM_CHAT_API_PORT=${OPENIM_CHAT_API_PORT}
# Port for the OpenIM admin API.
# Default: OPENIM_ADMIN_API_PORT=10009
-# !!! TODO: Do not change the chat port https://github.com/openimsdk/chat/issues/365
OPENIM_ADMIN_API_PORT=${OPENIM_ADMIN_API_PORT}
-# Directory path for storing data files or related information for OpenIM chat.
-# Default: OPENIM_CHAT_DATA_DIR=./openim-chat/main
-OPENIM_CHAT_DATA_DIR=${OPENIM_CHAT_DATA_DIR}
-
# ======================================
# ========== OpenIM Admin ==============
# ======================================
From baf0d1888c908906714ab295786c7dce7599bc9a Mon Sep 17 00:00:00 2001
From: Xinwei Xiong <3293172751@qq.com>
Date: Thu, 4 Jan 2024 18:24:54 +0800
Subject: [PATCH 07/17] Update docker-start-all.sh
---
scripts/docker-start-all.sh | 15 ---------------
1 file changed, 15 deletions(-)
diff --git a/scripts/docker-start-all.sh b/scripts/docker-start-all.sh
index d3eb67979..2616b7bd1 100755
--- a/scripts/docker-start-all.sh
+++ b/scripts/docker-start-all.sh
@@ -21,21 +21,6 @@ set -o pipefail
#fixme This scripts is the total startup scripts
#fixme The full name of the shell scripts that needs to be started is placed in the need_to_start_server_shell array
-# Fixed ports inside the docker startup container
-export OPENIM_WS_PORT=10001
-export API_OPENIM_PORT=10002
-export API_PROM_PORT=20100
-export USER_PROM_PORT=20110
-export FRIEND_PROM_PORT=20120
-export MESSAGE_PROM_PORT=20130
-export MSG_GATEWAY_PROM_PORT=20140
-export GROUP_PROM_PORT=20150
-export AUTH_PROM_PORT=20160
-export PUSH_PROM_PORT=20170
-export CONVERSATION_PROM_PORT=20230
-export RTC_PROM_PORT=21300
-export THIRD_PROM_PORT=21301
-
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/install/common.sh"
From b17b364b02a3b43c82f7e1634779d741356b49b9 Mon Sep 17 00:00:00 2001
From: "Xinwei Xiong (cubxxw)" <3293172751nss@gmail.com>
Date: Fri, 5 Jan 2024 10:02:37 +0800
Subject: [PATCH 08/17] fix openim config mongo passwd env
Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>
---
docs/contrib/environment.md | 6 ++++--
pkg/common/db/unrelation/mongo.go | 4 ++--
scripts/install/dependency.sh | 4 ++--
3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/docs/contrib/environment.md b/docs/contrib/environment.md
index e52d57235..8db462688 100644
--- a/docs/contrib/environment.md
+++ b/docs/contrib/environment.md
@@ -304,8 +304,10 @@ This section involves setting up MongoDB, including its port, address, and crede
| -------------- | -------------- | ----------------------- |
| MONGO_PORT | "27017" | Port used by MongoDB. |
| MONGO_ADDRESS | [Generated IP] | IP address for MongoDB. |
-| MONGO_USERNAME | [User Defined] | Username for MongoDB. |
-| MONGO_PASSWORD | [User Defined] | Password for MongoDB. |
+| MONGO_USERNAME | [User Defined] | Admin Username for MongoDB. |
+| MONGO_PASSWORD | [User Defined] | Admin Password for MongoDB. |
+| MONGO_OPENIM_PASSWORD | [User Defined] | OpenIM Username for MongoDB. |
+| MONGO_OPENIM_PASSWORD | [User Defined] | OpenIM Password for MongoDB. |
### 2.8. Tencent Cloud COS Configuration
diff --git a/pkg/common/db/unrelation/mongo.go b/pkg/common/db/unrelation/mongo.go
index 279a7901e..b8184d767 100644
--- a/pkg/common/db/unrelation/mongo.go
+++ b/pkg/common/db/unrelation/mongo.go
@@ -78,8 +78,8 @@ func buildMongoURI() string {
return config.Config.Mongo.Uri
}
- username := os.Getenv("MONGO_USERNAME")
- password := os.Getenv("MONGO_PASSWORD")
+ username := os.Getenv("MONGO_OPENIM_USERNAME")
+ password := os.Getenv("MONGO_OPENIM_PASSWORD")
address := os.Getenv("MONGO_ADDRESS")
port := os.Getenv("MONGO_PORT")
database := os.Getenv("MONGO_DATABASE")
diff --git a/scripts/install/dependency.sh b/scripts/install/dependency.sh
index bfa0909e2..78995bcf9 100755
--- a/scripts/install/dependency.sh
+++ b/scripts/install/dependency.sh
@@ -35,8 +35,8 @@ docker run -d \
-e MONGO_INITDB_ROOT_USERNAME=${OPENIM_USER} \
-e MONGO_INITDB_ROOT_PASSWORD=${PASSWORD} \
-e MONGO_INITDB_DATABASE=openIM \
- -e MONGO_USERNAME=${OPENIM_USER} \
- -e MONGO_PASSWORD=${PASSWORD} \
+ -e MONGO_OPENIM_USERNAME=${OPENIM_USER} \
+ -e MONGO_OPENIM_PASSWORD=${PASSWORD} \
--restart always \
mongo:6.0.2 --wiredTigerCacheSizeGB 1 --auth
From c71bcefcbe2ee65daa323b8a5e3598bfbcb78fe6 Mon Sep 17 00:00:00 2001
From: luhaoling <2198702716@qq.com>
Date: Mon, 8 Jan 2024 18:27:50 +0800
Subject: [PATCH 09/17] fix: fix some bug
---
go.mod | 4 +-
go.sum | 4 +-
internal/rpc/user/user.go | 101 ++++++++++++---------------
pkg/common/db/controller/user.go | 6 ++
pkg/common/db/mgo/user.go | 4 ++
pkg/common/db/table/relation/user.go | 1 +
6 files changed, 60 insertions(+), 60 deletions(-)
diff --git a/go.mod b/go.mod
index f10e123a0..345cf044d 100644
--- a/go.mod
+++ b/go.mod
@@ -4,8 +4,8 @@ go 1.19
require (
firebase.google.com/go v3.13.0+incompatible
- github.com/OpenIMSDK/protocol v0.0.44
- github.com/OpenIMSDK/tools v0.0.21
+ github.com/OpenIMSDK/protocol v0.0.46
+ github.com/OpenIMSDK/tools v0.0.23
github.com/bwmarrin/snowflake v0.3.0 // indirect
github.com/dtm-labs/rockscache v0.1.1
github.com/gin-gonic/gin v1.9.1
diff --git a/go.sum b/go.sum
index 34f5d3ae9..a0bca1238 100644
--- a/go.sum
+++ b/go.sum
@@ -18,8 +18,8 @@ firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIw
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/IBM/sarama v1.41.3 h1:MWBEJ12vHC8coMjdEXFq/6ftO6DUZnQlFYcxtOJFa7c=
github.com/IBM/sarama v1.41.3/go.mod h1:Xxho9HkHd4K/MDUo/T/sOqwtX/17D33++E9Wib6hUdQ=
-github.com/OpenIMSDK/protocol v0.0.44 h1:P+9gJ9EW3y+VmzrjPludzn/5r1fjubaC19mKYJ7Oiew=
-github.com/OpenIMSDK/protocol v0.0.44/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y=
+github.com/OpenIMSDK/protocol v0.0.46 h1:LKfwcC3pUcJKSxiIyj82fc479BuDbDtsCrPxa7bHxmo=
+github.com/OpenIMSDK/protocol v0.0.46/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y=
github.com/OpenIMSDK/tools v0.0.21 h1:iTapc2mIEVH/xl5Nd6jfwPub11Pgp44tVcE1rjB3a48=
github.com/OpenIMSDK/tools v0.0.21/go.mod h1:eg+q4A34Qmu73xkY0mt37FHGMCMfC6CtmOnm0kFEGFI=
github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM=
diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go
index 51403d631..74d4a7512 100644
--- a/internal/rpc/user/user.go
+++ b/internal/rpc/user/user.go
@@ -17,6 +17,7 @@ package user
import (
"context"
"errors"
+ "github.com/OpenIMSDK/tools/pagination"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
"math/rand"
"strings"
@@ -58,6 +59,11 @@ type userServer struct {
RegisterCenter registry.SvcDiscoveryRegistry
}
+func (s *userServer) ProcessUserCommandGetAll(ctx context.Context, req *pbuser.ProcessUserCommandGetAllReq) (*pbuser.ProcessUserCommandGetAllResp, error) {
+ //TODO implement me
+ panic("implement me")
+}
+
func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
rdb, err := cache.NewRedis()
if err != nil {
@@ -228,7 +234,7 @@ func (s *userServer) AccountCheck(ctx context.Context, req *pbuser.AccountCheckR
}
func (s *userServer) GetPaginationUsers(ctx context.Context, req *pbuser.GetPaginationUsersReq) (resp *pbuser.GetPaginationUsersResp, err error) {
- total, users, err := s.Page(ctx, req.Pagination)
+ total, users, err := s.PageFindUser(ctx, constant.IMOrdinaryUser, req.Pagination)
if err != nil {
return nil, err
}
@@ -379,11 +385,6 @@ func (s *userServer) GetSubscribeUsersStatus(ctx context.Context,
// ProcessUserCommandAdd user general function add
func (s *userServer) ProcessUserCommandAdd(ctx context.Context, req *pbuser.ProcessUserCommandAddReq) (*pbuser.ProcessUserCommandAddResp, error) {
- // Assuming you have a method in s.UserDatabase to add a user command
- err := s.UserDatabase.AddUserCommand(ctx, req.UserID, req.Type, req.Uuid, req.Value)
- if err != nil {
- return nil, err
- }
return &pbuser.ProcessUserCommandAddResp{}, nil
}
@@ -395,42 +396,19 @@ func (s *userServer) ProcessUserCommandDelete(ctx context.Context, req *pbuser.P
if err != nil {
return nil, err
}
-
return &pbuser.ProcessUserCommandDeleteResp{}, nil
}
// ProcessUserCommandUpdate user general function update
func (s *userServer) ProcessUserCommandUpdate(ctx context.Context, req *pbuser.ProcessUserCommandUpdateReq) (*pbuser.ProcessUserCommandUpdateResp, error) {
- // Assuming you have a method in s.UserDatabase to update a user command
- err := s.UserDatabase.UpdateUserCommand(ctx, req.UserID, req.Type, req.Uuid, req.Value)
- if err != nil {
- return nil, err
- }
return &pbuser.ProcessUserCommandUpdateResp{}, nil
}
func (s *userServer) ProcessUserCommandGet(ctx context.Context, req *pbuser.ProcessUserCommandGetReq) (*pbuser.ProcessUserCommandGetResp, error) {
- // Fetch user commands from the database
- commands, err := s.UserDatabase.GetUserCommands(ctx, req.UserID, req.Type)
- if err != nil {
- return nil, err
- }
-
- // Initialize commandInfoSlice as an empty slice
- commandInfoSlice := make([]*pbuser.CommandInfoResp, 0, len(commands))
-
- for _, command := range commands {
- // No need to use index since command is already a pointer
- commandInfoSlice = append(commandInfoSlice, &pbuser.CommandInfoResp{
- Uuid: command.Uuid,
- Value: command.Value,
- CreateTime: command.CreateTime,
- })
- }
// Return the response with the slice
- return &pbuser.ProcessUserCommandGetResp{KVArray: commandInfoSlice}, nil
+ return &pbuser.ProcessUserCommandGetResp{}, nil
}
func (s *userServer) AddNotificationAccount(ctx context.Context, req *pbuser.AddNotificationAccountReq) (*pbuser.AddNotificationAccountResp, error) {
@@ -438,22 +416,23 @@ func (s *userServer) AddNotificationAccount(ctx context.Context, req *pbuser.Add
return nil, err
}
- var userID string
- for i := 0; i < 20; i++ {
- userId := s.genUserID()
- _, err := s.UserDatabase.FindWithError(ctx, []string{userId})
- if err == nil {
- continue
+ if req.UserID == "" {
+ for i := 0; i < 20; i++ {
+ userId := s.genUserID()
+ _, err := s.UserDatabase.FindWithError(ctx, []string{userId})
+ if err == nil {
+ continue
+ }
+ req.UserID = userId
+ break
+ }
+ if req.UserID == "" {
+ return nil, errs.ErrInternalServer.Wrap("gen user id failed")
}
- userID = userId
- break
- }
- if userID == "" {
- return nil, errs.ErrInternalServer.Wrap("gen user id failed")
}
user := &tablerelation.UserModel{
- UserID: userID,
+ UserID: req.UserID,
Nickname: req.NickName,
FaceURL: req.FaceURL,
CreateTime: time.Now(),
@@ -463,7 +442,11 @@ func (s *userServer) AddNotificationAccount(ctx context.Context, req *pbuser.Add
return nil, err
}
- return &pbuser.AddNotificationAccountResp{}, nil
+ return &pbuser.AddNotificationAccountResp{
+ UserID: req.UserID,
+ NickName: req.NickName,
+ FaceURL: req.FaceURL,
+ }, nil
}
func (s *userServer) UpdateNotificationAccountInfo(ctx context.Context, req *pbuser.UpdateNotificationAccountInfoReq) (*pbuser.UpdateNotificationAccountInfoResp, error) {
@@ -497,30 +480,33 @@ func (s *userServer) SearchNotificationAccount(ctx context.Context, req *pbuser.
return nil, err
}
- if req.NickName != "" {
- users, err := s.UserDatabase.FindByNickname(ctx, req.NickName)
+ var users []*relation.UserModel
+ var err error
+ if req.Keyword != "" {
+ users, err = s.UserDatabase.Find(ctx, []string{req.Keyword})
if err != nil {
return nil, err
}
- resp := s.userModelToResp(users)
- return resp, nil
- }
-
- if req.UserID != "" {
- users, err := s.UserDatabase.Find(ctx, []string{req.UserID})
+ resp := s.userModelToResp(users, req.Pagination)
+ if resp.Total != 0 {
+ return resp, nil
+ }
+ users, err = s.UserDatabase.FindByNickname(ctx, req.Keyword)
if err != nil {
return nil, err
}
- resp := s.userModelToResp(users)
+ resp = s.userModelToResp(users, req.Pagination)
+ return resp, nil
+
return resp, nil
}
- users, err := s.UserDatabase.FindNotification(ctx, constant.AppNotificationAdmin)
+ users, err = s.UserDatabase.FindNotification(ctx, constant.AppNotificationAdmin)
if err != nil {
return nil, err
}
- resp := s.userModelToResp(users)
+ resp := s.userModelToResp(users, req.Pagination)
return resp, nil
}
@@ -554,7 +540,7 @@ func (s *userServer) genUserID() string {
return string(data)
}
-func (s *userServer) userModelToResp(users []*relation.UserModel) *pbuser.SearchNotificationAccountResp {
+func (s *userServer) userModelToResp(users []*relation.UserModel, pagination pagination.Pagination) *pbuser.SearchNotificationAccountResp {
accounts := make([]*pbuser.NotificationAccountInfo, 0)
var total int64
for _, v := range users {
@@ -568,5 +554,8 @@ func (s *userServer) userModelToResp(users []*relation.UserModel) *pbuser.Search
total += 1
}
}
- return &pbuser.SearchNotificationAccountResp{Total: total, NotificationAccounts: accounts}
+
+ notificationAccounts := utils.Paginate(accounts, int(pagination.GetPageNumber()), int(pagination.GetShowNumber()))
+
+ return &pbuser.SearchNotificationAccountResp{Total: total, NotificationAccounts: notificationAccounts}
}
diff --git a/pkg/common/db/controller/user.go b/pkg/common/db/controller/user.go
index a109b81ef..f664417db 100644
--- a/pkg/common/db/controller/user.go
+++ b/pkg/common/db/controller/user.go
@@ -48,6 +48,8 @@ type UserDatabase interface {
//Update(ctx context.Context, user *relation.UserModel) (err error)
// UpdateByMap update (zero value) external guarantee userID exists
UpdateByMap(ctx context.Context, userID string, args map[string]any) (err error)
+ // FindUser
+ PageFindUser(ctx context.Context, level int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error)
// Page If not found, no error is returned
Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error)
// IsExist true as long as one exists
@@ -182,6 +184,10 @@ func (u *userDatabase) Page(ctx context.Context, pagination pagination.Paginatio
return u.userDB.Page(ctx, pagination)
}
+func (u *userDatabase) PageFindUser(ctx context.Context, level int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error) {
+ return u.userDB.PageFindUser(ctx, level, pagination)
+}
+
// IsExist Does userIDs exist? As long as there is one, it will be true.
func (u *userDatabase) IsExist(ctx context.Context, userIDs []string) (exist bool, err error) {
users, err := u.userDB.Find(ctx, userIDs)
diff --git a/pkg/common/db/mgo/user.go b/pkg/common/db/mgo/user.go
index 27ca264dd..892a42003 100644
--- a/pkg/common/db/mgo/user.go
+++ b/pkg/common/db/mgo/user.go
@@ -77,6 +77,10 @@ func (u *UserMgo) Page(ctx context.Context, pagination pagination.Pagination) (c
return mgoutil.FindPage[*relation.UserModel](ctx, u.coll, bson.M{}, pagination)
}
+func (u *UserMgo) PageFindUser(ctx context.Context, level int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error) {
+ return mgoutil.FindPage[*relation.UserModel](ctx, u.coll, bson.M{"app_manger_level": level}, pagination)
+}
+
func (u *UserMgo) GetAllUserID(ctx context.Context, pagination pagination.Pagination) (int64, []string, error) {
return mgoutil.FindPage[string](ctx, u.coll, bson.M{}, pagination, options.Find().SetProjection(bson.M{"user_id": 1}))
}
diff --git a/pkg/common/db/table/relation/user.go b/pkg/common/db/table/relation/user.go
index fc116adc2..9844bdcee 100644
--- a/pkg/common/db/table/relation/user.go
+++ b/pkg/common/db/table/relation/user.go
@@ -56,6 +56,7 @@ type UserModelInterface interface {
TakeNotification(ctx context.Context, level int64) (user []*UserModel, err error)
TakeByNickname(ctx context.Context, nickname string) (user []*UserModel, err error)
Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
+ PageFindUser(ctx context.Context, level int64, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
Exist(ctx context.Context, userID string) (exist bool, err error)
GetAllUserID(ctx context.Context, pagination pagination.Pagination) (count int64, userIDs []string, err error)
GetUserGlobalRecvMsgOpt(ctx context.Context, userID string) (opt int, err error)
From 093f9a3b340d05dfd5fe59c97bf38a469c864c97 Mon Sep 17 00:00:00 2001
From: Gordon <46924906+FGadvancer@users.noreply.github.com>
Date: Tue, 9 Jan 2024 10:17:39 +0800
Subject: [PATCH 10/17] fix: group messages sync failed.
---
pkg/common/db/controller/conversation.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pkg/common/db/controller/conversation.go b/pkg/common/db/controller/conversation.go
index 2a0cb63e4..c6629e9c8 100644
--- a/pkg/common/db/controller/conversation.go
+++ b/pkg/common/db/controller/conversation.go
@@ -279,7 +279,7 @@ func (c *conversationDatabase) CreateGroupChatConversation(ctx context.Context,
for _, v := range existConversationUserIDs {
cache = cache.DelConversations(v, conversationID)
}
- return c.cache.ExecDel(ctx)
+ return cache.ExecDel(ctx)
})
}
From 89b59eb82eacf7eecbc6aca37a4cbfafdd4335a8 Mon Sep 17 00:00:00 2001
From: luhaoling <2198702716@qq.com>
Date: Tue, 9 Jan 2024 18:48:58 +0800
Subject: [PATCH 11/17] fix: fix the valiable name
---
go.mod | 2 +-
internal/api/conversation.go | 4 ++--
internal/api/route.go | 2 +-
internal/rpc/conversation/conversaion.go | 18 +++++++++---------
4 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/go.mod b/go.mod
index 345cf044d..5e8e7275b 100644
--- a/go.mod
+++ b/go.mod
@@ -4,7 +4,7 @@ go 1.19
require (
firebase.google.com/go v3.13.0+incompatible
- github.com/OpenIMSDK/protocol v0.0.46
+ github.com/OpenIMSDK/protocol v0.0.47
github.com/OpenIMSDK/tools v0.0.23
github.com/bwmarrin/snowflake v0.3.0 // indirect
github.com/dtm-labs/rockscache v0.1.1
diff --git a/internal/api/conversation.go b/internal/api/conversation.go
index 6463cbde6..eb735e550 100644
--- a/internal/api/conversation.go
+++ b/internal/api/conversation.go
@@ -33,8 +33,8 @@ func (o *ConversationApi) GetAllConversations(c *gin.Context) {
a2r.Call(conversation.ConversationClient.GetAllConversations, o.Client, c)
}
-func (o *ConversationApi) GetConversationsList(c *gin.Context) {
- a2r.Call(conversation.ConversationClient.GetConversationList, o.Client, c)
+func (o *ConversationApi) GetSortedConversationList(c *gin.Context) {
+ a2r.Call(conversation.ConversationClient.GetSortedConversationList, o.Client, c)
}
func (o *ConversationApi) GetConversation(c *gin.Context) {
diff --git a/internal/api/route.go b/internal/api/route.go
index 1c91f4dde..fa34f109a 100644
--- a/internal/api/route.go
+++ b/internal/api/route.go
@@ -204,7 +204,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
conversationGroup := r.Group("/conversation", ParseToken)
{
c := NewConversationApi(*conversationRpc)
- conversationGroup.POST("/get_conversations_list", c.GetConversationsList)
+ conversationGroup.POST("/get_sorted_conversation_list", c.GetSortedConversationList)
conversationGroup.POST("/get_all_conversations", c.GetAllConversations)
conversationGroup.POST("/get_conversation", c.GetConversation)
conversationGroup.POST("/get_conversations", c.GetConversations)
diff --git a/internal/rpc/conversation/conversaion.go b/internal/rpc/conversation/conversaion.go
index b80e32953..9ce5a3b67 100644
--- a/internal/rpc/conversation/conversaion.go
+++ b/internal/rpc/conversation/conversaion.go
@@ -89,7 +89,7 @@ func (c *conversationServer) GetConversation(ctx context.Context, req *pbconvers
return resp, nil
}
-func (m *conversationServer) GetConversationList(ctx context.Context, req *pbconversation.GetConversationListReq) (resp *pbconversation.GetConversationListResp, err error) {
+func (m *conversationServer) GetSortedConversationList(ctx context.Context, req *pbconversation.GetSortedConversationListReq) (resp *pbconversation.GetSortedConversationListResp, err error) {
log.ZDebug(ctx, "GetConversationList", "seqs", req, "userID", req.UserID)
var conversationIDs []string
if len(req.ConversationIDs) == 0 {
@@ -134,25 +134,25 @@ func (m *conversationServer) GetConversationList(ctx context.Context, req *pbcon
conversation_unreadCount[conversationID] = maxSeq - hasReadSeqs[conversationID]
}
- conversation_isPinkTime := make(map[int64]string)
- conversation_notPinkTime := make(map[int64]string)
+ conversation_isPinTime := make(map[int64]string)
+ conversation_notPinTime := make(map[int64]string)
for _, v := range conversations {
conversationID := v.ConversationID
time := conversationMsg[conversationID].MsgInfo.LatestMsgRecvTime
conversationMsg[conversationID].RecvMsgOpt = v.RecvMsgOpt
if v.IsPinned {
conversationMsg[conversationID].IsPinned = v.IsPinned
- conversation_isPinkTime[time] = conversationID
+ conversation_isPinTime[time] = conversationID
continue
}
- conversation_notPinkTime[time] = conversationID
+ conversation_notPinTime[time] = conversationID
}
- resp = &pbconversation.GetConversationListResp{
+ resp = &pbconversation.GetSortedConversationListResp{
ConversationElems: []*pbconversation.ConversationElem{},
}
- m.conversationSort(conversation_isPinkTime, resp, conversation_unreadCount, conversationMsg)
- m.conversationSort(conversation_notPinkTime, resp, conversation_unreadCount, conversationMsg)
+ m.conversationSort(conversation_isPinTime, resp, conversation_unreadCount, conversationMsg)
+ m.conversationSort(conversation_notPinTime, resp, conversation_unreadCount, conversationMsg)
return resp, nil
}
@@ -425,7 +425,7 @@ func (c *conversationServer) GetConversationOfflinePushUserIDs(
func (c *conversationServer) conversationSort(
conversations map[int64]string,
- resp *pbconversation.GetConversationListResp,
+ resp *pbconversation.GetSortedConversationListResp,
conversation_unreadCount map[string]int64,
conversationMsg map[string]*pbconversation.ConversationElem,
) {
From 159822e207508a280445486585f8081fb15412e2 Mon Sep 17 00:00:00 2001
From: luhaoling <2198702716@qq.com>
Date: Tue, 9 Jan 2024 18:58:17 +0800
Subject: [PATCH 12/17] fix: fix the getSortedConversation api
---
internal/rpc/conversation/conversaion.go | 11 +++++++++--
internal/rpc/user/user.go | 5 +++++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/internal/rpc/conversation/conversaion.go b/internal/rpc/conversation/conversaion.go
index 9ce5a3b67..d0d59547c 100644
--- a/internal/rpc/conversation/conversaion.go
+++ b/internal/rpc/conversation/conversaion.go
@@ -90,7 +90,7 @@ func (c *conversationServer) GetConversation(ctx context.Context, req *pbconvers
}
func (m *conversationServer) GetSortedConversationList(ctx context.Context, req *pbconversation.GetSortedConversationListReq) (resp *pbconversation.GetSortedConversationListResp, err error) {
- log.ZDebug(ctx, "GetConversationList", "seqs", req, "userID", req.UserID)
+ log.ZDebug(ctx, "GetSortedConversationList", "seqs", req, "userID", req.UserID)
var conversationIDs []string
if len(req.ConversationIDs) == 0 {
conversationIDs, err = m.conversationDatabase.GetConversationIDs(ctx, req.UserID)
@@ -129,9 +129,12 @@ func (m *conversationServer) GetSortedConversationList(ctx context.Context, req
return nil, err
}
+ var unreadTotal int64
conversation_unreadCount := make(map[string]int64)
for conversationID, maxSeq := range maxSeqs {
- conversation_unreadCount[conversationID] = maxSeq - hasReadSeqs[conversationID]
+ unreadCount := maxSeq - hasReadSeqs[conversationID]
+ conversation_unreadCount[conversationID] = unreadCount
+ unreadTotal += unreadCount
}
conversation_isPinTime := make(map[int64]string)
@@ -148,11 +151,15 @@ func (m *conversationServer) GetSortedConversationList(ctx context.Context, req
conversation_notPinTime[time] = conversationID
}
resp = &pbconversation.GetSortedConversationListResp{
+ ConversationTotal: int64(len(chatLogs)),
ConversationElems: []*pbconversation.ConversationElem{},
+ UnreadTotal: unreadTotal,
}
m.conversationSort(conversation_isPinTime, resp, conversation_unreadCount, conversationMsg)
m.conversationSort(conversation_notPinTime, resp, conversation_unreadCount, conversationMsg)
+
+ resp.ConversationElems = utils.Paginate(resp.ConversationElems, int(req.Pagination.GetPageNumber()), int(req.Pagination.GetShowNumber()))
return resp, nil
}
diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go
index 74d4a7512..5680c2b3d 100644
--- a/internal/rpc/user/user.go
+++ b/internal/rpc/user/user.go
@@ -429,6 +429,11 @@ func (s *userServer) AddNotificationAccount(ctx context.Context, req *pbuser.Add
if req.UserID == "" {
return nil, errs.ErrInternalServer.Wrap("gen user id failed")
}
+ } else {
+ _, err := s.UserDatabase.FindWithError(ctx, []string{req.UserID})
+ if err == nil {
+ return nil, errs.ErrArgs.Wrap("userID is used")
+ }
}
user := &tablerelation.UserModel{
From 8d5d54af33b5e10b4eb382427bf44be115de6714 Mon Sep 17 00:00:00 2001
From: luhaoling <2198702716@qq.com>
Date: Wed, 10 Jan 2024 18:24:24 +0800
Subject: [PATCH 13/17] fix: fix the mongo search error
---
pkg/common/db/mgo/user.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pkg/common/db/mgo/user.go b/pkg/common/db/mgo/user.go
index 892a42003..574689fc1 100644
--- a/pkg/common/db/mgo/user.go
+++ b/pkg/common/db/mgo/user.go
@@ -82,7 +82,7 @@ func (u *UserMgo) PageFindUser(ctx context.Context, level int64, pagination pagi
}
func (u *UserMgo) GetAllUserID(ctx context.Context, pagination pagination.Pagination) (int64, []string, error) {
- return mgoutil.FindPage[string](ctx, u.coll, bson.M{}, pagination, options.Find().SetProjection(bson.M{"user_id": 1}))
+ return mgoutil.FindPage[string](ctx, u.coll, bson.M{}, pagination, options.Find().SetProjection(bson.M{"_id": 0, "user_id": 1}))
}
func (u *UserMgo) Exist(ctx context.Context, userID string) (exist bool, err error) {
@@ -90,7 +90,7 @@ func (u *UserMgo) Exist(ctx context.Context, userID string) (exist bool, err err
}
func (u *UserMgo) GetUserGlobalRecvMsgOpt(ctx context.Context, userID string) (opt int, err error) {
- return mgoutil.FindOne[int](ctx, u.coll, bson.M{"user_id": userID}, options.FindOne().SetProjection(bson.M{"global_recv_msg_opt": 1}))
+ return mgoutil.FindOne[int](ctx, u.coll, bson.M{"user_id": userID}, options.FindOne().SetProjection(bson.M{"_id": 0, "global_recv_msg_opt": 1}))
}
func (u *UserMgo) CountTotal(ctx context.Context, before *time.Time) (count int64, err error) {
From 0c745782b09d40d4cf54bbb9e09ecb84ba1876c3 Mon Sep 17 00:00:00 2001
From: withchao <993506633@qq.com>
Date: Thu, 11 Jan 2024 11:18:52 +0800
Subject: [PATCH 14/17] fix: GroupApplicationAcceptedNotification
(cherry picked from commit 4c3c4555a35ec8e31ffbf3e96a5dba3bceec09ee)
---
pkg/rpcclient/notification/group.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pkg/rpcclient/notification/group.go b/pkg/rpcclient/notification/group.go
index cbae7c49b..f2413143d 100755
--- a/pkg/rpcclient/notification/group.go
+++ b/pkg/rpcclient/notification/group.go
@@ -413,7 +413,7 @@ func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(ctx conte
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
- for _, userID := range append(userIDs, mcontext.GetOpUserID(ctx)) {
+ for _, userID := range append(userIDs, req.FromUserID) {
err = g.Notification(ctx, mcontext.GetOpUserID(ctx), userID, constant.GroupApplicationAcceptedNotification, tips)
if err != nil {
log.ZError(ctx, "failed", err)
@@ -441,7 +441,7 @@ func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx conte
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
- for _, userID := range append(userIDs, mcontext.GetOpUserID(ctx)) {
+ for _, userID := range append(userIDs, req.FromUserID) {
err = g.Notification(ctx, mcontext.GetOpUserID(ctx), userID, constant.GroupApplicationRejectedNotification, tips)
if err != nil {
log.ZError(ctx, "failed", err)
From c2b8279ddc649cf2f8e6c787db581789f07690e0 Mon Sep 17 00:00:00 2001
From: withchao <993506633@qq.com>
Date: Thu, 11 Jan 2024 16:31:24 +0800
Subject: [PATCH 15/17] fix: GroupApplicationAcceptedNotification
---
pkg/rpcclient/notification/group.go | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/pkg/rpcclient/notification/group.go b/pkg/rpcclient/notification/group.go
index f2413143d..8c3719b2c 100755
--- a/pkg/rpcclient/notification/group.go
+++ b/pkg/rpcclient/notification/group.go
@@ -409,11 +409,16 @@ func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(ctx conte
if err != nil {
return err
}
- tips := &sdkws.GroupApplicationAcceptedTips{Group: group, HandleMsg: req.HandledMsg, ReceiverAs: 1}
+ tips := &sdkws.GroupApplicationAcceptedTips{Group: group, HandleMsg: req.HandledMsg}
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
for _, userID := range append(userIDs, req.FromUserID) {
+ if userID == req.FromUserID {
+ tips.ReceiverAs = 0
+ } else {
+ tips.ReceiverAs = 1
+ }
err = g.Notification(ctx, mcontext.GetOpUserID(ctx), userID, constant.GroupApplicationAcceptedNotification, tips)
if err != nil {
log.ZError(ctx, "failed", err)
@@ -442,6 +447,11 @@ func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx conte
return err
}
for _, userID := range append(userIDs, req.FromUserID) {
+ if userID == req.FromUserID {
+ tips.ReceiverAs = 0
+ } else {
+ tips.ReceiverAs = 1
+ }
err = g.Notification(ctx, mcontext.GetOpUserID(ctx), userID, constant.GroupApplicationRejectedNotification, tips)
if err != nil {
log.ZError(ctx, "failed", err)
From 07dfde965c1987ab2c9fb44fabee4eb57c4f5e46 Mon Sep 17 00:00:00 2001
From: AndrewZuo01
Date: Thu, 11 Jan 2024 20:41:24 +0800
Subject: [PATCH 16/17] fix update friends
---
internal/rpc/friend/friend.go | 29 +++++++-------
pkg/common/db/cache/friend.go | 14 +++++++
pkg/common/db/controller/friend.go | 30 ++++----------
pkg/common/db/mgo/friend.go | 54 +++++++-------------------
pkg/common/db/table/relation/friend.go | 8 +---
pkg/rpcclient/notification/friend.go | 2 +-
6 files changed, 50 insertions(+), 87 deletions(-)
diff --git a/internal/rpc/friend/friend.go b/internal/rpc/friend/friend.go
index c53cb88f5..84702f548 100644
--- a/internal/rpc/friend/friend.go
+++ b/internal/rpc/friend/friend.go
@@ -452,22 +452,19 @@ func (s *friendServer) UpdateFriends(
return nil, err
}
- for _, friendID := range req.FriendUserIDs {
- if req.IsPinned != nil {
- if err = s.friendDatabase.UpdateFriendPinStatus(ctx, req.OwnerUserID, friendID, req.IsPinned.Value); err != nil {
- return nil, err
- }
- }
- if req.Remark != nil {
- if err = s.friendDatabase.UpdateFriendRemark(ctx, req.OwnerUserID, friendID, req.Remark.Value); err != nil {
- return nil, err
- }
- }
- if req.Ex != nil {
- if err = s.friendDatabase.UpdateFriendEx(ctx, req.OwnerUserID, friendID, req.Ex.Value); err != nil {
- return nil, err
- }
- }
+ val := make(map[string]any)
+
+ if req.IsPinned != nil {
+ val["is_pinned"] = req.IsPinned.Value
+ }
+ if req.Remark != nil {
+ val["remark"] = req.Remark.Value
+ }
+ if req.Ex != nil {
+ val["ex"] = req.Ex.Value
+ }
+ if err = s.friendDatabase.UpdateFriends(ctx, req.OwnerUserID, req.FriendUserIDs, val); err != nil {
+ return nil, err
}
resp := &pbfriend.UpdateFriendsResp{}
diff --git a/pkg/common/db/cache/friend.go b/pkg/common/db/cache/friend.go
index 1708f7664..a2b60d48f 100644
--- a/pkg/common/db/cache/friend.go
+++ b/pkg/common/db/cache/friend.go
@@ -44,6 +44,8 @@ type FriendCache interface {
GetFriend(ctx context.Context, ownerUserID, friendUserID string) (friend *relationtb.FriendModel, err error)
// Delete friend when friend info changed
DelFriend(ownerUserID, friendUserID string) FriendCache
+ // Delete friends when friends' info changed
+ DelFriends(ownerUserID string, friendUserIDs []string) FriendCache
}
// FriendCacheRedis is an implementation of the FriendCache interface using Redis.
@@ -152,3 +154,15 @@ func (f *FriendCacheRedis) DelFriend(ownerUserID, friendUserID string) FriendCac
return newFriendCache
}
+
+// DelFriends deletes multiple friend infos from the cache.
+func (f *FriendCacheRedis) DelFriends(ownerUserID string, friendUserIDs []string) FriendCache {
+ newFriendCache := f.NewCache()
+
+ for _, friendUserID := range friendUserIDs {
+ key := f.getFriendKey(ownerUserID, friendUserID)
+ newFriendCache.AddKeys(key) // Assuming AddKeys marks the keys for deletion
+ }
+
+ return newFriendCache
+}
diff --git a/pkg/common/db/controller/friend.go b/pkg/common/db/controller/friend.go
index 924a179ba..3b98f5d7b 100644
--- a/pkg/common/db/controller/friend.go
+++ b/pkg/common/db/controller/friend.go
@@ -74,15 +74,8 @@ type FriendDatabase interface {
// FindBothFriendRequests finds friend requests sent and received
FindBothFriendRequests(ctx context.Context, fromUserID, toUserID string) (friends []*relation.FriendRequestModel, err error)
- // UpdateFriendPinStatus updates the pinned status of a friend
- UpdateFriendPinStatus(ctx context.Context, ownerUserID string, friendUserID string, isPinned bool) (err error)
-
- // UpdateFriendRemark updates the remark for a friend
- UpdateFriendRemark(ctx context.Context, ownerUserID string, friendUserID string, remark string) (err error)
-
- // UpdateFriendEx updates the 'ex' field for a friend
- UpdateFriendEx(ctx context.Context, ownerUserID string, friendUserID string, ex string) (err error)
-
+ // UpdateFriends updates fields for friends
+ UpdateFriends(ctx context.Context, ownerUserID string, friendUserIDs []string, val map[string]any) (err error)
}
type friendDatabase struct {
@@ -323,21 +316,12 @@ func (f *friendDatabase) FindFriendUserIDs(ctx context.Context, ownerUserID stri
func (f *friendDatabase) FindBothFriendRequests(ctx context.Context, fromUserID, toUserID string) (friends []*relation.FriendRequestModel, err error) {
return f.friendRequest.FindBothFriendRequests(ctx, fromUserID, toUserID)
}
-func (f *friendDatabase) UpdateFriendPinStatus(ctx context.Context, ownerUserID string, friendUserID string, isPinned bool) (err error) {
- if err := f.friend.UpdatePinStatus(ctx, ownerUserID, friendUserID, isPinned); err != nil {
- return err
+func (f *friendDatabase) UpdateFriends(ctx context.Context, ownerUserID string, friendUserIDs []string, val map[string]any) (err error) {
+ if len(val) == 0 {
+ return nil
}
- return f.cache.DelFriend(ownerUserID, friendUserID).ExecDel(ctx)
-}
-func (f *friendDatabase) UpdateFriendRemark(ctx context.Context, ownerUserID string, friendUserID string, remark string) (err error) {
- if err := f.friend.UpdateFriendRemark(ctx, ownerUserID, friendUserID, remark); err != nil {
+ if err := f.friend.UpdateFriends(ctx, ownerUserID, friendUserIDs, val); err != nil {
return err
}
- return f.cache.DelFriend(ownerUserID, friendUserID).ExecDel(ctx)
-}
-func (f *friendDatabase) UpdateFriendEx(ctx context.Context, ownerUserID string, friendUserID string, ex string) (err error) {
- if err := f.friend.UpdateFriendEx(ctx, ownerUserID, friendUserID, ex); err != nil {
- return err
- }
- return f.cache.DelFriend(ownerUserID, friendUserID).ExecDel(ctx)
+ return f.cache.DelFriends(ownerUserID, friendUserIDs).ExecDel(ctx)
}
diff --git a/pkg/common/db/mgo/friend.go b/pkg/common/db/mgo/friend.go
index 72289181b..b4172d0fb 100644
--- a/pkg/common/db/mgo/friend.go
+++ b/pkg/common/db/mgo/friend.go
@@ -16,7 +16,6 @@ package mgo
import (
"context"
- "github.com/OpenIMSDK/tools/errs"
"github.com/OpenIMSDK/tools/mgoutil"
"github.com/OpenIMSDK/tools/pagination"
"go.mongodb.org/mongo-driver/mongo/options"
@@ -144,49 +143,22 @@ func (f *FriendMgo) FindFriendUserIDs(ctx context.Context, ownerUserID string) (
return mgoutil.Find[string](ctx, f.coll, filter, options.Find().SetProjection(bson.M{"_id": 0, "friend_user_id": 1}))
}
-// UpdatePinStatus update friend's pin status
-func (f *FriendMgo) UpdatePinStatus(ctx context.Context, ownerUserID string, friendUserID string, isPinned bool) (err error) {
-
- filter := bson.M{"owner_user_id": ownerUserID, "friend_user_id": friendUserID}
- // Create an update operation to set the "is_pinned" field to isPinned for all documents.
- update := bson.M{"$set": bson.M{"is_pinned": isPinned}}
-
- // Perform the update operation for all documents in the collection.
- _, err = f.coll.UpdateMany(ctx, filter, update)
-
- if err != nil {
- return errs.Wrap(err, "update pin error")
+func (f *FriendMgo) UpdateFriends(ctx context.Context, ownerUserID string, friendUserIDs []string, val map[string]any) error {
+ // Ensure there are IDs to update
+ if len(friendUserIDs) == 0 {
+ return nil // Or return an error if you expect there to always be IDs
}
- return nil
-}
-func (f *FriendMgo) UpdateFriendRemark(ctx context.Context, ownerUserID string, friendUserID string, remark string) (err error) {
-
- filter := bson.M{"owner_user_id": ownerUserID, "friend_user_id": friendUserID}
- // Create an update operation to set the "is_pinned" field to isPinned for all documents.
- update := bson.M{"$set": bson.M{"remark": remark}}
-
- // Perform the update operation for all documents in the collection.
- _, err = f.coll.UpdateMany(ctx, filter, update)
-
- if err != nil {
- return errs.Wrap(err, "update remark error")
+ // Create a filter to match documents with the specified ownerUserID and any of the friendUserIDs
+ filter := bson.M{
+ "owner_user_id": ownerUserID,
+ "friend_user_id": bson.M{"$in": friendUserIDs},
}
- return nil
-}
-func (f *FriendMgo) UpdateFriendEx(ctx context.Context, ownerUserID string, friendUserID string, ex string) (err error) {
-
- filter := bson.M{"owner_user_id": ownerUserID, "friend_user_id": friendUserID}
- // Create an update operation to set the "is_pinned" field to isPinned for all documents.
- update := bson.M{"$set": bson.M{"ex": ex}}
-
- // Perform the update operation for all documents in the collection.
- _, err = f.coll.UpdateMany(ctx, filter, update)
-
- if err != nil {
- return errs.Wrap(err, "update ex error")
- }
+ // Create an update document
+ update := bson.M{"$set": val}
- return nil
+ // Perform the update operation for all matching documents
+ _, err := mgoutil.UpdateMany(ctx, f.coll, filter, update)
+ return err
}
diff --git a/pkg/common/db/table/relation/friend.go b/pkg/common/db/table/relation/friend.go
index cc337701d..73f7454df 100644
--- a/pkg/common/db/table/relation/friend.go
+++ b/pkg/common/db/table/relation/friend.go
@@ -57,10 +57,6 @@ type FriendModelInterface interface {
FindInWhoseFriends(ctx context.Context, friendUserID string, pagination pagination.Pagination) (total int64, friends []*FriendModel, err error)
// FindFriendUserIDs retrieves a list of friend user IDs for a given owner.
FindFriendUserIDs(ctx context.Context, ownerUserID string) (friendUserIDs []string, err error)
- // UpdatePinStatus update friend's pin status
- UpdatePinStatus(ctx context.Context, ownerUserID string, friendUserID string, isPinned bool) (err error)
- // UpdateFriendRemark update friend's remark
- UpdateFriendRemark(ctx context.Context, ownerUserID string, friendUserID string, remark string) (err error)
- // UpdateFriendEx update friend's ex
- UpdateFriendEx(ctx context.Context, ownerUserID string, friendUserID string, ex string) (err error)
+ // UpdateFriends update friends' fields
+ UpdateFriends(ctx context.Context, ownerUserID string, friendUserIDs []string, val map[string]any) (err error)
}
diff --git a/pkg/rpcclient/notification/friend.go b/pkg/rpcclient/notification/friend.go
index 00759b1b2..b98a1d38e 100644
--- a/pkg/rpcclient/notification/friend.go
+++ b/pkg/rpcclient/notification/friend.go
@@ -197,7 +197,7 @@ func (f *FriendNotificationSender) FriendRemarkSetNotification(ctx context.Conte
return f.Notification(ctx, fromUserID, toUserID, constant.FriendRemarkSetNotification, &tips)
}
func (f *FriendNotificationSender) FriendsInfoUpdateNotification(ctx context.Context, toUserID string, friendIDs []string) error {
- tips := sdkws.FriendsInfoUpdateTips{}
+ tips := sdkws.FriendsInfoUpdateTips{FromToUserID: &sdkws.FromToUserID{}}
tips.FromToUserID.ToUserID = toUserID
tips.FriendIDs = friendIDs
return f.Notification(ctx, toUserID, toUserID, constant.FriendsInfoUpdateNotification, &tips)
From 3be16ce3e82184da077ef449bf531f5391bfcd56 Mon Sep 17 00:00:00 2001
From: AndrewZuo01
Date: Fri, 12 Jan 2024 15:19:40 +0800
Subject: [PATCH 17/17] fix pageFindUser
---
internal/rpc/user/user.go | 2 +-
pkg/common/db/controller/user.go | 6 +++---
pkg/common/db/mgo/user.go | 11 +++++++++--
pkg/common/db/table/relation/user.go | 2 +-
4 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go
index 5680c2b3d..254d0564b 100644
--- a/internal/rpc/user/user.go
+++ b/internal/rpc/user/user.go
@@ -234,7 +234,7 @@ func (s *userServer) AccountCheck(ctx context.Context, req *pbuser.AccountCheckR
}
func (s *userServer) GetPaginationUsers(ctx context.Context, req *pbuser.GetPaginationUsersReq) (resp *pbuser.GetPaginationUsersResp, err error) {
- total, users, err := s.PageFindUser(ctx, constant.IMOrdinaryUser, req.Pagination)
+ total, users, err := s.PageFindUser(ctx, constant.IMOrdinaryUser, constant.AppOrdinaryUsers, req.Pagination)
if err != nil {
return nil, err
}
diff --git a/pkg/common/db/controller/user.go b/pkg/common/db/controller/user.go
index f664417db..50e3ea0fe 100644
--- a/pkg/common/db/controller/user.go
+++ b/pkg/common/db/controller/user.go
@@ -49,7 +49,7 @@ type UserDatabase interface {
// UpdateByMap update (zero value) external guarantee userID exists
UpdateByMap(ctx context.Context, userID string, args map[string]any) (err error)
// FindUser
- PageFindUser(ctx context.Context, level int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error)
+ PageFindUser(ctx context.Context, level1 int64, level2 int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error)
// Page If not found, no error is returned
Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error)
// IsExist true as long as one exists
@@ -184,8 +184,8 @@ func (u *userDatabase) Page(ctx context.Context, pagination pagination.Paginatio
return u.userDB.Page(ctx, pagination)
}
-func (u *userDatabase) PageFindUser(ctx context.Context, level int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error) {
- return u.userDB.PageFindUser(ctx, level, pagination)
+func (u *userDatabase) PageFindUser(ctx context.Context, level1 int64, level2 int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error) {
+ return u.userDB.PageFindUser(ctx, level1, level2, pagination)
}
// IsExist Does userIDs exist? As long as there is one, it will be true.
diff --git a/pkg/common/db/mgo/user.go b/pkg/common/db/mgo/user.go
index 574689fc1..af541662d 100644
--- a/pkg/common/db/mgo/user.go
+++ b/pkg/common/db/mgo/user.go
@@ -77,8 +77,15 @@ func (u *UserMgo) Page(ctx context.Context, pagination pagination.Pagination) (c
return mgoutil.FindPage[*relation.UserModel](ctx, u.coll, bson.M{}, pagination)
}
-func (u *UserMgo) PageFindUser(ctx context.Context, level int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error) {
- return mgoutil.FindPage[*relation.UserModel](ctx, u.coll, bson.M{"app_manger_level": level}, pagination)
+func (u *UserMgo) PageFindUser(ctx context.Context, level1 int64, level2 int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error) {
+ query := bson.M{
+ "$or": []bson.M{
+ {"app_manager_level": level1},
+ {"app_manager_level": level2},
+ },
+ }
+
+ return mgoutil.FindPage[*relation.UserModel](ctx, u.coll, query, pagination)
}
func (u *UserMgo) GetAllUserID(ctx context.Context, pagination pagination.Pagination) (int64, []string, error) {
diff --git a/pkg/common/db/table/relation/user.go b/pkg/common/db/table/relation/user.go
index 9844bdcee..dd7cefe59 100644
--- a/pkg/common/db/table/relation/user.go
+++ b/pkg/common/db/table/relation/user.go
@@ -56,7 +56,7 @@ type UserModelInterface interface {
TakeNotification(ctx context.Context, level int64) (user []*UserModel, err error)
TakeByNickname(ctx context.Context, nickname string) (user []*UserModel, err error)
Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
- PageFindUser(ctx context.Context, level int64, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
+ PageFindUser(ctx context.Context, level1 int64, level2 int64, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
Exist(ctx context.Context, userID string) (exist bool, err error)
GetAllUserID(ctx context.Context, pagination pagination.Pagination) (count int64, userIDs []string, err error)
GetUserGlobalRecvMsgOpt(ctx context.Context, userID string) (opt int, err error)