mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-25 11:06:43 +08:00
group nickname
This commit is contained in:
parent
5d7809624c
commit
1e1c6de56e
@ -10,6 +10,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -45,6 +46,24 @@ func GetPublicUserInfoMap(ctx context.Context, userIDs []string) (map[string]*sd
|
|||||||
}), nil
|
}), 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) {
|
func GroupNotification(ctx context.Context, groupID string) {
|
||||||
var conversationReq pbConversation.ModifyConversationFieldReq
|
var conversationReq pbConversation.ModifyConversationFieldReq
|
||||||
conversation := pbConversation.Conversation{
|
conversation := pbConversation.Conversation{
|
||||||
|
@ -159,6 +159,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
|||||||
group.GroupID = genGroupID(ctx, req.GroupInfo.GroupID)
|
group.GroupID = genGroupID(ctx, req.GroupInfo.GroupID)
|
||||||
joinGroup := func(userID string, roleLevel int32) error {
|
joinGroup := func(userID string, roleLevel int32) error {
|
||||||
groupMember := PbToDbGroupMember(userMap[userID])
|
groupMember := PbToDbGroupMember(userMap[userID])
|
||||||
|
groupMember.Nickname = ""
|
||||||
groupMember.GroupID = group.GroupID
|
groupMember.GroupID = group.GroupID
|
||||||
groupMember.RoleLevel = roleLevel
|
groupMember.RoleLevel = roleLevel
|
||||||
groupMember.OperatorUserID = tracelog.GetOpUserID(ctx)
|
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 {
|
resp.Groups = utils.Slice(utils.Order(groupIDs, groups, func(group *relationTb.GroupModel) string {
|
||||||
return group.GroupID
|
return group.GroupID
|
||||||
}), func(group *relationTb.GroupModel) *open_im_sdk.GroupInfo {
|
}), 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
|
return resp, nil
|
||||||
}
|
}
|
||||||
@ -321,6 +322,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
|||||||
var groupMembers []*relationTb.GroupMemberModel
|
var groupMembers []*relationTb.GroupMemberModel
|
||||||
for _, userID := range req.InvitedUserIDs {
|
for _, userID := range req.InvitedUserIDs {
|
||||||
member := PbToDbGroupMember(userMap[userID])
|
member := PbToDbGroupMember(userMap[userID])
|
||||||
|
member.Nickname = ""
|
||||||
member.GroupID = req.GroupID
|
member.GroupID = req.GroupID
|
||||||
member.RoleLevel = constant.GroupOrdinaryUsers
|
member.RoleLevel = constant.GroupOrdinaryUsers
|
||||||
member.OperatorUserID = opUserID
|
member.OperatorUserID = opUserID
|
||||||
@ -352,7 +354,16 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGro
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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 {
|
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 DbToPbGroupMembersCMSResp(e)
|
||||||
})
|
})
|
||||||
return resp, nil
|
return resp, nil
|
||||||
@ -365,7 +376,16 @@ func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGr
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
resp.Total = total
|
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 {
|
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 DbToPbGroupMembersCMSResp(e)
|
||||||
})
|
})
|
||||||
return resp, nil
|
return resp, nil
|
||||||
@ -450,7 +470,16 @@ func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbGroup.GetG
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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 {
|
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 DbToPbGroupMembersCMSResp(e)
|
||||||
})
|
})
|
||||||
return resp, nil
|
return resp, nil
|
||||||
@ -801,7 +830,16 @@ func (s *groupServer) GetGroupMembersCMS(ctx context.Context, req *pbGroup.GetGr
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
resp.Total = total
|
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 {
|
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 DbToPbGroupMembersCMSResp(e)
|
||||||
})
|
})
|
||||||
return resp, nil
|
return resp, nil
|
||||||
@ -1011,8 +1049,8 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGr
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = s.GroupInterface.UpdateGroupMembers(ctx, utils.Slice(req.Members, func(e *pbGroup.SetGroupMemberInfo) *controller.BatchUpdateGroupMember {
|
err = s.GroupInterface.UpdateGroupMembers(ctx, utils.Slice(req.Members, func(e *pbGroup.SetGroupMemberInfo) *relationTb.BatchUpdateGroupMember {
|
||||||
return &controller.BatchUpdateGroupMember{
|
return &relationTb.BatchUpdateGroupMember{
|
||||||
GroupID: e.GroupID,
|
GroupID: e.GroupID,
|
||||||
UserID: e.UserID,
|
UserID: e.UserID,
|
||||||
Map: UpdateGroupMemberMap(e),
|
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 {
|
resp.GroupAbstractInfos = utils.Slice(groups, func(group *relationTb.GroupModel) *pbGroup.GroupAbstractInfo {
|
||||||
users := groupUserMap[group.GroupID]
|
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
|
return resp, nil
|
||||||
}
|
}
|
||||||
@ -1067,7 +1105,16 @@ func (s *groupServer) GetUserInGroupMembers(ctx context.Context, req *pbGroup.Ge
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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 {
|
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 DbToPbGroupMembersCMSResp(e)
|
||||||
})
|
})
|
||||||
return resp, nil
|
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) {
|
func (s *groupServer) GetGroupMemberUserID(ctx context.Context, req *pbGroup.GetGroupMemberUserIDReq) (*pbGroup.GetGroupMemberUserIDResp, error) {
|
||||||
resp := &pbGroup.GetGroupMemberUserIDResp{}
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
resp.UserIDs = userIDs
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
111
pkg/common/db/cache/group.go
vendored
111
pkg/common/db/cache/group.go
vendored
@ -1,7 +1,6 @@
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/constant"
|
|
||||||
"Open_IM/pkg/common/db/relation"
|
"Open_IM/pkg/common/db/relation"
|
||||||
relationTb "Open_IM/pkg/common/db/table/relation"
|
relationTb "Open_IM/pkg/common/db/table/relation"
|
||||||
"Open_IM/pkg/common/db/unrelation"
|
"Open_IM/pkg/common/db/unrelation"
|
||||||
@ -12,8 +11,8 @@ import (
|
|||||||
"github.com/dtm-labs/rockscache"
|
"github.com/dtm-labs/rockscache"
|
||||||
"github.com/go-redis/redis/v8"
|
"github.com/go-redis/redis/v8"
|
||||||
"math/big"
|
"math/big"
|
||||||
"sort"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"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
|
// userJoinSuperGroup
|
||||||
func (g *GroupCacheRedis) BatchDelJoinedSuperGroupIDs(ctx context.Context, userIDs []string) (err error) {
|
func (g *GroupCacheRedis) BatchDelJoinedSuperGroupIDs(ctx context.Context, userIDs []string) (err error) {
|
||||||
for _, userID := range userIDs {
|
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
|
// groupMembersHash
|
||||||
func (g *GroupCacheRedis) GetGroupMembersHash(ctx context.Context, groupID string) (hashCodeUint64 uint64, err error) {
|
func (g *GroupCacheRedis) GetGroupMembersHash(ctx context.Context, groupID string) (hashCodeUint64 uint64, err error) {
|
||||||
generateHash := func() (string, error) {
|
return GetCache(ctx, g.rcClient, g.getGroupMembersHashKey(groupID), g.expireTime, func(ctx context.Context) (uint64, error) {
|
||||||
groupInfo, err := g.GetGroupInfo(ctx, groupID)
|
userIDs, err := g.GetGroupMemberIDs(ctx, groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return 0, err
|
||||||
}
|
|
||||||
if groupInfo.Status == constant.GroupStatusDismissed {
|
|
||||||
return "0", nil
|
|
||||||
}
|
|
||||||
groupMemberIDList, err := g.GetGroupMemberIDs(ctx, groupID)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
sort.Strings(groupMemberIDList)
|
|
||||||
var all string
|
|
||||||
for _, v := range groupMemberIDList {
|
|
||||||
all += v
|
|
||||||
}
|
}
|
||||||
|
utils.Sort(userIDs, true)
|
||||||
bi := big.NewInt(0)
|
bi := big.NewInt(0)
|
||||||
bi.SetString(utils.Md5(all)[0:8], 16)
|
bi.SetString(utils.Md5(strings.Join(userIDs, ";"))[0:8], 16)
|
||||||
return strconv.Itoa(int(bi.Uint64())), nil
|
return 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupCacheRedis) DelGroupMembersHash(ctx context.Context, groupID string) (err error) {
|
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
|
// groupMemberIDs
|
||||||
// from redis
|
|
||||||
func (g *GroupCacheRedis) GetGroupMemberIDs(ctx context.Context, groupID string) (groupMemberIDs []string, err error) {
|
func (g *GroupCacheRedis) GetGroupMemberIDs(ctx context.Context, groupID string) (groupMemberIDs []string, err error) {
|
||||||
f := func() (string, error) {
|
return GetCache(ctx, g.rcClient, g.getGroupMemberIDsKey(groupID), g.expireTime, func(ctx context.Context) ([]string, error) {
|
||||||
groupInfo, err := g.GetGroupInfo(ctx, groupID)
|
return g.groupMember.FindMemberUserID(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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupCacheRedis) DelGroupMemberIDs(ctx context.Context, groupID string) (err error) {
|
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))
|
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 GroupInterface GroupDataBaseInterface
|
||||||
|
|
||||||
type BatchUpdateGroupMember struct {
|
|
||||||
GroupID string
|
|
||||||
UserID string
|
|
||||||
Map map[string]any
|
|
||||||
}
|
|
||||||
|
|
||||||
type GroupSimpleUserID struct {
|
|
||||||
Hash uint64
|
|
||||||
UserIDs []string
|
|
||||||
}
|
|
||||||
|
|
||||||
type GroupInterface interface {
|
type GroupInterface interface {
|
||||||
CreateGroup(ctx context.Context, groups []*relationTb.GroupModel, groupMembers []*relationTb.GroupMemberModel) error
|
CreateGroup(ctx context.Context, groups []*relationTb.GroupModel, groupMembers []*relationTb.GroupMemberModel) error
|
||||||
TakeGroup(ctx context.Context, groupID string) (group *relationTb.GroupModel, err 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)
|
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
|
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
|
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)
|
MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error)
|
||||||
TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string, roleLevel int32) 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
|
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
|
// GroupRequest
|
||||||
CreateGroupRequest(ctx context.Context, requests []*relationTb.GroupRequestModel) error
|
CreateGroupRequest(ctx context.Context, requests []*relationTb.GroupRequestModel) error
|
||||||
TakeGroupRequest(ctx context.Context, groupID string, userID string) (*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)
|
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)
|
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)
|
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)
|
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)
|
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
|
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
|
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)
|
MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error)
|
||||||
TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string, roleLevel int32) 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
|
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
|
// GroupRequest
|
||||||
CreateGroupRequest(ctx context.Context, requests []*relationTb.GroupRequestModel) error
|
CreateGroupRequest(ctx context.Context, requests []*relationTb.GroupRequestModel) error
|
||||||
TakeGroupRequest(ctx context.Context, groupID string, userID string) (*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)
|
mapGroupUserIDs, err := g.groupMemberDB.FindJoinUserID(ctx, groupIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
res := make(map[string]*GroupSimpleUserID)
|
res := make(map[string]*relationTb.GroupSimpleUserID)
|
||||||
for _, groupID := range groupIDs {
|
for _, groupID := range groupIDs {
|
||||||
users := &GroupSimpleUserID{
|
userIDs := mapGroupUserIDs[groupID]
|
||||||
UserIDs: mapGroupUserIDs[groupID],
|
users := &relationTb.GroupSimpleUserID{}
|
||||||
}
|
if len(userIDs) > 0 {
|
||||||
if len(users.UserIDs) > 0 {
|
utils.Sort(userIDs, true)
|
||||||
utils.Sort(users.UserIDs, true)
|
|
||||||
bi := big.NewInt(0)
|
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
|
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 {
|
return g.db.Transaction(func(tx *gorm.DB) error {
|
||||||
for _, item := range data {
|
for _, item := range data {
|
||||||
if err := g.groupMemberDB.Update(ctx, item.GroupID, item.UserID, item.Map, tx); err != nil {
|
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 {
|
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 unrelation.MongoTransaction(ctx, g.mongoDB.MgoClient, func(tx mongo.SessionContext) error {
|
||||||
return s.CreateSuperGroup(ctx, groupID, initMemberIDList, tx)
|
return g.mongoDB.CreateSuperGroup(ctx, groupID, initMemberIDList, tx)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupDataBase) DeleteSuperGroup(ctx context.Context, groupID string) error {
|
func (g *GroupDataBase) DeleteSuperGroup(ctx context.Context, groupID string) error {
|
||||||
return g.mongoDB.Transaction(ctx, func(s unrelationTb.SuperGroupModelInterface, tx any) error {
|
return unrelation.MongoTransaction(ctx, g.mongoDB.MgoClient, func(tx mongo.SessionContext) error {
|
||||||
return s.DeleteSuperGroup(ctx, groupID, tx)
|
return g.mongoDB.DeleteSuperGroup(ctx, groupID, tx)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupDataBase) DeleteSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
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 unrelation.MongoTransaction(ctx, g.mongoDB.MgoClient, func(tx mongo.SessionContext) error {
|
||||||
return s.RemoverUserFromSuperGroup(ctx, groupID, userIDs, tx)
|
return g.mongoDB.RemoverUserFromSuperGroup(ctx, groupID, userIDs, tx)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupDataBase) CreateSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
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 unrelation.MongoTransaction(ctx, g.mongoDB.MgoClient, func(tx mongo.SessionContext) error {
|
||||||
return s.AddUserToSuperGroup(ctx, groupID, userIDs, tx)
|
return g.mongoDB.AddUserToSuperGroup(ctx, groupID, userIDs, tx)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
12
pkg/common/db/table/relation/utils.go
Normal file
12
pkg/common/db/table/relation/utils.go
Normal file
@ -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 {
|
func Filter[E, T any](es []E, fn func(e E) (T, bool)) []T {
|
||||||
rs := make([]E, 0, len(es))
|
rs := make([]T, 0, len(es))
|
||||||
for i := 0; i < len(es); i++ {
|
for i := 0; i < len(es); i++ {
|
||||||
if e := es[i]; fn(e) {
|
e := es[i]
|
||||||
rs = append(rs, e)
|
if t, ok := fn(e); ok {
|
||||||
|
rs = append(rs, t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rs
|
return rs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user