From 9d6b1536d26401f2d685a73d2b46a1fcb347b075 Mon Sep 17 00:00:00 2001 From: withchao <48119764+withchao@users.noreply.github.com> Date: Thu, 31 Aug 2023 14:44:02 +0800 Subject: [PATCH] add GetSpecifiedFriendsInfo (#986) * fix: create group type limit * fix: group notification * fix: group notification * fix: group notification * chore: group member hash * chore: group member hash * chore: group member hash * chore: group member hash * test: log * test: log * test: log * test: log * test: log * sync: hash code * sync: hash code * sync: hash code * test: log * test: log * test: log * test: log * test: log * fix: time stamp * fix: minio sign endpoint opts * cicd: robot automated Change Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix: minio bucket url * fix: op user info * cicd: robot automated Change Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix: importFriends Conversation * fix: importFriends Notification * cicd: robot automated Change Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix: importFriends Notification * NotificationUserInfoUpdate * NotificationUserInfoUpdate * NotificationUserInfoUpdate * NotificationUserInfoUpdate * NotificationUserInfoUpdate * NotificationUserInfoUpdate * NotificationUserInfoUpdate * TransferGroupOwner del group hash * add GetSpecifiedFriendsInfo * cicd: robot automated Change Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: withchao --- go.mod | 2 +- go.sum | 4 +- internal/api/friend.go | 4 ++ internal/api/route.go | 1 + internal/rpc/friend/friend.go | 65 +++++++++++++++++++++++++++ pkg/common/db/controller/black.go | 5 +++ pkg/common/db/relation/black_model.go | 6 +++ pkg/common/db/table/relation/black.go | 7 +-- 8 files changed, 86 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index e3891297b..1e2fd2c9c 100644 --- a/go.mod +++ b/go.mod @@ -37,7 +37,7 @@ require ( require github.com/google/uuid v1.3.0 require ( - github.com/OpenIMSDK/protocol v0.0.17 + github.com/OpenIMSDK/protocol v0.0.18 github.com/OpenIMSDK/tools v0.0.14 github.com/aliyun/aliyun-oss-go-sdk v2.2.8+incompatible github.com/go-redis/redis v6.15.9+incompatible diff --git a/go.sum b/go.sum index 92cd11a78..fcf36033e 100644 --- a/go.sum +++ b/go.sum @@ -17,8 +17,8 @@ cloud.google.com/go/storage v1.30.1/go.mod h1:NfxhC0UJE1aXSx7CIIbCf7y9HKT7Biccwk firebase.google.com/go v3.13.0+incompatible h1:3TdYC3DDi6aHn20qoRkxwGqNgdjtblwVAyRLQwGn/+4= firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIwjt8toICdV5Wh9ptHs= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/OpenIMSDK/protocol v0.0.17 h1:ixjKUVGlTW+jQK5cPaKV//6l4bk9DAlbjDhocztYSbU= -github.com/OpenIMSDK/protocol v0.0.17/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y= +github.com/OpenIMSDK/protocol v0.0.18 h1:hXukFiDMLZx7s+hDCQePIK9ABiHyNlobNL4MppvOuMY= +github.com/OpenIMSDK/protocol v0.0.18/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y= github.com/OpenIMSDK/tools v0.0.14 h1:WLof/+WxyPyRST+QkoTKubYCiV73uCLiL8pgnpH/yKQ= github.com/OpenIMSDK/tools v0.0.14/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/api/friend.go b/internal/api/friend.go index 9542a61f9..2f708901e 100644 --- a/internal/api/friend.go +++ b/internal/api/friend.go @@ -88,3 +88,7 @@ func (o *FriendApi) IsFriend(c *gin.Context) { func (o *FriendApi) GetFriendIDs(c *gin.Context) { a2r.Call(friend.FriendClient.GetFriendIDs, o.Client, c) } + +func (o *FriendApi) GetSpecifiedFriendsInfo(c *gin.Context) { + a2r.Call(friend.FriendClient.GetSpecifiedFriendsInfo, o.Client, c) +} diff --git a/internal/api/route.go b/internal/api/route.go index 0a0201d43..a118092c4 100644 --- a/internal/api/route.go +++ b/internal/api/route.go @@ -106,6 +106,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive friendRouterGroup.POST("/import_friend", f.ImportFriends) friendRouterGroup.POST("/is_friend", f.IsFriend) friendRouterGroup.POST("/get_friend_id", f.GetFriendIDs) + friendRouterGroup.POST("/get_specified_friends_info", f.GetSpecifiedFriendsInfo) } g := NewGroupApi(*groupRpc) groupRouterGroup := r.Group("/group", ParseToken) diff --git a/internal/rpc/friend/friend.go b/internal/rpc/friend/friend.go index 0efcd1d81..7b753faa5 100644 --- a/internal/rpc/friend/friend.go +++ b/internal/rpc/friend/friend.go @@ -17,6 +17,8 @@ package friend import ( "context" + "github.com/OpenIMSDK/protocol/sdkws" + "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" "github.com/OpenIMSDK/tools/log" @@ -357,3 +359,66 @@ func (s *friendServer) GetFriendIDs( } return resp, nil } + +func (s *friendServer) GetSpecifiedFriendsInfo(ctx context.Context, req *pbfriend.GetSpecifiedFriendsInfoReq) (*pbfriend.GetSpecifiedFriendsInfoResp, error) { + if len(req.UserIDList) == 0 { + return nil, errs.ErrArgs.Wrap("userIDList is empty") + } + if utils.Duplicate(req.UserIDList) { + return nil, errs.ErrArgs.Wrap("userIDList repeated") + } + userMap, err := s.userRpcClient.GetUsersInfoMap(ctx, req.UserIDList) + if err != nil { + return nil, err + } + friends, err := s.friendDatabase.FindFriendsWithError(ctx, req.OwnerUserID, req.UserIDList) + if err != nil { + return nil, err + } + blacks, err := s.blackDatabase.FindBlackInfos(ctx, req.OwnerUserID, req.UserIDList) + if err != nil { + return nil, err + } + friendMap := utils.SliceToMap(friends, func(e *tablerelation.FriendModel) string { + return e.FriendUserID + }) + blackMap := utils.SliceToMap(blacks, func(e *tablerelation.BlackModel) string { + return e.BlockUserID + }) + resp := &pbfriend.GetSpecifiedFriendsInfoResp{ + Infos: make([]*pbfriend.GetSpecifiedFriendsInfoInfo, 0, len(req.UserIDList)), + } + for _, userID := range req.UserIDList { + user := userMap[userID] + if user == nil { + continue + } + var friendInfo *sdkws.FriendInfo + if friend := friendMap[userID]; friend != nil { + friendInfo = &sdkws.FriendInfo{ + OwnerUserID: friend.OwnerUserID, + Remark: friend.Remark, + CreateTime: friend.CreateTime.UnixMilli(), + AddSource: friend.AddSource, + OperatorUserID: friend.OperatorUserID, + Ex: friend.Ex, + } + } + var blackInfo *sdkws.BlackInfo + if black := blackMap[userID]; black != nil { + blackInfo = &sdkws.BlackInfo{ + OwnerUserID: black.OwnerUserID, + CreateTime: black.CreateTime.UnixMilli(), + AddSource: black.AddSource, + OperatorUserID: black.OperatorUserID, + Ex: black.Ex, + } + } + resp.Infos = append(resp.Infos, &pbfriend.GetSpecifiedFriendsInfoInfo{ + UserInfo: user, + FriendInfo: friendInfo, + BlackInfo: blackInfo, + }) + } + return resp, nil +} diff --git a/pkg/common/db/controller/black.go b/pkg/common/db/controller/black.go index 4a239829f..a962df213 100644 --- a/pkg/common/db/controller/black.go +++ b/pkg/common/db/controller/black.go @@ -36,6 +36,7 @@ type BlackDatabase interface { pageNumber, showNumber int32, ) (blacks []*relation.BlackModel, total int64, err error) FindBlackIDs(ctx context.Context, ownerUserID string) (blackIDs []string, err error) + FindBlackInfos(ctx context.Context, ownerUserID string, userIDs []string) (blacks []*relation.BlackModel, err error) // CheckIn 检查user2是否在user1的黑名单列表中(inUser1Blacks==true) 检查user1是否在user2的黑名单列表中(inUser2Blacks==true) CheckIn(ctx context.Context, userID1, userID2 string) (inUser1Blacks bool, inUser2Blacks bool, err error) } @@ -102,3 +103,7 @@ func (b *blackDatabase) CheckIn( func (b *blackDatabase) FindBlackIDs(ctx context.Context, ownerUserID string) (blackIDs []string, err error) { return b.cache.GetBlackIDs(ctx, ownerUserID) } + +func (b *blackDatabase) FindBlackInfos(ctx context.Context, ownerUserID string, userIDs []string) (blacks []*relation.BlackModel, err error) { + return b.black.FindOwnerBlackInfos(ctx, ownerUserID, userIDs) +} diff --git a/pkg/common/db/relation/black_model.go b/pkg/common/db/relation/black_model.go index 9684b6f77..3946c8fc2 100644 --- a/pkg/common/db/relation/black_model.go +++ b/pkg/common/db/relation/black_model.go @@ -17,6 +17,8 @@ package relation import ( "context" + "github.com/OpenIMSDK/tools/errs" + "github.com/OpenIMSDK/tools/ormutil" "gorm.io/gorm" @@ -103,3 +105,7 @@ func (b *BlackGorm) FindBlackUserIDs(ctx context.Context, ownerUserID string) (b "", ) } + +func (b *BlackGorm) FindOwnerBlackInfos(ctx context.Context, ownerUserID string, userIDs []string) (blacks []*relation.BlackModel, err error) { + return blacks, errs.Wrap(b.db(ctx).Where("owner_user_id = ? and block_user_id in ?", ownerUserID, userIDs).Find(&blacks).Error) +} diff --git a/pkg/common/db/table/relation/black.go b/pkg/common/db/table/relation/black.go index ec7ca7a56..59dd12122 100644 --- a/pkg/common/db/table/relation/black.go +++ b/pkg/common/db/table/relation/black.go @@ -43,10 +43,7 @@ type BlackModelInterface interface { Update(ctx context.Context, blacks []*BlackModel) (err error) Find(ctx context.Context, blacks []*BlackModel) (blackList []*BlackModel, err error) Take(ctx context.Context, ownerUserID, blockUserID string) (black *BlackModel, err error) - FindOwnerBlacks( - ctx context.Context, - ownerUserID string, - pageNumber, showNumber int32, - ) (blacks []*BlackModel, total int64, err error) + FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*BlackModel, total int64, err error) + FindOwnerBlackInfos(ctx context.Context, ownerUserID string, userIDs []string) (blacks []*BlackModel, err error) FindBlackUserIDs(ctx context.Context, ownerUserID string) (blackUserIDs []string, err error) }