group controller

test-errcode
withchao 2 years ago
parent dad31652ad
commit 77edbe1edd

@ -251,32 +251,37 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo
if err := token_verify.CheckAccessV3(ctx, req.FromUserID); err != nil {
return nil, err
}
total, groups, err := s.GroupInterface.FindJoinedGroup(ctx, req.FromUserID, req.Pagination.PageNumber, req.Pagination.ShowNumber)
total, members, err := s.GroupInterface.PageGroupMember(ctx, nil, []string{req.FromUserID}, nil, req.Pagination.PageNumber, req.Pagination.ShowNumber)
if err != nil {
return nil, err
}
resp.Total = total
if len(groups) == 0 {
if len(members) == 0 {
return resp, nil
}
groupIDs := utils.Slice(groups, func(e *relation2.GroupModel) string {
groupIDs := utils.Slice(members, func(e *relation2.GroupMemberModel) string {
return e.GroupID
})
groupMemberNum, err := s.GroupInterface.MapGroupMemberNum(ctx, groupIDs)
groups, err := s.GroupInterface.FindGroup(ctx, groupIDs)
if err != nil {
return nil, err
}
groupOwnerUserID, err := s.GroupInterface.MapGroupOwnerUserID(ctx, groupIDs)
groupMemberNum, err := s.GroupInterface.MapGroupMemberNum(ctx, groupIDs)
if err != nil {
return nil, err
}
for _, group := range groups {
if group.Status == constant.GroupStatusDismissed || group.GroupType == constant.SuperGroup {
continue
}
resp.Groups = append(resp.Groups, DbToPbGroupInfo(group, groupOwnerUserID[group.GroupID], uint32(groupMemberNum[group.GroupID])))
owners, err := s.GroupInterface.FindGroupMember(ctx, groupIDs, nil, []int32{constant.GroupOwner})
if err != nil {
return nil, err
}
resp.Total = int32(len(resp.Groups))
ownerMap := utils.SliceToMap(owners, func(e *relation2.GroupMemberModel) string {
return e.GroupID
})
resp.Groups = utils.Slice(utils.Order(groupIDs, groups, func(group *relation2.GroupModel) string {
return group.GroupID
}), func(group *relation2.GroupModel) *open_im_sdk.GroupInfo {
return DbToPbGroupInfo(group, ownerMap[group.GroupID].UserID, uint32(groupMemberNum[group.GroupID]))
})
return resp, nil
}
@ -295,7 +300,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
if group.Status == constant.GroupStatusDismissed {
return nil, constant.ErrDismissedAlready.Wrap()
}
members, err := s.GroupInterface.FindGroupMemberAll(ctx, group.GroupID)
members, err := s.GroupInterface.FindGroupMember(ctx, []string{group.GroupID}, nil, nil)
if err != nil {
return nil, err
}
@ -345,7 +350,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
}
}
if group.GroupType == constant.SuperGroup {
if err := s.GroupInterface.AddUserToSuperGroup(ctx, req.GroupID, req.InvitedUserIDs); err != nil {
if err := s.GroupInterface.CreateSuperGroupMember(ctx, req.GroupID, req.InvitedUserIDs); err != nil {
return nil, err
}
for _, userID := range req.InvitedUserIDs {
@ -366,7 +371,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
}
groupMembers = append(groupMembers, member)
}
if err := s.GroupInterface.CreateGroupMember(ctx, groupMembers); err != nil {
if err := s.GroupInterface.CreateGroup(ctx, nil, groupMembers); err != nil {
return nil, err
}
chat.MemberInvitedNotification(tracelog.GetOperationID(ctx), req.GroupID, tracelog.GetOpUserID(ctx), req.Reason, req.InvitedUserIDs)
@ -383,7 +388,7 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGro
if group.GroupType == constant.SuperGroup {
return nil, constant.ErrArgs.Wrap("unsupported super group")
}
members, err := s.GroupInterface.FindGroupMemberAll(ctx, req.GroupID)
members, err := s.GroupInterface.FindGroupMember(ctx, []string{req.GroupID}, nil, nil)
if err != nil {
return nil, err
}
@ -395,10 +400,11 @@ 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{}
members, err := s.GroupInterface.FindGroupMemberFilterList(ctx, req.GroupID, req.Filter, req.Pagination.PageNumber, req.Pagination.ShowNumber)
total, members, err := s.GroupInterface.PageGroupMember(ctx, []string{req.GroupID}, nil, utils.If(req.Filter >= 0, []int32{req.Filter}, nil), req.Pagination.PageNumber, req.Pagination.ShowNumber)
if err != nil {
return nil, err
}
resp.Total = total
resp.Members = utils.Slice(members, func(e *relation2.GroupMemberModel) *open_im_sdk.GroupMemberFullInfo {
return DbToPbGroupMembersCMSResp(e)
})
@ -431,7 +437,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
}
}()
} else {
members, err := s.GroupInterface.FindGroupMember(ctx, req.GroupID, append(req.KickedUserIDs, opUserID))
members, err := s.GroupInterface.FindGroupMember(ctx, []string{req.GroupID}, append(req.KickedUserIDs, opUserID), nil)
if err != nil {
return nil, err
}
@ -474,7 +480,13 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbGroup.GetGroupMembersInfoReq) (*pbGroup.GetGroupMembersInfoResp, error) {
resp := &pbGroup.GetGroupMembersInfoResp{}
members, err := s.GroupInterface.FindGroupMember(ctx, req.GroupID, req.Members)
if len(req.Members) == 0 {
return nil, constant.ErrArgs.Wrap("members empty")
}
if req.GroupID == "" {
return nil, constant.ErrArgs.Wrap("groupID empty")
}
members, err := s.GroupInterface.FindGroupMember(ctx, []string{req.GroupID}, req.Members, nil)
if err != nil {
return nil, err
}
@ -486,10 +498,11 @@ func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbGroup.GetG
func (s *groupServer) GetGroupApplicationList(ctx context.Context, req *pbGroup.GetGroupApplicationListReq) (*pbGroup.GetGroupApplicationListResp, error) {
resp := &pbGroup.GetGroupApplicationListResp{}
groupRequests, err := s.GroupInterface.GetGroupRecvApplicationList(ctx, req.FromUserID)
total, groupRequests, err := s.GroupInterface.PageGroupRequestUser(ctx, req.FromUserID, req.Pagination.PageNumber, req.Pagination.ShowNumber)
if err != nil {
return nil, err
}
resp.Total = total
if len(groupRequests) == 0 {
return resp, nil
}
@ -524,12 +537,15 @@ func (s *groupServer) GetGroupApplicationList(ctx context.Context, req *pbGroup.
if err != nil {
return nil, err
}
groupOwnerUserIDMap, err := s.GroupInterface.MapGroupOwnerUserID(ctx, groupIDs)
owners, err := s.GroupInterface.FindGroupMember(ctx, groupIDs, nil, []int32{constant.GroupOwner})
if err != nil {
return nil, err
}
ownerMap := utils.SliceToMap(owners, func(e *relation2.GroupMemberModel) string {
return e.GroupID
})
resp.GroupRequests = utils.Slice(groupRequests, func(e *relation2.GroupRequestModel) *open_im_sdk.GroupRequest {
return DbToPbGroupRequest(e, userMap[e.UserID], DbToPbGroupInfo(groupMap[e.GroupID], groupOwnerUserIDMap[e.GroupID], uint32(groupMemberNumMap[e.GroupID])))
return DbToPbGroupRequest(e, userMap[e.UserID], DbToPbGroupInfo(groupMap[e.GroupID], ownerMap[e.GroupID].UserID, uint32(groupMemberNumMap[e.GroupID])))
})
return resp, nil
}
@ -547,12 +563,15 @@ func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsI
if err != nil {
return nil, err
}
groupOwnerUserIDMap, err := s.GroupInterface.MapGroupOwnerUserID(ctx, req.GroupIDs)
owners, err := s.GroupInterface.FindGroupMember(ctx, req.GroupIDs, nil, []int32{constant.GroupOwner})
if err != nil {
return nil, err
}
ownerMap := utils.SliceToMap(owners, func(e *relation2.GroupMemberModel) string {
return e.GroupID
})
resp.GroupInfos = utils.Slice(groups, func(e *relation2.GroupModel) *open_im_sdk.GroupInfo {
return DbToPbGroupInfo(e, groupOwnerUserIDMap[e.GroupID], uint32(groupMemberNumMap[e.GroupID]))
return DbToPbGroupInfo(e, ownerMap[e.GroupID].UserID, uint32(groupMemberNumMap[e.GroupID]))
})
return resp, nil
}
@ -652,7 +671,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
if err := CallbackBeforeMemberJoinGroup(ctx, tracelog.GetOperationID(ctx), groupMember, group.Ex); err != nil {
return nil, err
}
if err := s.GroupInterface.CreateGroupMember(ctx, []*relation2.GroupMemberModel{groupMember}); err != nil {
if err := s.GroupInterface.CreateGroup(ctx, nil, []*relation2.GroupMemberModel{groupMember}); err != nil {
return nil, err
}
chat.MemberEnterDirectlyNotification(req.GroupID, tracelog.GetOpUserID(ctx), tracelog.GetOperationID(ctx))
@ -741,7 +760,7 @@ func (s *groupServer) TransferGroupOwner(ctx context.Context, req *pbGroup.Trans
if req.OldOwnerUserID == req.NewOwnerUserID {
return nil, constant.ErrArgs.Wrap("OldOwnerUserID == NewOwnerUserID")
}
members, err := s.GroupInterface.FindGroupMember(ctx, req.GroupID, []string{req.OldOwnerUserID, req.NewOwnerUserID})
members, err := s.GroupInterface.FindGroupMember(ctx, []string{req.GroupID}, []string{req.OldOwnerUserID, req.NewOwnerUserID}, nil)
if err != nil {
return nil, err
}
@ -794,7 +813,7 @@ func (s *groupServer) GetGroups(ctx context.Context, req *pbGroup.GetGroupsReq)
groupIDs := utils.Slice(groups, func(e *relation2.GroupModel) string {
return e.GroupID
})
ownerMembers, err := s.GroupInterface.FindGroupOwnerUser(ctx, groupIDs)
ownerMembers, err := s.GroupInterface.FindGroupMember(ctx, groupIDs, nil, []int32{constant.GroupOwner})
if err != nil {
return nil, err
}
@ -817,7 +836,7 @@ func (s *groupServer) GetGroups(ctx context.Context, req *pbGroup.GetGroupsReq)
func (s *groupServer) GetGroupMembersCMS(ctx context.Context, req *pbGroup.GetGroupMembersCMSReq) (*pbGroup.GetGroupMembersCMSResp, error) {
resp := &pbGroup.GetGroupMembersCMSResp{}
total, members, err := s.GroupInterface.SearchGroupMember(ctx, req.GroupID, req.UserName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
total, members, err := s.GroupInterface.SearchGroupMember(ctx, req.UserName, []string{req.GroupID}, nil, nil, req.Pagination.PageNumber, req.Pagination.ShowNumber)
if err != nil {
return nil, err
}
@ -834,7 +853,7 @@ func (s *groupServer) GetUserReqApplicationList(ctx context.Context, req *pbGrou
if err != nil {
return nil, err
}
total, requests, err := s.GroupInterface.FindUserGroupRequest(ctx, req.UserID, req.Pagination.PageNumber, req.Pagination.ShowNumber)
total, requests, err := s.GroupInterface.PageGroupRequestUser(ctx, req.UserID, req.Pagination.PageNumber, req.Pagination.ShowNumber)
if err != nil {
return nil, err
}
@ -855,7 +874,7 @@ func (s *groupServer) GetUserReqApplicationList(ctx context.Context, req *pbGrou
if ids := utils.Single(groupIDs, utils.Keys(groupMap)); len(ids) > 0 {
return nil, constant.ErrGroupIDNotFound.Wrap(strings.Join(ids, ","))
}
owners, err := s.GroupInterface.FindGroupOwnerUser(ctx, groupIDs)
owners, err := s.GroupInterface.FindGroupMember(ctx, groupIDs, nil, []int32{constant.GroupOwner})
if err != nil {
return nil, err
}
@ -1048,7 +1067,7 @@ func (s *groupServer) GetUserInGroupMembers(ctx context.Context, req *pbGroup.Ge
if len(req.GroupIDs) == 0 {
return nil, constant.ErrArgs.Wrap("groupIDs empty")
}
members, err := s.GroupInterface.FindGroupMember(ctx, req.UserID, req.GroupIDs)
members, err := s.GroupInterface.FindGroupMember(ctx, []string{req.UserID}, req.GroupIDs, nil)
if err != nil {
return nil, err
}

@ -23,10 +23,13 @@ func (s *groupServer) GetJoinedSuperGroupList(ctx context.Context, req *pbGroup.
if err != nil {
return nil, err
}
ownerIdMap, err := s.GroupInterface.MapGroupOwnerUserID(ctx, groupIDs)
owners, err := s.GroupInterface.FindGroupMember(ctx, groupIDs, nil, []int32{constant.GroupOwner})
if err != nil {
return nil, err
}
ownerMap := utils.SliceToMap(owners, func(e *relation.GroupMemberModel) string {
return e.GroupID
})
groups, err := s.GroupInterface.FindGroup(ctx, groupIDs)
if err != nil {
return nil, err
@ -35,7 +38,7 @@ func (s *groupServer) GetJoinedSuperGroupList(ctx context.Context, req *pbGroup.
return e.GroupID
})
resp.Groups = utils.Slice(groupIDs, func(groupID string) *sdk_ws.GroupInfo {
return DbToPbGroupInfo(groupMap[groupID], ownerIdMap[groupID], numMap[groupID])
return DbToPbGroupInfo(groupMap[groupID], ownerMap[groupID].UserID, numMap[groupID])
})
return resp, nil
}
@ -53,12 +56,15 @@ func (s *groupServer) GetSuperGroupsInfo(ctx context.Context, req *pbGroup.GetSu
if err != nil {
return nil, err
}
ownerIdMap, err := s.GroupInterface.MapGroupOwnerUserID(ctx, req.GroupIDs)
owners, err := s.GroupInterface.FindGroupMember(ctx, req.GroupIDs, nil, []int32{constant.GroupOwner})
if err != nil {
return nil, err
}
ownerMap := utils.SliceToMap(owners, func(e *relation.GroupMemberModel) string {
return e.GroupID
})
resp.GroupInfos = utils.Slice(groups, func(e *relation.GroupModel) *sdk_ws.GroupInfo {
return DbToPbGroupInfo(e, ownerIdMap[e.GroupID], numMap[e.GroupID])
return DbToPbGroupInfo(e, ownerMap[e.GroupID].UserID, numMap[e.GroupID])
})
return resp, nil
}

@ -1,284 +1,92 @@
package controller
import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db/cache"
"Open_IM/pkg/common/db/relation"
relation2 "Open_IM/pkg/common/db/table/relation"
unrelation2 "Open_IM/pkg/common/db/table/unrelation"
"Open_IM/pkg/common/db/unrelation"
"Open_IM/pkg/utils"
"context"
"github.com/dtm-labs/rockscache"
_ "github.com/dtm-labs/rockscache"
"github.com/go-redis/redis/v8"
"go.mongodb.org/mongo-driver/mongo"
"gorm.io/gorm"
)
type GroupInterface interface {
// group
FindGroup(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error)
SearchGroup(ctx context.Context, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error)
TakeGroup(ctx context.Context, groupID string) (group *relation2.GroupModel, err error)
FindJoinedGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error)
UpdateGroup(ctx context.Context, groupID string, data map[string]any) error
DismissGroup(ctx context.Context, groupID string) error // 解散群,并删除群成员
// groupMember
CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMember []*relation2.GroupMemberModel) error
TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupMemberModel, err error)
FindGroupMember(ctx context.Context, groupID string, userIDs []string) ([]*relation2.GroupMemberModel, error)
FindGroupMemberAll(ctx context.Context, groupID string) ([]*relation2.GroupMemberModel, error)
FindGroupMemberFilterList(ctx context.Context, groupID string, filter int32, begin int32, maxNumber int32) ([]*relation2.GroupMemberModel, error) // relation.GetGroupMemberByGroupID(req.GroupID, req.Filter, req.NextSeq, 30)
SearchGroupMember(ctx context.Context, groupID, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error)
TakeGroupOwner(ctx context.Context, groupID string) (*relation2.GroupMemberModel, error)
FindGroupOwnerUser(ctx context.Context, groupID []string) ([]*relation2.GroupMemberModel, error)
CreateGroupMember(ctx context.Context, groupMember []*relation2.GroupMemberModel) error
HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relation2.GroupMemberModel) error
DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error
MapGroupHash(ctx context.Context, groupIDs []string) (map[string]uint64, error)
MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error)
MapGroupOwnerUserID(ctx context.Context, groupIDs []string) (map[string]string, error)
TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string) error // 转让群
UpdateGroupMember(ctx context.Context, groupID, userID string, data map[string]any) error
CreateGroupRequest(ctx context.Context, requests []*relation2.GroupRequestModel) error
GetGroupRecvApplicationList(ctx context.Context, userID string) ([]*relation2.GroupRequestModel, error) // ?
TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relation2.GroupRequestModel, error)
FindUserGroupRequest(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupRequestModel, error)
// superGroup
TakeSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation2.SuperGroupModel, err error)
CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error
DeleteSuperGroup(ctx context.Context, groupID string) error
DeleteSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error
AddUserToSuperGroup(ctx context.Context, groupID string, userIDs []string) error
FindJoinSuperGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (total int32, groupIDs []string, err error)
MapSuperGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error)
}
var _ GroupInterface = (*GroupController)(nil)
type GroupController struct {
database GroupDataBaseInterface
}
func (g *GroupController) FindGroup(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) SearchGroup(ctx context.Context, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) TakeGroup(ctx context.Context, groupID string) (group *relation2.GroupModel, err error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) FindJoinedGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) UpdateGroup(ctx context.Context, groupID string, data map[string]any) error {
//TODO implement me
panic("implement me")
}
func (g *GroupController) DismissGroup(ctx context.Context, groupID string) error {
//TODO implement me
panic("implement me")
}
func (g *GroupController) CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMember []*relation2.GroupMemberModel) error {
//TODO implement me
panic("implement me")
}
func (g *GroupController) TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupMemberModel, err error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) FindGroupMember(ctx context.Context, groupID string, userIDs []string) ([]*relation2.GroupMemberModel, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) FindGroupMemberAll(ctx context.Context, groupID string) ([]*relation2.GroupMemberModel, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) FindGroupMemberFilterList(ctx context.Context, groupID string, filter int32, begin int32, maxNumber int32) ([]*relation2.GroupMemberModel, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) SearchGroupMember(ctx context.Context, groupID, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) TakeGroupOwner(ctx context.Context, groupID string) (*relation2.GroupMemberModel, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) FindGroupOwnerUser(ctx context.Context, groupID []string) ([]*relation2.GroupMemberModel, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) CreateGroupMember(ctx context.Context, groupMember []*relation2.GroupMemberModel) error {
//TODO implement me
panic("implement me")
}
func (g *GroupController) HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relation2.GroupMemberModel) error {
//TODO implement me
panic("implement me")
}
func (g *GroupController) DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error {
//TODO implement me
panic("implement me")
}
func (g *GroupController) MapGroupHash(ctx context.Context, groupIDs []string) (map[string]uint64, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) MapGroupOwnerUserID(ctx context.Context, groupIDs []string) (map[string]string, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string) error {
//TODO implement me
panic("implement me")
}
func (g *GroupController) UpdateGroupMember(ctx context.Context, groupID, userID string, data map[string]any) error {
//TODO implement me
panic("implement me")
}
func (g *GroupController) CreateGroupRequest(ctx context.Context, requests []*relation2.GroupRequestModel) error {
//TODO implement me
panic("implement me")
}
func (g *GroupController) GetGroupRecvApplicationList(ctx context.Context, userID string) ([]*relation2.GroupRequestModel, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relation2.GroupRequestModel, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) FindUserGroupRequest(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupRequestModel, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) TakeSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation2.SuperGroupModel, err error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error {
//TODO implement me
panic("implement me")
}
func (g *GroupController) DeleteSuperGroup(ctx context.Context, groupID string) error {
//TODO implement me
panic("implement me")
}
func (g *GroupController) DeleteSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error {
//TODO implement me
panic("implement me")
}
func (g *GroupController) AddUserToSuperGroup(ctx context.Context, groupID string, userIDs []string) error {
//TODO implement me
panic("implement me")
}
func (g *GroupController) FindJoinSuperGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (total int32, groupIDs []string, err error) {
//TODO implement me
panic("implement me")
}
func (g *GroupController) MapSuperGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error) {
//TODO implement me
panic("implement me")
}
type GroupInterface GroupDataBaseInterface
//type GroupInterface interface {
// // Group
// CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMembers []*relation2.GroupMemberModel) error
// TakeGroup(ctx context.Context, groupID string) (group *relation2.GroupModel, err error)
// FindGroup(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error)
// SearchGroup(ctx context.Context, keyword string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error)
// UpdateGroup(ctx context.Context, groupID string, data map[string]any) error
// DismissGroup(ctx context.Context, groupID string) error // 解散群,并删除群成员
// // GroupMember
// TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupMemberModel, err error)
// TakeGroupOwner(ctx context.Context, groupID string) (*relation2.GroupMemberModel, error)
// FindGroupMember(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32) ([]*relation2.GroupMemberModel, error)
// PageGroupMember(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error)
// SearchGroupMember(ctx context.Context, name string, groupIDs []string, userIDs []string, roleLevels []int32, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error)
// HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relation2.GroupMemberModel) error
// DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error
// MapGroupHash(ctx context.Context, groupIDs []string) (map[string]uint64, error)
// MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error)
// TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string) error // 转让群
// UpdateGroupMember(ctx context.Context, groupID, userID string, data map[string]any) error
// // GroupRequest
// CreateGroupRequest(ctx context.Context, requests []*relation2.GroupRequestModel) error
// TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relation2.GroupRequestModel, error)
// PageGroupRequestUser(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupRequestModel, error)
// // SuperGroup
// TakeSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation2.SuperGroupModel, err error)
// FindJoinSuperGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (total int32, groupIDs []string, err error)
// CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error
// DeleteSuperGroup(ctx context.Context, groupID string) error
// DeleteSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error
// CreateSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error
// MapSuperGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error)
//}
//
//var _ GroupInterface = (*GroupController)(nil)
//
//type GroupController struct {
// database GroupDataBaseInterface
//}
type GroupDataBaseInterface interface {
// group
FindGroup(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error)
SearchGroup(ctx context.Context, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error)
CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMembers []*relation2.GroupMemberModel) error
TakeGroup(ctx context.Context, groupID string) (group *relation2.GroupModel, err error)
FindJoinedGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error)
FindGroup(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error)
SearchGroup(ctx context.Context, keyword string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error)
UpdateGroup(ctx context.Context, groupID string, data map[string]any) error
DismissGroup(ctx context.Context, groupID string) error // 解散群,并删除群成员
// groupMember
CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMember []*relation2.GroupMemberModel) error
// GroupMember
TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupMemberModel, err error)
FindGroupMember(ctx context.Context, groupID string, userIDs []string) ([]*relation2.GroupMemberModel, error)
FindGroupMemberAll(ctx context.Context, groupID string) ([]*relation2.GroupMemberModel, error)
FindGroupMemberFilterList(ctx context.Context, groupID string, filter int32, begin int32, maxNumber int32) ([]*relation2.GroupMemberModel, error) // relation.GetGroupMemberByGroupID(req.GroupID, req.Filter, req.NextSeq, 30)
SearchGroupMember(ctx context.Context, groupID, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error)
TakeGroupOwner(ctx context.Context, groupID string) (*relation2.GroupMemberModel, error)
FindGroupOwnerUser(ctx context.Context, groupID []string) ([]*relation2.GroupMemberModel, error)
CreateGroupMember(ctx context.Context, groupMember []*relation2.GroupMemberModel) error
FindGroupMember(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32) ([]*relation2.GroupMemberModel, error)
PageGroupMember(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error)
SearchGroupMember(ctx context.Context, name string, groupIDs []string, userIDs []string, roleLevels []int32, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error)
HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relation2.GroupMemberModel) error
DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error
MapGroupHash(ctx context.Context, groupIDs []string) (map[string]uint64, error)
MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error)
MapGroupOwnerUserID(ctx context.Context, groupIDs []string) (map[string]string, error)
TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string) error // 转让群
UpdateGroupMember(ctx context.Context, groupID, userID string, data map[string]any) error
// GroupRequest
CreateGroupRequest(ctx context.Context, requests []*relation2.GroupRequestModel) error
GetGroupRecvApplicationList(ctx context.Context, userID string) ([]*relation2.GroupRequestModel, error) // ?
TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relation2.GroupRequestModel, error)
FindUserGroupRequest(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupRequestModel, error)
// superGroup
PageGroupRequestUser(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupRequestModel, error)
// SuperGroup
TakeSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation2.SuperGroupModel, err error)
FindJoinSuperGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (total int32, groupIDs []string, err error)
CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error
DeleteSuperGroup(ctx context.Context, groupID string) error
DeleteSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error
AddUserToSuperGroup(ctx context.Context, groupID string, userIDs []string) error
FindJoinSuperGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (total int32, groupIDs []string, err error)
CreateSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error
MapSuperGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error)
}
var _ *GroupDataBase = (GroupDataBaseInterface)(nil)
type GroupDataBase struct {
groupDB *relation.GroupGorm
groupMemberDB *relation.GroupMemberGorm
groupRequestDB *relation.GroupRequestGorm
db *gorm.DB
cache *cache.GroupCache
mongoDB *unrelation.SuperGroupMongoDriver
}
func newGroupDatabase(db *gorm.DB, rdb redis.UniversalClient, mgoClient *mongo.Client) GroupDataBaseInterface {
groupDB := relation.NewGroupDB(db)
groupMemberDB := relation.NewGroupMemberDB(db)
@ -381,50 +189,104 @@ func newGroupDatabase(db *gorm.DB, rdb redis.UniversalClient, mgoClient *mongo.C
// return g.mongoDB.GetSuperGroup(ctx, groupID)
//}
func (g *GroupDataBase) FindGroup(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error) {
return g.groupDB.Find(ctx, groupIDs)
}
func (g *GroupDataBase) SearchGroup(ctx context.Context, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error) {
return g.groupDB.Search(ctx, name, pageNumber, showNumber)
}
func (g *GroupDataBase) TakeGroup(ctx context.Context, groupID string) (group *relation2.GroupModel, err error) {
return g.groupDB.Take(ctx, groupID)
}
//func (g *GroupDataBase) FindGroup(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error) {
// return g.groupDB.Find(ctx, groupIDs)
//}
//
//func (g *GroupDataBase) SearchGroup(ctx context.Context, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error) {
// return g.groupDB.Search(ctx, name, pageNumber, showNumber)
//}
//
//func (g *GroupDataBase) TakeGroup(ctx context.Context, groupID string) (group *relation2.GroupModel, err error) {
// return g.groupDB.Take(ctx, groupID)
//}
//
//func (g *GroupDataBase) FindJoinedGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error) {
// total, members, err := g.groupMemberDB.PageByUser(ctx, userID, pageNumber, showNumber)
// if err != nil {
// return 0, nil, err
// }
// if len(members) == 0 {
// return total, []*relation2.GroupModel{}, nil
// }
// groupIDs := utils.Slice(members, func(e *relation2.GroupMemberModel) string {
// return e.GroupID
// })
// groups, err := g.groupDB.Find(ctx, groupIDs)
// if err != nil {
// return 0, nil, err
// }
// utils.OrderPtr(groupIDs, &groups, func(e *relation2.GroupModel) string {
// return e.GroupID
// })
// return total, groups, nil
//}
//
//func (g *GroupDataBase) UpdateGroup(ctx context.Context, groupID string, data map[string]any) error {
// return g.groupDB.UpdateMap(ctx, groupID, data)
//}
//
//func (g *GroupDataBase) DismissGroup(ctx context.Context, groupID string) error {
// return utils.Wrap(g.db.Transaction(func(tx *gorm.DB) error {
// if err := g.groupDB.UpdateStatus(ctx, groupID, constant.GroupStatusDismissed, tx); err != nil {
// return err
// }
// return g.groupMemberDB.DeleteGroup(ctx, []string{groupID}, tx)
// }), "")
//}
//
//func (g *GroupDataBase) CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMembers []*relation2.GroupMemberModel) error {
// if len(groups) > 0 && len(groupMembers) > 0 {
// return g.db.Transaction(func(tx *gorm.DB) error {
// if err := g.groupDB.Create(ctx, groups, tx); err != nil {
// return err
// }
// return g.groupMemberDB.Create(ctx, groupMembers, tx)
// })
// }
// if len(groups) > 0 {
// return g.groupDB.Create(ctx, groups)
// }
// if len(groupMembers) > 0 {
// return g.groupMemberDB.Create(ctx, groupMembers)
// }
// return nil
//}
//
//func (g *GroupDataBase) TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupMemberModel, err error) {
// return g.groupMemberDB.Take(ctx, groupID, userID)
//}
//
//func (g *GroupDataBase) FindGroupMember(ctx context.Context, groupID string, userIDs []string) ([]*relation2.GroupMemberModel, error) {
// return g.groupMemberDB.FindGroupUser(ctx, []string{groupID}, userIDs, nil)
//}
//
//func (g *GroupDataBase) FindGroupMemberAll(ctx context.Context, groupID string) ([]*relation2.GroupMemberModel, error) {
// return g.groupMemberDB.FindGroupUser(ctx, []string{groupID}, nil, nil)
//}
//
//func (g *GroupDataBase) SearchGroupMember(ctx context.Context, groupID string, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error) {
// return g.groupMemberDB.SearchMember(ctx, groupID, name, pageNumber, showNumber)
//}
//
//func (g *GroupDataBase) TakeGroupOwner(ctx context.Context, groupID string) (*relation2.GroupMemberModel, error) {
// return g.groupMemberDB.TakeOwner(ctx, groupID)
//}
//
//func (g *GroupDataBase) FindGroupOwnerUser(ctx context.Context, groupIDs []string) ([]*relation2.GroupMemberModel, error) {
// return g.groupMemberDB.FindGroupUser(ctx, groupIDs, nil, []int32{constant.GroupOwner})
//}
func (g *GroupDataBase) FindJoinedGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error) {
total, members, err := g.groupMemberDB.PageByUser(ctx, userID, pageNumber, showNumber)
if err != nil {
return 0, nil, err
}
if len(members) == 0 {
return total, []*relation2.GroupModel{}, nil
}
groupIDs := utils.Slice(members, func(e *relation2.GroupMemberModel) string {
return e.GroupID
})
groups, err := g.groupDB.Find(ctx, groupIDs)
if err != nil {
return 0, nil, err
}
utils.OrderPtr(groupIDs, &groups, func(e *relation2.GroupModel) string {
return e.GroupID
})
return total, groups, nil
}
var _ GroupDataBaseInterface = (*GroupDataBase)(nil)
func (g *GroupDataBase) UpdateGroup(ctx context.Context, groupID string, data map[string]any) error {
return g.groupDB.UpdateMap(ctx, groupID, data)
}
type GroupDataBase struct {
groupDB *relation.GroupGorm
groupMemberDB *relation.GroupMemberGorm
groupRequestDB *relation.GroupRequestGorm
db *gorm.DB
func (g *GroupDataBase) DismissGroup(ctx context.Context, groupID string) error {
return utils.Wrap(g.db.Transaction(func(tx *gorm.DB) error {
if err := g.groupDB.UpdateStatus(ctx, groupID, constant.GroupStatusDismissed, tx); err != nil {
return err
}
return g.groupMemberDB.DeleteGroup(ctx, []string{groupID}, tx)
}), "")
cache *cache.GroupCache
mongoDB *unrelation.SuperGroupMongoDriver
}
func (g *GroupDataBase) CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMembers []*relation2.GroupMemberModel) error {
@ -445,61 +307,72 @@ func (g *GroupDataBase) CreateGroup(ctx context.Context, groups []*relation2.Gro
return nil
}
func (g *GroupDataBase) TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupMemberModel, err error) {
return g.groupMemberDB.Take(ctx, groupID, userID)
func (g *GroupDataBase) TakeGroup(ctx context.Context, groupID string) (group *relation2.GroupModel, err error) {
//TODO implement me
panic("implement me")
}
func (g *GroupDataBase) FindGroupMember(ctx context.Context, groupID string, userIDs []string) ([]*relation2.GroupMemberModel, error) {
return g.groupMemberDB.FindGroupUser(ctx, []string{groupID}, userIDs, nil)
func (g *GroupDataBase) FindGroup(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error) {
//TODO implement me
panic("implement me")
}
func (g *GroupDataBase) FindGroupMemberAll(ctx context.Context, groupID string) ([]*relation2.GroupMemberModel, error) {
return g.groupMemberDB.FindGroupUser(ctx, []string{groupID}, nil, nil)
func (g *GroupDataBase) SearchGroup(ctx context.Context, keyword string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupDataBase) FindGroupMemberFilterList(ctx context.Context, groupID string, filter int32, begin int32, maxNumber int32) ([]*relation2.GroupMemberModel, error) {
func (g *GroupDataBase) UpdateGroup(ctx context.Context, groupID string, data map[string]any) error {
//TODO implement me
panic("implement me")
}
func (g *GroupDataBase) SearchGroupMember(ctx context.Context, groupID string, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error) {
return g.groupMemberDB.SearchMember(ctx, groupID, name, pageNumber, showNumber)
func (g *GroupDataBase) DismissGroup(ctx context.Context, groupID string) error {
//TODO implement me
panic("implement me")
}
func (g *GroupDataBase) TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupMemberModel, err error) {
//TODO implement me
panic("implement me")
}
func (g *GroupDataBase) TakeGroupOwner(ctx context.Context, groupID string) (*relation2.GroupMemberModel, error) {
return g.groupMemberDB.TakeOwner(ctx, groupID)
//TODO implement me
panic("implement me")
}
func (g *GroupDataBase) FindGroupOwnerUser(ctx context.Context, groupIDs []string) ([]*relation2.GroupMemberModel, error) {
return g.groupMemberDB.FindGroupUser(ctx, groupIDs, nil, []int32{constant.GroupOwner})
func (g *GroupDataBase) FindGroupMember(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32) ([]*relation2.GroupMemberModel, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupDataBase) CreateGroupMember(ctx context.Context, groupMember []*relation2.GroupMemberModel) error {
func (g *GroupDataBase) PageGroupMember(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupDataBase) HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relation2.GroupMemberModel) error {
func (g *GroupDataBase) SearchGroupMember(ctx context.Context, name string, groupIDs []string, userIDs []string, roleLevels []int32, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupDataBase) DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error {
func (g *GroupDataBase) HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relation2.GroupMemberModel) error {
//TODO implement me
panic("implement me")
}
func (g *GroupDataBase) MapGroupHash(ctx context.Context, groupIDs []string) (map[string]uint64, error) {
func (g *GroupDataBase) DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error {
//TODO implement me
panic("implement me")
}
func (g *GroupDataBase) MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error) {
func (g *GroupDataBase) MapGroupHash(ctx context.Context, groupIDs []string) (map[string]uint64, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupDataBase) MapGroupOwnerUserID(ctx context.Context, groupIDs []string) (map[string]string, error) {
func (g *GroupDataBase) MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error) {
//TODO implement me
panic("implement me")
}
@ -519,22 +392,22 @@ func (g *GroupDataBase) CreateGroupRequest(ctx context.Context, requests []*rela
panic("implement me")
}
func (g *GroupDataBase) GetGroupRecvApplicationList(ctx context.Context, userID string) ([]*relation2.GroupRequestModel, error) {
func (g *GroupDataBase) TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relation2.GroupRequestModel, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupDataBase) TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relation2.GroupRequestModel, error) {
func (g *GroupDataBase) PageGroupRequestUser(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupRequestModel, error) {
//TODO implement me
panic("implement me")
}
func (g *GroupDataBase) FindUserGroupRequest(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupRequestModel, error) {
func (g *GroupDataBase) TakeSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation2.SuperGroupModel, err error) {
//TODO implement me
panic("implement me")
}
func (g *GroupDataBase) TakeSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation2.SuperGroupModel, err error) {
func (g *GroupDataBase) FindJoinSuperGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (total int32, groupIDs []string, err error) {
//TODO implement me
panic("implement me")
}
@ -554,12 +427,7 @@ func (g *GroupDataBase) DeleteSuperGroupMember(ctx context.Context, groupID stri
panic("implement me")
}
func (g *GroupDataBase) AddUserToSuperGroup(ctx context.Context, groupID string, userIDs []string) error {
//TODO implement me
panic("implement me")
}
func (g *GroupDataBase) FindJoinSuperGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (total int32, groupIDs []string, err error) {
func (g *GroupDataBase) CreateSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error {
//TODO implement me
panic("implement me")
}

@ -144,6 +144,16 @@ 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))
for i := 0; i < len(es); i++ {
if e := es[i]; fn(e) {
rs = append(rs, e)
}
}
return rs
}
// Slice 批量转换切片类型
func Slice[E any, T any](es []E, fn func(e E) T) []T {
v := make([]T, len(es))

Loading…
Cancel
Save