|
|
@ -7,7 +7,9 @@ import (
|
|
|
|
relation2 "Open_IM/pkg/common/db/table/relation"
|
|
|
|
relation2 "Open_IM/pkg/common/db/table/relation"
|
|
|
|
unrelation2 "Open_IM/pkg/common/db/table/unrelation"
|
|
|
|
unrelation2 "Open_IM/pkg/common/db/table/unrelation"
|
|
|
|
"Open_IM/pkg/common/db/unrelation"
|
|
|
|
"Open_IM/pkg/common/db/unrelation"
|
|
|
|
|
|
|
|
"Open_IM/pkg/utils"
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"github.com/dtm-labs/rockscache"
|
|
|
|
"github.com/dtm-labs/rockscache"
|
|
|
|
_ "github.com/dtm-labs/rockscache"
|
|
|
|
_ "github.com/dtm-labs/rockscache"
|
|
|
|
"github.com/go-redis/redis/v8"
|
|
|
|
"github.com/go-redis/redis/v8"
|
|
|
@ -15,47 +17,154 @@ import (
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type GroupInterface GroupDataBaseInterface
|
|
|
|
//type GroupInterface GroupDataBaseInterface
|
|
|
|
|
|
|
|
|
|
|
|
//type GroupInterface interface {
|
|
|
|
type GroupInterface interface {
|
|
|
|
// // Group
|
|
|
|
CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMembers []*relation2.GroupMemberModel) error
|
|
|
|
// CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMembers []*relation2.GroupMemberModel) error
|
|
|
|
TakeGroup(ctx context.Context, groupID string) (group *relation2.GroupModel, err error)
|
|
|
|
// TakeGroup(ctx context.Context, groupID string) (group *relation2.GroupModel, err error)
|
|
|
|
FindGroup(ctx context.Context, groupIDs []string) (groups []*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)
|
|
|
|
// SearchGroup(ctx context.Context, keyword string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error)
|
|
|
|
UpdateGroup(ctx context.Context, groupID string, data map[string]any) error
|
|
|
|
// UpdateGroup(ctx context.Context, groupID string, data map[string]any) error
|
|
|
|
DismissGroup(ctx context.Context, groupID string) error // 解散群,并删除群成员
|
|
|
|
// DismissGroup(ctx context.Context, groupID string) error // 解散群,并删除群成员
|
|
|
|
// GroupMember
|
|
|
|
// // GroupMember
|
|
|
|
TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupMemberModel, err error)
|
|
|
|
// TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupMemberModel, err error)
|
|
|
|
TakeGroupOwner(ctx context.Context, groupID string) (*relation2.GroupMemberModel, error)
|
|
|
|
// TakeGroupOwner(ctx context.Context, groupID string) (*relation2.GroupMemberModel, error)
|
|
|
|
FindGroupMember(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32) ([]*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)
|
|
|
|
// PageGroupMember(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error)
|
|
|
|
SearchGroupMember(ctx context.Context, keyword string, 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
|
|
|
|
// 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
|
|
|
|
// DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
|
|
|
MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string][]string, error)
|
|
|
|
// MapGroupHash(ctx context.Context, groupIDs []string) (map[string]uint64, error)
|
|
|
|
MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error)
|
|
|
|
// MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error)
|
|
|
|
TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string, roleLevel int32) error // 转让群
|
|
|
|
// TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string) error // 转让群
|
|
|
|
UpdateGroupMember(ctx context.Context, groupID, userID string, data map[string]any) error
|
|
|
|
// UpdateGroupMember(ctx context.Context, groupID, userID string, data map[string]any) error
|
|
|
|
// GroupRequest
|
|
|
|
// // GroupRequest
|
|
|
|
CreateGroupRequest(ctx context.Context, requests []*relation2.GroupRequestModel) error
|
|
|
|
// CreateGroupRequest(ctx context.Context, requests []*relation2.GroupRequestModel) error
|
|
|
|
TakeGroupRequest(ctx context.Context, groupID string, userID string) (*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)
|
|
|
|
// PageGroupRequestUser(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupRequestModel, error)
|
|
|
|
// SuperGroup
|
|
|
|
// // SuperGroup
|
|
|
|
TakeSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation2.SuperGroupModel, err error)
|
|
|
|
// 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)
|
|
|
|
// FindJoinSuperGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (total int32, groupIDs []string, err error)
|
|
|
|
CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error
|
|
|
|
// CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error
|
|
|
|
DeleteSuperGroup(ctx context.Context, groupID string) error
|
|
|
|
// DeleteSuperGroup(ctx context.Context, groupID string) error
|
|
|
|
DeleteSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
|
|
|
// DeleteSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
|
|
|
CreateSuperGroupMember(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)
|
|
|
|
// MapSuperGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error)
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
//
|
|
|
|
var _ GroupInterface = (*GroupController)(nil)
|
|
|
|
//var _ GroupInterface = (*GroupController)(nil)
|
|
|
|
|
|
|
|
//
|
|
|
|
type GroupController struct {
|
|
|
|
//type GroupController struct {
|
|
|
|
database GroupDataBaseInterface
|
|
|
|
// database GroupDataBaseInterface
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMembers []*relation2.GroupMemberModel) error {
|
|
|
|
|
|
|
|
return g.database.CreateGroup(ctx, groups, groupMembers)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) TakeGroup(ctx context.Context, groupID string) (group *relation2.GroupModel, err error) {
|
|
|
|
|
|
|
|
return g.TakeGroup(ctx, groupID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) FindGroup(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error) {
|
|
|
|
|
|
|
|
return g.database.FindGroup(ctx, groupIDs)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) SearchGroup(ctx context.Context, keyword string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error) {
|
|
|
|
|
|
|
|
return g.database.SearchGroup(ctx, keyword, pageNumber, showNumber)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) UpdateGroup(ctx context.Context, groupID string, data map[string]any) error {
|
|
|
|
|
|
|
|
return g.database.UpdateGroup(ctx, groupID, data)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) DismissGroup(ctx context.Context, groupID string) error {
|
|
|
|
|
|
|
|
return g.database.DismissGroup(ctx, groupID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupMemberModel, err error) {
|
|
|
|
|
|
|
|
return g.database.TakeGroupMember(ctx, groupID, userID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) TakeGroupOwner(ctx context.Context, groupID string) (*relation2.GroupMemberModel, error) {
|
|
|
|
|
|
|
|
return g.database.TakeGroupOwner(ctx, groupID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) FindGroupMember(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32) ([]*relation2.GroupMemberModel, error) {
|
|
|
|
|
|
|
|
return g.database.FindGroupMember(ctx, groupIDs, userIDs, roleLevels)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) PageGroupMember(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error) {
|
|
|
|
|
|
|
|
return g.database.PageGroupMember(ctx, groupIDs, userIDs, roleLevels, pageNumber, showNumber)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) SearchGroupMember(ctx context.Context, keyword string, groupIDs []string, userIDs []string, roleLevels []int32, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error) {
|
|
|
|
|
|
|
|
return g.database.SearchGroupMember(ctx, keyword, groupIDs, userIDs, roleLevels, pageNumber, showNumber)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relation2.GroupMemberModel) error {
|
|
|
|
|
|
|
|
return g.database.HandlerGroupRequest(ctx, groupID, userID, handledMsg, handleResult, member)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
|
|
|
|
|
|
|
return g.database.DeleteGroupMember(ctx, groupID, userIDs)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string][]string, error) {
|
|
|
|
|
|
|
|
return g.database.MapGroupMemberUserID(ctx, groupIDs)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error) {
|
|
|
|
|
|
|
|
return g.database.MapGroupMemberNum(ctx, groupIDs)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string, roleLevel int32) error {
|
|
|
|
|
|
|
|
return g.database.TransferGroupOwner(ctx, groupID, oldOwnerUserID, newOwnerUserID, roleLevel)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) UpdateGroupMember(ctx context.Context, groupID, userID string, data map[string]any) error {
|
|
|
|
|
|
|
|
return g.database.UpdateGroupMember(ctx, groupID, userID, data)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) CreateGroupRequest(ctx context.Context, requests []*relation2.GroupRequestModel) error {
|
|
|
|
|
|
|
|
return g.database.CreateGroupRequest(ctx, requests)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relation2.GroupRequestModel, error) {
|
|
|
|
|
|
|
|
return g.database.TakeGroupRequest(ctx, groupID, userID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) PageGroupRequestUser(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupRequestModel, error) {
|
|
|
|
|
|
|
|
return g.database.PageGroupRequestUser(ctx, userID, pageNumber, showNumber)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) TakeSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation2.SuperGroupModel, err error) {
|
|
|
|
|
|
|
|
return g.database.TakeSuperGroup(ctx, groupID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) FindJoinSuperGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (total int32, groupIDs []string, err error) {
|
|
|
|
|
|
|
|
return g.database.FindJoinSuperGroup(ctx, userID, pageNumber, showNumber)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error {
|
|
|
|
|
|
|
|
return g.database.CreateSuperGroup(ctx, groupID, initMemberIDList)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) DeleteSuperGroup(ctx context.Context, groupID string) error {
|
|
|
|
|
|
|
|
return g.database.DeleteSuperGroup(ctx, groupID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) DeleteSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
|
|
|
|
|
|
|
return g.database.DeleteSuperGroupMember(ctx, groupID, userIDs)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) CreateSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
|
|
|
|
|
|
|
return g.database.CreateSuperGroupMember(ctx, groupID, userIDs)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupController) MapSuperGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error) {
|
|
|
|
|
|
|
|
return g.database.MapSuperGroupMemberNum(ctx, groupIDs)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type GroupDataBaseInterface interface {
|
|
|
|
type GroupDataBaseInterface interface {
|
|
|
|
CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMembers []*relation2.GroupMemberModel) error
|
|
|
|
CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMembers []*relation2.GroupMemberModel) error
|
|
|
@ -72,9 +181,9 @@ type GroupDataBaseInterface interface {
|
|
|
|
SearchGroupMember(ctx context.Context, keyword string, groupIDs []string, userIDs []string, roleLevels []int32, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error)
|
|
|
|
SearchGroupMember(ctx context.Context, keyword 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
|
|
|
|
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
|
|
|
|
DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
|
|
|
MapGroupHash(ctx context.Context, groupIDs []string) (map[string]uint64, error)
|
|
|
|
MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string][]string, error)
|
|
|
|
MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error)
|
|
|
|
MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error)
|
|
|
|
TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string) error // 转让群
|
|
|
|
TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string, roleLevel int32) error // 转让群
|
|
|
|
UpdateGroupMember(ctx context.Context, groupID, userID string, data map[string]any) error
|
|
|
|
UpdateGroupMember(ctx context.Context, groupID, userID string, data map[string]any) error
|
|
|
|
// GroupRequest
|
|
|
|
// GroupRequest
|
|
|
|
CreateGroupRequest(ctx context.Context, requests []*relation2.GroupRequestModel) error
|
|
|
|
CreateGroupRequest(ctx context.Context, requests []*relation2.GroupRequestModel) error
|
|
|
@ -112,154 +221,6 @@ func newGroupDatabase(db *gorm.DB, rdb redis.UniversalClient, mgoClient *mongo.C
|
|
|
|
return database
|
|
|
|
return database
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//func (g *GroupDataBase) DeleteGroupByIDs(ctx context.Context, groupIDs []string) error {
|
|
|
|
|
|
|
|
// return g.groupDB.DB.Transaction(func(tx *gorm.DB) error {
|
|
|
|
|
|
|
|
// if err := g.groupDB.Delete(ctx, groupIDs, tx); err != nil {
|
|
|
|
|
|
|
|
// return err
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if err := g.cache.DelGroupsInfo(ctx, groupIDs); err != nil {
|
|
|
|
|
|
|
|
// return err
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return nil
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//func (g *GroupDataBase) TakeGroupByID(ctx context.Context, groupID string) (group *relation2.GroupModel, err error) {
|
|
|
|
|
|
|
|
// return g.cache.GetGroupInfo(ctx, groupID)
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//func (g *GroupDataBase) Update(ctx context.Context, groups []*relation2.GroupModel) error {
|
|
|
|
|
|
|
|
// return g.db.Transaction(func(tx *gorm.DB) error {
|
|
|
|
|
|
|
|
// if err := g.groupDB.Update(ctx, groups, tx); err != nil {
|
|
|
|
|
|
|
|
// return err
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// var groupIDs []string
|
|
|
|
|
|
|
|
// for _, group := range groups {
|
|
|
|
|
|
|
|
// groupIDs = append(groupIDs, group.GroupID)
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if err := g.cache.DelGroupsInfo(ctx, groupIDs); err != nil {
|
|
|
|
|
|
|
|
// return err
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return nil
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//func (g *GroupDataBase) GetJoinedGroupList(ctx context.Context, userID string) ([]*relation2.GroupModel, error) {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// return nil, nil
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//func (g *GroupDataBase) CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error {
|
|
|
|
|
|
|
|
// sess, err := g.mongoDB.MgoClient.StartSession()
|
|
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
|
|
|
// return err
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// defer sess.EndSession(ctx)
|
|
|
|
|
|
|
|
// sCtx := mongo.NewSessionContext(ctx, sess)
|
|
|
|
|
|
|
|
// if err = g.mongoDB.CreateSuperGroup(sCtx, groupID, initMemberIDList); err != nil {
|
|
|
|
|
|
|
|
// _ = sess.AbortTransaction(ctx)
|
|
|
|
|
|
|
|
// return err
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if err = g.cache.BatchDelJoinedSuperGroupIDs(ctx, initMemberIDList); err != nil {
|
|
|
|
|
|
|
|
// _ = sess.AbortTransaction(ctx)
|
|
|
|
|
|
|
|
// return err
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return sess.CommitTransaction(ctx)
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//func (g *GroupDataBase) GetSuperGroupByID(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error) {
|
|
|
|
|
|
|
|
// 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) 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})
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var _ GroupDataBaseInterface = (*GroupDataBase)(nil)
|
|
|
|
var _ GroupDataBaseInterface = (*GroupDataBase)(nil)
|
|
|
|
|
|
|
|
|
|
|
|
type GroupDataBase struct {
|
|
|
|
type GroupDataBase struct {
|
|
|
@ -336,81 +297,108 @@ func (g *GroupDataBase) SearchGroupMember(ctx context.Context, keyword string, g
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupDataBase) HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relation2.GroupMemberModel) error {
|
|
|
|
func (g *GroupDataBase) HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relation2.GroupMemberModel) error {
|
|
|
|
//TODO implement me
|
|
|
|
if member == nil {
|
|
|
|
panic("implement me")
|
|
|
|
return g.groupRequestDB.UpdateHandler(ctx, groupID, userID, handledMsg, handleResult)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return g.db.Transaction(func(tx *gorm.DB) error {
|
|
|
|
|
|
|
|
if err := g.groupRequestDB.UpdateHandler(ctx, groupID, userID, handledMsg, handleResult, tx); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return g.groupMemberDB.Create(ctx, []*relation2.GroupMemberModel{member}, tx)
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupDataBase) DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
|
|
|
func (g *GroupDataBase) DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
|
|
|
//TODO implement me
|
|
|
|
return g.groupMemberDB.Delete(ctx, groupID, userIDs)
|
|
|
|
panic("implement me")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupDataBase) MapGroupHash(ctx context.Context, groupIDs []string) (map[string]uint64, error) {
|
|
|
|
func (g *GroupDataBase) MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string][]string, error) {
|
|
|
|
//TODO implement me
|
|
|
|
return g.groupMemberDB.FindJoinUserID(ctx, groupIDs)
|
|
|
|
panic("implement me")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupDataBase) MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error) {
|
|
|
|
func (g *GroupDataBase) MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error) {
|
|
|
|
//TODO implement me
|
|
|
|
return g.groupMemberDB.MapGroupMemberNum(ctx, groupIDs)
|
|
|
|
panic("implement me")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupDataBase) TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string) error {
|
|
|
|
func (g *GroupDataBase) TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string, roleLevel int32) error {
|
|
|
|
//TODO implement me
|
|
|
|
return g.db.Transaction(func(tx *gorm.DB) error {
|
|
|
|
panic("implement me")
|
|
|
|
rowsAffected, err := g.groupMemberDB.UpdateRoleLevel(ctx, groupID, oldOwnerUserID, roleLevel, tx)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if rowsAffected != 1 {
|
|
|
|
|
|
|
|
return utils.Wrap(fmt.Errorf("oldOwnerUserID %s rowsAffected = %d", oldOwnerUserID, rowsAffected), "")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
rowsAffected, err = g.groupMemberDB.UpdateRoleLevel(ctx, groupID, newOwnerUserID, constant.GroupOwner, tx)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if rowsAffected != 1 {
|
|
|
|
|
|
|
|
return utils.Wrap(fmt.Errorf("newOwnerUserID %s rowsAffected = %d", newOwnerUserID, rowsAffected), "")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupDataBase) UpdateGroupMember(ctx context.Context, groupID, userID string, data map[string]any) error {
|
|
|
|
func (g *GroupDataBase) UpdateGroupMember(ctx context.Context, groupID, userID string, data map[string]any) error {
|
|
|
|
//TODO implement me
|
|
|
|
return g.groupMemberDB.Update(ctx, groupID, userID, data)
|
|
|
|
panic("implement me")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupDataBase) CreateGroupRequest(ctx context.Context, requests []*relation2.GroupRequestModel) error {
|
|
|
|
func (g *GroupDataBase) CreateGroupRequest(ctx context.Context, requests []*relation2.GroupRequestModel) error {
|
|
|
|
//TODO implement me
|
|
|
|
return g.groupRequestDB.Create(ctx, requests)
|
|
|
|
panic("implement me")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupDataBase) TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relation2.GroupRequestModel, error) {
|
|
|
|
func (g *GroupDataBase) TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relation2.GroupRequestModel, error) {
|
|
|
|
//TODO implement me
|
|
|
|
return g.groupRequestDB.Take(ctx, groupID, userID)
|
|
|
|
panic("implement me")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupDataBase) PageGroupRequestUser(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupRequestModel, error) {
|
|
|
|
func (g *GroupDataBase) PageGroupRequestUser(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupRequestModel, error) {
|
|
|
|
//TODO implement me
|
|
|
|
return g.groupRequestDB.Page(ctx, userID, pageNumber, showNumber)
|
|
|
|
panic("implement me")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupDataBase) TakeSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation2.SuperGroupModel, err error) {
|
|
|
|
func (g *GroupDataBase) TakeSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation2.SuperGroupModel, err error) {
|
|
|
|
//TODO implement me
|
|
|
|
return g.mongoDB.GetSuperGroup(ctx, groupID)
|
|
|
|
panic("implement me")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupDataBase) FindJoinSuperGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (total int32, groupIDs []string, err error) {
|
|
|
|
func (g *GroupDataBase) FindJoinSuperGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (total int32, groupIDs []string, err error) {
|
|
|
|
//TODO implement me
|
|
|
|
return g.mongoDB.GetJoinGroup(ctx, userID, pageNumber, showNumber)
|
|
|
|
panic("implement me")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupDataBase) CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error {
|
|
|
|
func (g *GroupDataBase) CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error {
|
|
|
|
//TODO implement me
|
|
|
|
return MongoTransaction(ctx, g.mongoDB.MgoClient, func(ctx mongo.SessionContext) error {
|
|
|
|
panic("implement me")
|
|
|
|
if err := g.mongoDB.CreateSuperGroup(ctx, groupID, initMemberIDList); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return g.cache.BatchDelJoinedSuperGroupIDs(ctx, initMemberIDList)
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupDataBase) DeleteSuperGroup(ctx context.Context, groupID string) error {
|
|
|
|
func (g *GroupDataBase) DeleteSuperGroup(ctx context.Context, groupID string) error {
|
|
|
|
//TODO implement me
|
|
|
|
return g.mongoDB.DeleteSuperGroup(ctx, groupID)
|
|
|
|
panic("implement me")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupDataBase) DeleteSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
|
|
|
func (g *GroupDataBase) DeleteSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
|
|
|
//TODO implement me
|
|
|
|
return g.mongoDB.RemoverUserFromSuperGroup(ctx, groupID, userIDs)
|
|
|
|
panic("implement me")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupDataBase) CreateSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
|
|
|
func (g *GroupDataBase) CreateSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
|
|
|
//TODO implement me
|
|
|
|
return g.mongoDB.AddUserToSuperGroup(ctx, groupID, userIDs)
|
|
|
|
panic("implement me")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *GroupDataBase) MapSuperGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error) {
|
|
|
|
func (g *GroupDataBase) MapSuperGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error) {
|
|
|
|
//TODO implement me
|
|
|
|
return g.mongoDB.MapGroupMemberCount(ctx, groupIDs)
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func MongoTransaction(ctx context.Context, mgo *mongo.Client, fn func(ctx mongo.SessionContext) error) error {
|
|
|
|
|
|
|
|
sess, err := mgo.StartSession()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sCtx := mongo.NewSessionContext(ctx, sess)
|
|
|
|
|
|
|
|
defer sess.EndSession(sCtx)
|
|
|
|
|
|
|
|
if err := fn(sCtx); err != nil {
|
|
|
|
|
|
|
|
_ = sess.AbortTransaction(sCtx)
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return utils.Wrap(sess.CommitTransaction(sCtx), "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|