Merge branch 'errcode' of github.com:OpenIMSDK/Open-IM-Server into errcode

 Conflicts:
	pkg/common/db/controller/group.go
test-errcode
wangchuxiao 2 years ago
commit 4aaac8595a

@ -10,6 +10,7 @@ import (
"errors"
"math/big"
"strconv"
"strings"
"time"
)
@ -45,6 +46,24 @@ func GetPublicUserInfoMap(ctx context.Context, userIDs []string) (map[string]*sd
}), nil
}
func GetUsername(ctx context.Context, userIDs []string) (map[string]string, error) {
if len(userIDs) == 0 {
return map[string]string{}, nil
}
users, err := GetPublicUserInfo(ctx, userIDs)
if err != nil {
return nil, err
}
if ids := utils.Single(userIDs, utils.Slice(users, func(e *sdkws.PublicUserInfo) string {
return e.UserID
})); len(ids) > 0 {
return nil, constant.ErrUserIDNotFound.Wrap(strings.Join(ids, ","))
}
return utils.SliceToMapAny(users, func(e *sdkws.PublicUserInfo) (string, string) {
return e.UserID, e.Nickname
}), nil
}
func GroupNotification(ctx context.Context, groupID string) {
var conversationReq pbConversation.ModifyConversationFieldReq
conversation := pbConversation.Conversation{

@ -159,6 +159,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
group.GroupID = genGroupID(ctx, req.GroupInfo.GroupID)
joinGroup := func(userID string, roleLevel int32) error {
groupMember := PbToDbGroupMember(userMap[userID])
groupMember.Nickname = ""
groupMember.GroupID = group.GroupID
groupMember.RoleLevel = roleLevel
groupMember.OperatorUserID = tracelog.GetOpUserID(ctx)
@ -240,7 +241,7 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo
resp.Groups = utils.Slice(utils.Order(groupIDs, groups, func(group *relationTb.GroupModel) string {
return group.GroupID
}), func(group *relationTb.GroupModel) *open_im_sdk.GroupInfo {
return DbToPbGroupInfo(group, ownerMap[group.GroupID].UserID, uint32(groupMemberNum[group.GroupID]))
return DbToPbGroupInfo(group, ownerMap[group.GroupID].UserID, groupMemberNum[group.GroupID])
})
return resp, nil
}
@ -321,6 +322,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
var groupMembers []*relationTb.GroupMemberModel
for _, userID := range req.InvitedUserIDs {
member := PbToDbGroupMember(userMap[userID])
member.Nickname = ""
member.GroupID = req.GroupID
member.RoleLevel = constant.GroupOrdinaryUsers
member.OperatorUserID = opUserID
@ -352,7 +354,16 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGro
if err != nil {
return nil, err
}
nameMap, err := GetUsername(ctx, utils.Filter(members, func(e *relationTb.GroupMemberModel) (string, bool) {
return e.UserID, e.Nickname == ""
}))
if err != nil {
return nil, err
}
resp.Members = utils.Slice(members, func(e *relationTb.GroupMemberModel) *open_im_sdk.GroupMemberFullInfo {
if e.Nickname == "" {
e.Nickname = nameMap[e.UserID]
}
return DbToPbGroupMembersCMSResp(e)
})
return resp, nil
@ -365,7 +376,16 @@ func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGr
return nil, err
}
resp.Total = total
nameMap, err := GetUsername(ctx, utils.Filter(members, func(e *relationTb.GroupMemberModel) (string, bool) {
return e.UserID, e.Nickname == ""
}))
if err != nil {
return nil, err
}
resp.Members = utils.Slice(members, func(e *relationTb.GroupMemberModel) *open_im_sdk.GroupMemberFullInfo {
if e.Nickname == "" {
e.Nickname = nameMap[e.UserID]
}
return DbToPbGroupMembersCMSResp(e)
})
return resp, nil
@ -450,7 +470,16 @@ func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbGroup.GetG
if err != nil {
return nil, err
}
nameMap, err := GetUsername(ctx, utils.Filter(members, func(e *relationTb.GroupMemberModel) (string, bool) {
return e.UserID, e.Nickname == ""
}))
if err != nil {
return nil, err
}
resp.Members = utils.Slice(members, func(e *relationTb.GroupMemberModel) *open_im_sdk.GroupMemberFullInfo {
if e.Nickname == "" {
e.Nickname = nameMap[e.UserID]
}
return DbToPbGroupMembersCMSResp(e)
})
return resp, nil
@ -801,7 +830,16 @@ func (s *groupServer) GetGroupMembersCMS(ctx context.Context, req *pbGroup.GetGr
return nil, err
}
resp.Total = total
nameMap, err := GetUsername(ctx, utils.Filter(members, func(e *relationTb.GroupMemberModel) (string, bool) {
return e.UserID, e.Nickname == ""
}))
if err != nil {
return nil, err
}
resp.Members = utils.Slice(members, func(e *relationTb.GroupMemberModel) *open_im_sdk.GroupMemberFullInfo {
if e.Nickname == "" {
e.Nickname = nameMap[e.UserID]
}
return DbToPbGroupMembersCMSResp(e)
})
return resp, nil
@ -1011,8 +1049,8 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGr
return nil, err
}
}
err = s.GroupInterface.UpdateGroupMembers(ctx, utils.Slice(req.Members, func(e *pbGroup.SetGroupMemberInfo) *controller.BatchUpdateGroupMember {
return &controller.BatchUpdateGroupMember{
err = s.GroupInterface.UpdateGroupMembers(ctx, utils.Slice(req.Members, func(e *pbGroup.SetGroupMemberInfo) *relationTb.BatchUpdateGroupMember {
return &relationTb.BatchUpdateGroupMember{
GroupID: e.GroupID,
UserID: e.UserID,
Map: UpdateGroupMemberMap(e),
@ -1053,7 +1091,7 @@ func (s *groupServer) GetGroupAbstractInfo(ctx context.Context, req *pbGroup.Get
}
resp.GroupAbstractInfos = utils.Slice(groups, func(group *relationTb.GroupModel) *pbGroup.GroupAbstractInfo {
users := groupUserMap[group.GroupID]
return DbToPbGroupAbstractInfo(group.GroupID, uint32(len(users.UserIDs)), users.Hash)
return DbToPbGroupAbstractInfo(group.GroupID, users.MemberNum, users.Hash)
})
return resp, nil
}
@ -1067,7 +1105,16 @@ func (s *groupServer) GetUserInGroupMembers(ctx context.Context, req *pbGroup.Ge
if err != nil {
return nil, err
}
nameMap, err := GetUsername(ctx, utils.Filter(members, func(e *relationTb.GroupMemberModel) (string, bool) {
return e.UserID, e.Nickname == ""
}))
if err != nil {
return nil, err
}
resp.Members = utils.Slice(members, func(e *relationTb.GroupMemberModel) *open_im_sdk.GroupMemberFullInfo {
if e.Nickname == "" {
e.Nickname = nameMap[e.UserID]
}
return DbToPbGroupMembersCMSResp(e)
})
return resp, nil
@ -1075,10 +1122,10 @@ func (s *groupServer) GetUserInGroupMembers(ctx context.Context, req *pbGroup.Ge
func (s *groupServer) GetGroupMemberUserID(ctx context.Context, req *pbGroup.GetGroupMemberUserIDReq) (*pbGroup.GetGroupMemberUserIDResp, error) {
resp := &pbGroup.GetGroupMemberUserIDResp{}
userIDs, err := s.GroupInterface.FindGroupMemberUserID(ctx, req.GroupID)
var err error
resp.UserIDs, err = s.GroupInterface.FindGroupMemberUserID(ctx, req.GroupID)
if err != nil {
return nil, err
}
resp.UserIDs = userIDs
return resp, nil
}

@ -8,7 +8,7 @@ import (
"Open_IM/pkg/common/tokenverify"
utils2 "Open_IM/pkg/common/utils"
pbGroup "Open_IM/pkg/proto/group"
open_im_sdk "Open_IM/pkg/proto/sdkws"
"Open_IM/pkg/proto/sdkws"
"Open_IM/pkg/utils"
"context"
"github.com/golang/protobuf/jsonpb"
@ -23,7 +23,7 @@ import (
// uint64 OperationTime = 4;
//} creator->group
func setOpUserInfo(opUserID, groupID string, groupMemberInfo *open_im_sdk.GroupMemberFullInfo) error {
func setOpUserInfo(opUserID, groupID string, groupMemberInfo *sdkws.GroupMemberFullInfo) error {
if tokenverify.IsManagerUserID(opUserID) {
u, err := imdb.GetUserByUserID(opUserID)
if err != nil {
@ -51,7 +51,7 @@ func setOpUserInfo(opUserID, groupID string, groupMemberInfo *open_im_sdk.GroupM
return nil
}
func setGroupInfo(groupID string, groupInfo *open_im_sdk.GroupInfo) error {
func setGroupInfo(groupID string, groupInfo *sdkws.GroupInfo) error {
group, err := imdb.GetGroupInfoByGroupID(groupID)
if err != nil {
return utils.Wrap(err, "GetGroupInfoByGroupID failed")
@ -64,7 +64,7 @@ func setGroupInfo(groupID string, groupInfo *open_im_sdk.GroupInfo) error {
return nil
}
func setGroupMemberInfo(groupID, userID string, groupMemberInfo *open_im_sdk.GroupMemberFullInfo) error {
func setGroupMemberInfo(groupID, userID string, groupMemberInfo *sdkws.GroupMemberFullInfo) error {
groupMember, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(groupID, userID)
if err == nil {
return utils.Wrap(utils2.GroupMemberDBCopyOpenIM(groupMemberInfo, groupMember), "")
@ -82,7 +82,7 @@ func setGroupMemberInfo(groupID, userID string, groupMemberInfo *open_im_sdk.Gro
return nil
}
func setGroupOwnerInfo(groupID string, groupMemberInfo *open_im_sdk.GroupMemberFullInfo) error {
func setGroupOwnerInfo(groupID string, groupMemberInfo *sdkws.GroupMemberFullInfo) error {
groupMember, err := imdb.GetGroupOwnerInfoByGroupID(groupID)
if err != nil {
return utils.Wrap(err, "")
@ -93,7 +93,7 @@ func setGroupOwnerInfo(groupID string, groupMemberInfo *open_im_sdk.GroupMemberF
return nil
}
func setPublicUserInfo(userID string, publicUserInfo *open_im_sdk.PublicUserInfo) error {
func setPublicUserInfo(userID string, publicUserInfo *sdkws.PublicUserInfo) error {
user, err := imdb.GetUserByUserID(userID)
if err != nil {
return utils.Wrap(err, "")
@ -211,7 +211,7 @@ func groupNotification(contentType int32, m proto.Message, sendID, groupID, recv
// 创建群后调用
func GroupCreatedNotification(operationID, opUserID, groupID string, initMemberList []string) {
GroupCreatedTips := open_im_sdk.GroupCreatedTips{Group: &open_im_sdk.GroupInfo{},
GroupCreatedTips := sdkws.GroupCreatedTips{Group: &open_im_sdk.GroupInfo{},
OpUser: &open_im_sdk.GroupMemberFullInfo{}, GroupOwnerUser: &open_im_sdk.GroupMemberFullInfo{}}
if err := setOpUserInfo(opUserID, groupID, GroupCreatedTips.OpUser); err != nil {
log.NewError(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID, GroupCreatedTips.OpUser)
@ -248,7 +248,7 @@ func GroupCreatedNotification(operationID, opUserID, groupID string, initMemberL
// introduction := ""
// faceURL := ""
func GroupInfoSetNotification(operationID, opUserID, groupID string, groupName, notification, introduction, faceURL string, needVerification *wrapperspb.Int32Value) {
GroupInfoChangedTips := open_im_sdk.GroupInfoSetTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}}
GroupInfoChangedTips := sdkws.GroupInfoSetTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}}
if err := setGroupInfo(groupID, GroupInfoChangedTips.Group); err != nil {
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
return
@ -269,8 +269,8 @@ func GroupInfoSetNotification(operationID, opUserID, groupID string, groupName,
}
func GroupMutedNotification(operationID, opUserID, groupID string) {
tips := open_im_sdk.GroupMutedTips{Group: &open_im_sdk.GroupInfo{},
OpUser: &open_im_sdk.GroupMemberFullInfo{}}
tips := sdkws.GroupMutedTips{Group: &sdkws.GroupInfo{},
OpUser: &sdkws.GroupMemberFullInfo{}}
if err := setGroupInfo(groupID, tips.Group); err != nil {
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
return
@ -283,8 +283,8 @@ func GroupMutedNotification(operationID, opUserID, groupID string) {
}
func GroupCancelMutedNotification(operationID, opUserID, groupID string) {
tips := open_im_sdk.GroupCancelMutedTips{Group: &open_im_sdk.GroupInfo{},
OpUser: &open_im_sdk.GroupMemberFullInfo{}}
tips := sdkws.GroupCancelMutedTips{Group: &sdkws.GroupInfo{},
OpUser: &sdkws.GroupMemberFullInfo{}}
if err := setGroupInfo(groupID, tips.Group); err != nil {
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
return
@ -297,8 +297,8 @@ func GroupCancelMutedNotification(operationID, opUserID, groupID string) {
}
func GroupMemberMutedNotification(operationID, opUserID, groupID, groupMemberUserID string, mutedSeconds uint32) {
tips := open_im_sdk.GroupMemberMutedTips{Group: &open_im_sdk.GroupInfo{},
OpUser: &open_im_sdk.GroupMemberFullInfo{}, MutedUser: &open_im_sdk.GroupMemberFullInfo{}}
tips := sdkws.GroupMemberMutedTips{Group: &sdkws.GroupInfo{},
OpUser: &sdkws.GroupMemberFullInfo{}, MutedUser: &sdkws.GroupMemberFullInfo{}}
tips.MutedSeconds = mutedSeconds
if err := setGroupInfo(groupID, tips.Group); err != nil {
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
@ -316,8 +316,8 @@ func GroupMemberMutedNotification(operationID, opUserID, groupID, groupMemberUse
}
func GroupMemberInfoSetNotification(operationID, opUserID, groupID, groupMemberUserID string) {
tips := open_im_sdk.GroupMemberInfoSetTips{Group: &open_im_sdk.GroupInfo{},
OpUser: &open_im_sdk.GroupMemberFullInfo{}, ChangedUser: &open_im_sdk.GroupMemberFullInfo{}}
tips := sdkws.GroupMemberInfoSetTips{Group: &sdkws.GroupInfo{},
OpUser: &sdkws.GroupMemberFullInfo{}, ChangedUser: &sdkws.GroupMemberFullInfo{}}
if err := setGroupInfo(groupID, tips.Group); err != nil {
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
return
@ -338,8 +338,8 @@ func GroupMemberRoleLevelChangeNotification(operationID, opUserID, groupID, grou
log.NewError(operationID, utils.GetSelfFuncName(), "invalid notificationType: ", notificationType)
return
}
tips := open_im_sdk.GroupMemberInfoSetTips{Group: &open_im_sdk.GroupInfo{},
OpUser: &open_im_sdk.GroupMemberFullInfo{}, ChangedUser: &open_im_sdk.GroupMemberFullInfo{}}
tips := sdkws.GroupMemberInfoSetTips{Group: &sdkws.GroupInfo{},
OpUser: &sdkws.GroupMemberFullInfo{}, ChangedUser: &sdkws.GroupMemberFullInfo{}}
if err := setGroupInfo(groupID, tips.Group); err != nil {
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
return
@ -356,8 +356,8 @@ func GroupMemberRoleLevelChangeNotification(operationID, opUserID, groupID, grou
}
func GroupMemberCancelMutedNotification(operationID, opUserID, groupID, groupMemberUserID string) {
tips := open_im_sdk.GroupMemberCancelMutedTips{Group: &open_im_sdk.GroupInfo{},
OpUser: &open_im_sdk.GroupMemberFullInfo{}, MutedUser: &open_im_sdk.GroupMemberFullInfo{}}
tips := sdkws.GroupMemberCancelMutedTips{Group: &sdkws.GroupInfo{},
OpUser: &sdkws.GroupMemberFullInfo{}, MutedUser: &sdkws.GroupMemberFullInfo{}}
if err := setGroupInfo(groupID, tips.Group); err != nil {
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
return
@ -385,7 +385,7 @@ func GroupMemberCancelMutedNotification(operationID, opUserID, groupID, groupMem
//
// 申请进群后调用
func JoinGroupApplicationNotification(ctx context.Context, req *pbGroup.JoinGroupReq) {
JoinGroupApplicationTips := open_im_sdk.JoinGroupApplicationTips{Group: &open_im_sdk.GroupInfo{}, Applicant: &open_im_sdk.PublicUserInfo{}}
JoinGroupApplicationTips := sdkws.JoinGroupApplicationTips{Group: &sdkws.GroupInfo{}, Applicant: &sdkws.PublicUserInfo{}}
err := setGroupInfo(req.GroupID, JoinGroupApplicationTips.Group)
if err != nil {
log.Error(utils.OperationID(ctx), "setGroupInfo failed ", err.Error(), req.GroupID)
@ -409,7 +409,7 @@ func JoinGroupApplicationNotification(ctx context.Context, req *pbGroup.JoinGrou
}
func MemberQuitNotification(req *pbGroup.QuitGroupReq) {
MemberQuitTips := open_im_sdk.MemberQuitTips{Group: &open_im_sdk.GroupInfo{}, QuitUser: &open_im_sdk.GroupMemberFullInfo{}}
MemberQuitTips := sdkws.MemberQuitTips{Group: &sdkws.GroupInfo{}, QuitUser: &sdkws.GroupMemberFullInfo{}}
if err := setGroupInfo(req.GroupID, MemberQuitTips.Group); err != nil {
log.Error(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID)
return
@ -431,7 +431,7 @@ func MemberQuitNotification(req *pbGroup.QuitGroupReq) {
//
// 处理进群请求后调用
func GroupApplicationAcceptedNotification(req *pbGroup.GroupApplicationResponseReq) {
GroupApplicationAcceptedTips := open_im_sdk.GroupApplicationAcceptedTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}, HandleMsg: req.HandledMsg}
GroupApplicationAcceptedTips := sdkws.GroupApplicationAcceptedTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}, HandleMsg: req.HandledMsg}
if err := setGroupInfo(req.GroupID, GroupApplicationAcceptedTips.Group); err != nil {
log.NewError(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID, GroupApplicationAcceptedTips.Group)
return
@ -457,7 +457,7 @@ func GroupApplicationAcceptedNotification(req *pbGroup.GroupApplicationResponseR
}
func GroupApplicationRejectedNotification(req *pbGroup.GroupApplicationResponseReq) {
GroupApplicationRejectedTips := open_im_sdk.GroupApplicationRejectedTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}, HandleMsg: req.HandledMsg}
GroupApplicationRejectedTips := sdkws.GroupApplicationRejectedTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}, HandleMsg: req.HandledMsg}
if err := setGroupInfo(req.GroupID, GroupApplicationRejectedTips.Group); err != nil {
log.NewError(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID, GroupApplicationRejectedTips.Group)
return
@ -482,7 +482,7 @@ func GroupApplicationRejectedNotification(req *pbGroup.GroupApplicationResponseR
}
func GroupOwnerTransferredNotification(req *pbGroup.TransferGroupOwnerReq) {
GroupOwnerTransferredTips := open_im_sdk.GroupOwnerTransferredTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}, NewGroupOwner: &open_im_sdk.GroupMemberFullInfo{}}
GroupOwnerTransferredTips := sdkws.GroupOwnerTransferredTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}, NewGroupOwner: &sdkws.GroupMemberFullInfo{}}
if err := setGroupInfo(req.GroupID, GroupOwnerTransferredTips.Group); err != nil {
log.NewError(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID)
return
@ -499,7 +499,7 @@ func GroupOwnerTransferredNotification(req *pbGroup.TransferGroupOwnerReq) {
}
func GroupDismissedNotification(req *pbGroup.DismissGroupReq) {
tips := open_im_sdk.GroupDismissedTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}}
tips := sdkws.GroupDismissedTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}}
if err := setGroupInfo(req.GroupID, tips.Group); err != nil {
log.NewError(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID)
return
@ -520,7 +520,7 @@ func GroupDismissedNotification(req *pbGroup.DismissGroupReq) {
//
// 被踢后调用
func MemberKickedNotification(req *pbGroup.KickGroupMemberReq, kickedUserIDList []string) {
MemberKickedTips := open_im_sdk.MemberKickedTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}}
MemberKickedTips := sdkws.MemberKickedTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}}
if err := setGroupInfo(req.GroupID, MemberKickedTips.Group); err != nil {
log.Error(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID)
return
@ -530,7 +530,7 @@ func MemberKickedNotification(req *pbGroup.KickGroupMemberReq, kickedUserIDList
return
}
for _, v := range kickedUserIDList {
var groupMemberInfo open_im_sdk.GroupMemberFullInfo
var groupMemberInfo sdkws.GroupMemberFullInfo
if err := setGroupMemberInfo(req.GroupID, v, &groupMemberInfo); err != nil {
log.Error(req.OperationID, "setGroupMemberInfo failed ", err.Error(), req.GroupID, v)
continue
@ -553,7 +553,7 @@ func MemberKickedNotification(req *pbGroup.KickGroupMemberReq, kickedUserIDList
//
// 被邀请进群后调用
func MemberInvitedNotification(operationID, groupID, opUserID, reason string, invitedUserIDList []string) {
MemberInvitedTips := open_im_sdk.MemberInvitedTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}}
MemberInvitedTips := sdkws.MemberInvitedTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}}
if err := setGroupInfo(groupID, MemberInvitedTips.Group); err != nil {
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
return
@ -563,7 +563,7 @@ func MemberInvitedNotification(operationID, groupID, opUserID, reason string, in
return
}
for _, v := range invitedUserIDList {
var groupMemberInfo open_im_sdk.GroupMemberFullInfo
var groupMemberInfo sdkws.GroupMemberFullInfo
if err := setGroupMemberInfo(groupID, v, &groupMemberInfo); err != nil {
log.Error(operationID, "setGroupMemberInfo failed ", err.Error(), groupID)
continue
@ -594,8 +594,8 @@ func MemberInvitedNotification(operationID, groupID, opUserID, reason string, in
// }
//
// 群成员主动申请进群,管理员同意后调用,
func MemberEnterNotification(req *pbGroup.GroupApplicationResponseReq) {
MemberEnterTips := open_im_sdk.MemberEnterTips{Group: &open_im_sdk.GroupInfo{}, EntrantUser: &open_im_sdk.GroupMemberFullInfo{}}
func MemberEnterNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) {
MemberEnterTips := sdkws.MemberEnterTips{Group: &sdkws.GroupInfo{}, EntrantUser: &sdkws.GroupMemberFullInfo{}}
if err := setGroupInfo(req.GroupID, MemberEnterTips.Group); err != nil {
log.Error(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID, MemberEnterTips.Group)
return
@ -608,7 +608,7 @@ func MemberEnterNotification(req *pbGroup.GroupApplicationResponseReq) {
}
func MemberEnterDirectlyNotification(groupID string, entrantUserID string, operationID string) {
MemberEnterTips := open_im_sdk.MemberEnterTips{Group: &open_im_sdk.GroupInfo{}, EntrantUser: &open_im_sdk.GroupMemberFullInfo{}}
MemberEnterTips := sdkws.MemberEnterTips{Group: &sdkws.GroupInfo{}, EntrantUser: &sdkws.GroupMemberFullInfo{}}
if err := setGroupInfo(groupID, MemberEnterTips.Group); err != nil {
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID, MemberEnterTips.Group)
return

@ -8,15 +8,18 @@ import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db/controller"
"Open_IM/pkg/common/db/relation"
relationTb "Open_IM/pkg/common/db/table/relation"
tablerelation "Open_IM/pkg/common/db/table/relation"
"Open_IM/pkg/common/log"
promePkg "Open_IM/pkg/common/prometheus"
prome "Open_IM/pkg/common/prometheus"
"Open_IM/pkg/common/tokenverify"
"Open_IM/pkg/common/tracelog"
sdkws "Open_IM/pkg/proto/sdkws"
pbUser "Open_IM/pkg/proto/user"
"Open_IM/pkg/proto/group"
pbgroup "Open_IM/pkg/proto/group"
"Open_IM/pkg/proto/sdkws"
pbuser "Open_IM/pkg/proto/user"
"Open_IM/pkg/utils"
"context"
"github.com/golang/protobuf/ptypes/wrappers"
grpcPrometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"google.golang.org/grpc"
@ -61,9 +64,9 @@ func (s *userServer) Run() {
//grpc server
var grpcOpts []grpc.ServerOption
if config.Config.Prometheus.Enable {
promePkg.NewGrpcRequestCounter()
promePkg.NewGrpcRequestFailedCounter()
promePkg.NewGrpcRequestSuccessCounter()
prome.NewGrpcRequestCounter()
prome.NewGrpcRequestFailedCounter()
prome.NewGrpcRequestSuccessCounter()
grpcOpts = append(grpcOpts, []grpc.ServerOption{
// grpc.UnaryInterceptor(promePkg.UnaryServerInterceptorProme),
grpc.StreamInterceptor(grpcPrometheus.StreamServerInterceptor),
@ -73,7 +76,7 @@ func (s *userServer) Run() {
srv := grpc.NewServer(grpcOpts...)
defer srv.GracefulStop()
//Service registers with etcd
pbUser.RegisterUserServer(srv, s)
pbuser.RegisterUserServer(srv, s)
err = srv.Serve(listener)
if err != nil {
@ -88,12 +91,15 @@ func (s *userServer) SyncJoinedGroupMemberFaceURL(ctx context.Context, userID st
if err != nil {
return
}
for _, group := range members {
err := s.SetGroupMemberFaceURL(ctx, faceURL, group.GroupID, userID)
if err != nil {
return
}
chat.GroupMemberInfoSetNotification(operationID, opUserID, group.GroupID, userID)
groupIDs := make([]string, 0)
for _, v := range members {
groupIDs = append(groupIDs, v.GroupID)
}
if s.SetGroupMemberInfo(ctx, "", faceURL, "", 0, groupIDs, userID) != nil {
return
}
for _, v := range groupIDs {
chat.GroupMemberInfoSetNotification(operationID, opUserID, v, userID)
}
}
@ -103,24 +109,57 @@ func (s *userServer) SyncJoinedGroupMemberNickname(ctx context.Context, userID s
if err != nil {
return
}
groupIDs := make([]string, 0)
for _, v := range members {
if v.Nickname == oldNickname {
err := s.SetGroupMemberNickname(ctx, newNickname, v.GroupID, v.UserID)
if err != nil {
return
}
chat.GroupMemberInfoSetNotification(operationID, opUserID, v.GroupID, userID)
groupIDs = append(groupIDs, v.GroupID)
}
}
s.SetGroupMemberInfo(ctx, newNickname, "", "", 0, groupIDs, userID)
for _, v := range groupIDs {
chat.GroupMemberInfoSetNotification(operationID, opUserID, v, userID)
}
}
// 设置群昵称
func (s *userServer) SetGroupMemberNickname(ctx context.Context, nickname string, groupID string, userID string) (err error) {
return
}
//func (s *userServer) SetGroupMemberNickname(ctx context.Context, nickname string, groupID string, userID string) (err error) {
// conn, err := s.RegisterCenter.GetConn(config.Config.RpcRegisterName.OpenImGroupName)
// if err != nil {
// return err
// }
// client := group.NewGroupClient(conn)
// req := &pbgroup.SetGroupMemberNicknameReq{GroupID: groupID, Nickname: nickname, UserID: userID}
// _, err = client.SetGroupMemberNickname(ctx, req)
// return
//}
// 设置群头像
func (s *userServer) SetGroupMemberFaceURL(ctx context.Context, faceURL string, groupID string, userID string) (err error) {
func (s *userServer) SetGroupMemberInfo(ctx context.Context, nickname, faceURL, ex string, roleLevel int32, groupIDs []string, userID string) (err error) {
conn, err := s.RegisterCenter.GetConn(config.Config.RpcRegisterName.OpenImGroupName)
if err != nil {
return err
}
req := pbgroup.SetGroupMemberInfo{UserID: userID}
if nickname != "" {
req.Nickname = &wrappers.StringValue{Value: nickname}
}
if faceURL != "" {
req.FaceURL = &wrappers.StringValue{Value: faceURL}
}
if ex != "" {
req.Ex = &wrappers.StringValue{Value: ex}
}
if roleLevel != 0 {
req.RoleLevel = &wrappers.Int32Value{Value: roleLevel}
}
setGroupMemberInfoReq := &pbgroup.SetGroupMemberInfoReq{}
for _, v := range groupIDs {
req.GroupID = v
setGroupMemberInfoReq.Members = append(setGroupMemberInfoReq.Members, &req)
}
client := group.NewGroupClient(conn)
_, err = client.SetGroupMemberInfo(ctx, setGroupMemberInfoReq)
return
}
@ -130,8 +169,8 @@ func (s *userServer) GetJoinedGroupMembers(ctx context.Context, userID string) (
}
// ok
func (s *userServer) GetDesignateUsers(ctx context.Context, req *pbUser.GetDesignateUsersReq) (resp *pbUser.GetDesignateUsersResp, err error) {
resp = &pbUser.GetDesignateUsersResp{}
func (s *userServer) GetDesignateUsers(ctx context.Context, req *pbuser.GetDesignateUsersReq) (resp *pbuser.GetDesignateUsersResp, err error) {
resp = &pbuser.GetDesignateUsersResp{}
users, err := s.FindWithError(ctx, req.UserIDs)
if err != nil {
return nil, err
@ -148,8 +187,8 @@ func (s *userServer) GetAllPageFriends(ctx context.Context, ownerUserID string)
}
// ok
func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserInfoReq) (resp *pbUser.UpdateUserInfoResp, err error) {
resp = &pbUser.UpdateUserInfoResp{}
func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbuser.UpdateUserInfoReq) (resp *pbuser.UpdateUserInfoResp, err error) {
resp = &pbuser.UpdateUserInfoResp{}
err = tokenverify.CheckAccessV3(ctx, req.UserInfo.UserID)
if err != nil {
return nil, err
@ -166,7 +205,7 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
if err != nil {
return nil, err
}
err = s.Update(ctx, []*relationTb.UserModel{user})
err = s.Update(ctx, []*tablerelation.UserModel{user})
if err != nil {
return nil, err
}
@ -191,8 +230,8 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
}
// ok
func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbUser.SetGlobalRecvMessageOptReq) (resp *pbUser.SetGlobalRecvMessageOptResp, err error) {
resp = &pbUser.SetGlobalRecvMessageOptResp{}
func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbuser.SetGlobalRecvMessageOptReq) (resp *pbuser.SetGlobalRecvMessageOptResp, err error) {
resp = &pbuser.SetGlobalRecvMessageOptResp{}
if _, err := s.FindWithError(ctx, []string{req.UserID}); err != nil {
return nil, err
}
@ -206,8 +245,8 @@ func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbUser.Se
}
// ok
func (s *userServer) AccountCheck(ctx context.Context, req *pbUser.AccountCheckReq) (resp *pbUser.AccountCheckResp, err error) {
resp = &pbUser.AccountCheckResp{}
func (s *userServer) AccountCheck(ctx context.Context, req *pbuser.AccountCheckReq) (resp *pbuser.AccountCheckResp, err error) {
resp = &pbuser.AccountCheckResp{}
if utils.Duplicate(req.CheckUserIDs) {
return nil, constant.ErrArgs.Wrap("userID repeated")
}
@ -224,7 +263,7 @@ func (s *userServer) AccountCheck(ctx context.Context, req *pbUser.AccountCheckR
userIDs[v.UserID] = nil
}
for _, v := range req.CheckUserIDs {
temp := &pbUser.AccountCheckRespSingleUserStatus{UserID: v}
temp := &pbuser.AccountCheckRespSingleUserStatus{UserID: v}
if _, ok := userIDs[v]; ok {
temp.AccountStatus = constant.Registered
} else {
@ -236,8 +275,8 @@ func (s *userServer) AccountCheck(ctx context.Context, req *pbUser.AccountCheckR
}
// ok
func (s *userServer) GetPaginationUsers(ctx context.Context, req *pbUser.GetPaginationUsersReq) (resp *pbUser.GetPaginationUsersResp, err error) {
resp = &pbUser.GetPaginationUsersResp{}
func (s *userServer) GetPaginationUsers(ctx context.Context, req *pbuser.GetPaginationUsersReq) (resp *pbuser.GetPaginationUsersResp, err error) {
resp = &pbuser.GetPaginationUsersResp{}
usersDB, total, err := s.Page(ctx, req.Pagination.PageNumber, req.Pagination.ShowNumber)
if err != nil {
return nil, err
@ -248,8 +287,8 @@ func (s *userServer) GetPaginationUsers(ctx context.Context, req *pbUser.GetPagi
}
// ok
func (s *userServer) UserRegister(ctx context.Context, req *pbUser.UserRegisterReq) (resp *pbUser.UserRegisterResp, err error) {
resp = &pbUser.UserRegisterResp{}
func (s *userServer) UserRegister(ctx context.Context, req *pbuser.UserRegisterReq) (resp *pbuser.UserRegisterResp, err error) {
resp = &pbuser.UserRegisterResp{}
if utils.DuplicateAny(req.Users, func(e *sdkws.UserInfo) string { return e.UserID }) {
return nil, constant.ErrArgs.Wrap("userID repeated")
}

@ -1,7 +1,6 @@
package cache
import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db/relation"
relationTb "Open_IM/pkg/common/db/table/relation"
"Open_IM/pkg/common/db/unrelation"
@ -12,8 +11,8 @@ import (
"github.com/dtm-labs/rockscache"
"github.com/go-redis/redis/v8"
"math/big"
"sort"
"strconv"
"strings"
"time"
)
@ -117,22 +116,6 @@ func (g *GroupCacheRedis) GetGroupInfo(ctx context.Context, groupID string) (gro
})
}
func (g *GroupCacheRedis) DelGroupInfo(ctx context.Context, groupID string) (err error) {
defer func() {
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID)
}()
return g.rcClient.TagAsDeleted(g.getGroupInfoKey(groupID))
}
func (g *GroupCacheRedis) DelGroupsInfo(ctx context.Context, groupIDs []string) error {
for _, groupID := range groupIDs {
if err := g.DelGroupInfo(ctx, groupID); err != nil {
return err
}
}
return nil
}
// userJoinSuperGroup
func (g *GroupCacheRedis) BatchDelJoinedSuperGroupIDs(ctx context.Context, userIDs []string) (err error) {
for _, userID := range userIDs {
@ -160,43 +143,18 @@ func (g *GroupCacheRedis) GetJoinedSuperGroupIDs(ctx context.Context, userID str
})
}
//// groupMembersHash
//func (g *GroupCacheRedis) GetGroupsMembersHash(ctx context.Context, groupIDs []string) (map[string]uint64, error) {
// return GetCache(ctx, g.rcClient, g.getGroupMembersHashKey(groupID), g.expireTime, "")
//}
// groupMembersHash
func (g *GroupCacheRedis) GetGroupMembersHash(ctx context.Context, groupID string) (hashCodeUint64 uint64, err error) {
generateHash := func() (string, error) {
groupInfo, err := g.GetGroupInfo(ctx, groupID)
if err != nil {
return "", err
}
if groupInfo.Status == constant.GroupStatusDismissed {
return "0", nil
}
groupMemberIDList, err := g.GetGroupMemberIDs(ctx, groupID)
return GetCache(ctx, g.rcClient, g.getGroupMembersHashKey(groupID), g.expireTime, func(ctx context.Context) (uint64, error) {
userIDs, err := g.GetGroupMemberIDs(ctx, groupID)
if err != nil {
return "", err
}
sort.Strings(groupMemberIDList)
var all string
for _, v := range groupMemberIDList {
all += v
return 0, err
}
utils.Sort(userIDs, true)
bi := big.NewInt(0)
bi.SetString(utils.Md5(all)[0:8], 16)
return strconv.Itoa(int(bi.Uint64())), nil
}
defer func() {
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "hashCodeUint64", hashCodeUint64)
}()
hashCodeStr, err := g.rcClient.Fetch(g.getGroupMembersHashKey(groupID), time.Second*30*60, generateHash)
if err != nil {
return 0, utils.Wrap(err, "fetch failed")
}
hashCode, err := strconv.Atoi(hashCodeStr)
return uint64(hashCode), err
bi.SetString(utils.Md5(strings.Join(userIDs, ";"))[0:8], 16)
return bi.Uint64(), nil
})
}
func (g *GroupCacheRedis) DelGroupMembersHash(ctx context.Context, groupID string) (err error) {
@ -207,41 +165,10 @@ func (g *GroupCacheRedis) DelGroupMembersHash(ctx context.Context, groupID strin
}
// groupMemberIDs
// from redis
func (g *GroupCacheRedis) GetGroupMemberIDs(ctx context.Context, groupID string) (groupMemberIDs []string, err error) {
f := func() (string, error) {
groupInfo, err := g.GetGroupInfo(ctx, groupID)
if err != nil {
return "", err
}
var groupMemberIDList []string
if groupInfo.GroupType == constant.SuperGroup {
superGroup, err := g.mongoDB.GetSuperGroup(ctx, groupID)
if err != nil {
return "", err
}
groupMemberIDList = superGroup.MemberIDList
} else {
groupMemberIDList, err = relation.GetGroupMemberIDListByGroupID(groupID)
if err != nil {
return "", err
}
}
bytes, err := json.Marshal(groupMemberIDList)
if err != nil {
return "", utils.Wrap(err, "")
}
return string(bytes), nil
}
defer func() {
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "groupMemberIDList", groupMemberIDs)
}()
groupIDListStr, err := g.rcClient.Fetch(g.getGroupMemberIDsKey(groupID), time.Second*30*60, f)
if err != nil {
return nil, err
}
err = json.Unmarshal([]byte(groupIDListStr), &groupMemberIDs)
return groupMemberIDs, nil
return GetCache(ctx, g.rcClient, g.getGroupMemberIDsKey(groupID), g.expireTime, func(ctx context.Context) ([]string, error) {
return g.groupMember.FindMemberUserID(ctx, groupID)
})
}
func (g *GroupCacheRedis) DelGroupMemberIDs(ctx context.Context, groupID string) (err error) {
@ -389,3 +316,19 @@ func (g *GroupCacheRedis) DelGroupMemberNum(ctx context.Context, groupID string)
}()
return g.rcClient.TagAsDeleted(g.getGroupMemberNumKey(groupID))
}
func (g *GroupCacheRedis) DelGroupInfo(ctx context.Context, groupID string) (err error) {
defer func() {
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID)
}()
return g.rcClient.TagAsDeleted(g.getGroupInfoKey(groupID))
}
func (g *GroupCacheRedis) DelGroupsInfo(ctx context.Context, groupIDs []string) error {
for _, groupID := range groupIDs {
if err := g.DelGroupInfo(ctx, groupID); err != nil {
return err
}
}
return nil
}

@ -21,17 +21,6 @@ import (
//type GroupInterface GroupDataBaseInterface
type BatchUpdateGroupMember struct {
GroupID string
UserID string
Map map[string]any
}
type GroupSimpleUserID struct {
Hash uint64
UserIDs []string
}
type GroupInterface interface {
CreateGroup(ctx context.Context, groups []*relationTb.GroupModel, groupMembers []*relationTb.GroupMemberModel) error
TakeGroup(ctx context.Context, groupID string) (group *relationTb.GroupModel, err error)
@ -48,11 +37,11 @@ type GroupInterface interface {
SearchGroupMember(ctx context.Context, keyword string, groupIDs []string, userIDs []string, roleLevels []int32, pageNumber, showNumber int32) (uint32, []*relationTb.GroupMemberModel, error)
HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relationTb.GroupMemberModel) error
DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error
MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string]*GroupSimpleUserID, error)
MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string]*relationTb.GroupSimpleUserID, error)
MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error)
TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string, roleLevel int32) error // 转让群
UpdateGroupMember(ctx context.Context, groupID string, userID string, data map[string]any) error
UpdateGroupMembers(ctx context.Context, data []*BatchUpdateGroupMember) error
UpdateGroupMembers(ctx context.Context, data []*relationTb.BatchUpdateGroupMember) error
// GroupRequest
CreateGroupRequest(ctx context.Context, requests []*relationTb.GroupRequestModel) error
TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relationTb.GroupRequestModel, error)
@ -132,7 +121,7 @@ func (g *GroupController) DeleteGroupMember(ctx context.Context, groupID string,
return g.database.DeleteGroupMember(ctx, groupID, userIDs)
}
func (g *GroupController) MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string]*GroupSimpleUserID, error) {
func (g *GroupController) MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string]*relationTb.GroupSimpleUserID, error) {
return g.database.MapGroupMemberUserID(ctx, groupIDs)
}
@ -144,7 +133,7 @@ func (g *GroupController) TransferGroupOwner(ctx context.Context, groupID string
return g.database.TransferGroupOwner(ctx, groupID, oldOwnerUserID, newOwnerUserID, roleLevel)
}
func (g *GroupController) UpdateGroupMembers(ctx context.Context, data []*BatchUpdateGroupMember) error {
func (g *GroupController) UpdateGroupMembers(ctx context.Context, data []*relationTb.BatchUpdateGroupMember) error {
return g.database.UpdateGroupMembers(ctx, data)
}
@ -204,11 +193,11 @@ type GroupDataBaseInterface interface {
SearchGroupMember(ctx context.Context, keyword string, groupIDs []string, userIDs []string, roleLevels []int32, pageNumber, showNumber int32) (uint32, []*relationTb.GroupMemberModel, error)
HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relationTb.GroupMemberModel) error
DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error
MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string]*GroupSimpleUserID, error)
MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string]*relationTb.GroupSimpleUserID, error)
MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error)
TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string, roleLevel int32) error // 转让群
UpdateGroupMember(ctx context.Context, groupID string, userID string, data map[string]any) error
UpdateGroupMembers(ctx context.Context, data []*BatchUpdateGroupMember) error
UpdateGroupMembers(ctx context.Context, data []*relationTb.BatchUpdateGroupMember) error
// GroupRequest
CreateGroupRequest(ctx context.Context, requests []*relationTb.GroupRequestModel) error
TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relationTb.GroupRequestModel, error)
@ -393,20 +382,20 @@ func (g *GroupDataBase) DeleteGroupMember(ctx context.Context, groupID string, u
})
}
func (g *GroupDataBase) MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string]*GroupSimpleUserID, error) {
func (g *GroupDataBase) MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string]*relationTb.GroupSimpleUserID, error) {
mapGroupUserIDs, err := g.groupMemberDB.FindJoinUserID(ctx, groupIDs)
if err != nil {
return nil, err
} // 批量cache
res := make(map[string]*GroupSimpleUserID)
}
res := make(map[string]*relationTb.GroupSimpleUserID)
for _, groupID := range groupIDs {
users := &GroupSimpleUserID{
UserIDs: mapGroupUserIDs[groupID],
}
if len(users.UserIDs) > 0 {
utils.Sort(users.UserIDs, true)
userIDs := mapGroupUserIDs[groupID]
users := &relationTb.GroupSimpleUserID{}
if len(userIDs) > 0 {
utils.Sort(userIDs, true)
bi := big.NewInt(0)
bi.SetString(utils.Md5(strings.Join(users.UserIDs, ";"))[0:8], 16)
bi.SetString(utils.Md5(strings.Join(userIDs, ";"))[0:8], 16)
users.Hash = bi.Uint64()
}
res[groupID] = users
}
@ -452,7 +441,7 @@ func (g *GroupDataBase) UpdateGroupMember(ctx context.Context, groupID string, u
})
}
func (g *GroupDataBase) UpdateGroupMembers(ctx context.Context, data []*BatchUpdateGroupMember) error {
func (g *GroupDataBase) UpdateGroupMembers(ctx context.Context, data []*relationTb.BatchUpdateGroupMember) error {
return g.db.Transaction(func(tx *gorm.DB) error {
for _, item := range data {
if err := g.groupMemberDB.Update(ctx, item.GroupID, item.UserID, item.Map, tx); err != nil {
@ -487,25 +476,25 @@ func (g *GroupDataBase) FindJoinSuperGroup(ctx context.Context, userID string) (
}
func (g *GroupDataBase) CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error {
return g.mongoDB.Transaction(ctx, func(s unrelationTb.SuperGroupModelInterface, tx any) error {
return s.CreateSuperGroup(ctx, groupID, initMemberIDList, tx)
return unrelation.MongoTransaction(ctx, g.mongoDB.MgoClient, func(tx mongo.SessionContext) error {
return g.mongoDB.CreateSuperGroup(ctx, groupID, initMemberIDList, tx)
})
}
func (g *GroupDataBase) DeleteSuperGroup(ctx context.Context, groupID string) error {
return g.mongoDB.Transaction(ctx, func(s unrelationTb.SuperGroupModelInterface, tx any) error {
return s.DeleteSuperGroup(ctx, groupID, tx)
return unrelation.MongoTransaction(ctx, g.mongoDB.MgoClient, func(tx mongo.SessionContext) error {
return g.mongoDB.DeleteSuperGroup(ctx, groupID, tx)
})
}
func (g *GroupDataBase) DeleteSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error {
return g.mongoDB.Transaction(ctx, func(s unrelationTb.SuperGroupModelInterface, tx any) error {
return s.RemoverUserFromSuperGroup(ctx, groupID, userIDs, tx)
return unrelation.MongoTransaction(ctx, g.mongoDB.MgoClient, func(tx mongo.SessionContext) error {
return g.mongoDB.RemoverUserFromSuperGroup(ctx, groupID, userIDs, tx)
})
}
func (g *GroupDataBase) CreateSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error {
return g.mongoDB.Transaction(ctx, func(s unrelationTb.SuperGroupModelInterface, tx any) error {
return s.AddUserToSuperGroup(ctx, groupID, userIDs, tx)
return unrelation.MongoTransaction(ctx, g.mongoDB.MgoClient, func(tx mongo.SessionContext) error {
return g.mongoDB.AddUserToSuperGroup(ctx, groupID, userIDs, tx)
})
}

@ -0,0 +1,12 @@
package relation
type BatchUpdateGroupMember struct {
GroupID string
UserID string
Map map[string]any
}
type GroupSimpleUserID struct {
Hash uint64
MemberNum uint32
}

@ -144,11 +144,12 @@ func SliceSetAny[E any, K comparable](es []E, fn func(e E) K) map[K]struct{} {
})
}
func Filter[E any](es []E, fn func(e E) bool) []E {
rs := make([]E, 0, len(es))
func Filter[E, T any](es []E, fn func(e E) (T, bool)) []T {
rs := make([]T, 0, len(es))
for i := 0; i < len(es); i++ {
if e := es[i]; fn(e) {
rs = append(rs, e)
e := es[i]
if t, ok := fn(e); ok {
rs = append(rs, t)
}
}
return rs

Loading…
Cancel
Save