mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-03 19:02:31 +08:00
group
This commit is contained in:
parent
358f70895d
commit
d99e3d93e3
@ -20,6 +20,8 @@ import (
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/OpenIMSDK/tools/tx"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/newmgo"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
@ -73,11 +75,23 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
groupDB, err := newmgo.NewGroupMongo(mongo.GetDatabase())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
groupMemberDB, err := newmgo.NewGroupMember(mongo.GetDatabase())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
groupRequestDB, err := newmgo.NewGroupRequestMgo(mongo.GetDatabase())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
userRpcClient := rpcclient.NewUserRpcClient(client)
|
||||
msgRpcClient := rpcclient.NewMessageRpcClient(client)
|
||||
conversationRpcClient := rpcclient.NewConversationRpcClient(client)
|
||||
var gs groupServer
|
||||
database := controller.InitGroupDatabase(db, rdb, mongo.GetDatabase(), gs.groupMemberHashCode)
|
||||
database := controller.NewGroupDatabase(rdb, groupDB, groupMemberDB, groupRequestDB, tx.NewMongo(mongo.GetClient()), gs.groupMemberHashCode)
|
||||
gs.GroupDatabase = database
|
||||
gs.User = userRpcClient
|
||||
gs.Notification = notification.NewGroupNotificationSender(database, &msgRpcClient, &userRpcClient, func(ctx context.Context, userIDs []string) ([]notification.CommonUser, error) {
|
||||
|
||||
164
pkg/common/db/cache/group.go
vendored
164
pkg/common/db/cache/group.go
vendored
@ -26,19 +26,16 @@ import (
|
||||
"github.com/OpenIMSDK/tools/utils"
|
||||
|
||||
relationtb "github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||
unrelationtb "github.com/openimsdk/open-im-server/v3/pkg/common/db/table/unrelation"
|
||||
)
|
||||
|
||||
const (
|
||||
groupExpireTime = time.Second * 60 * 60 * 12
|
||||
groupInfoKey = "GROUP_INFO:"
|
||||
groupMemberIDsKey = "GROUP_MEMBER_IDS:"
|
||||
groupMembersHashKey = "GROUP_MEMBERS_HASH2:"
|
||||
groupMemberInfoKey = "GROUP_MEMBER_INFO:"
|
||||
joinedSuperGroupsKey = "JOIN_SUPER_GROUPS:"
|
||||
SuperGroupMemberIDsKey = "SUPER_GROUP_MEMBER_IDS:"
|
||||
joinedGroupsKey = "JOIN_GROUPS_KEY:"
|
||||
groupMemberNumKey = "GROUP_MEMBER_NUM_CACHE:"
|
||||
groupExpireTime = time.Second * 60 * 60 * 12
|
||||
groupInfoKey = "GROUP_INFO:"
|
||||
groupMemberIDsKey = "GROUP_MEMBER_IDS:"
|
||||
groupMembersHashKey = "GROUP_MEMBERS_HASH2:"
|
||||
groupMemberInfoKey = "GROUP_MEMBER_INFO:"
|
||||
joinedGroupsKey = "JOIN_GROUPS_KEY:"
|
||||
groupMemberNumKey = "GROUP_MEMBER_NUM_CACHE:"
|
||||
)
|
||||
|
||||
type GroupCache interface {
|
||||
@ -48,11 +45,6 @@ type GroupCache interface {
|
||||
GetGroupInfo(ctx context.Context, groupID string) (group *relationtb.GroupModel, err error)
|
||||
DelGroupsInfo(groupIDs ...string) GroupCache
|
||||
|
||||
GetJoinedSuperGroupIDs(ctx context.Context, userID string) (joinedSuperGroupIDs []string, err error)
|
||||
DelJoinedSuperGroupIDs(userIDs ...string) GroupCache
|
||||
GetSuperGroupMemberIDs(ctx context.Context, groupIDs ...string) (models []*unrelationtb.SuperGroupModel, err error)
|
||||
DelSuperGroupMemberIDs(groupIDs ...string) GroupCache
|
||||
|
||||
GetGroupMembersHash(ctx context.Context, groupID string) (hashCode uint64, err error)
|
||||
GetGroupMemberHashMap(ctx context.Context, groupIDs []string) (map[string]*relationtb.GroupSimpleUserID, error)
|
||||
DelGroupMembersHash(groupID string) GroupCache
|
||||
@ -81,7 +73,6 @@ type GroupCacheRedis struct {
|
||||
groupDB relationtb.GroupModelInterface
|
||||
groupMemberDB relationtb.GroupMemberModelInterface
|
||||
groupRequestDB relationtb.GroupRequestModelInterface
|
||||
mongoDB unrelationtb.SuperGroupModelInterface
|
||||
expireTime time.Duration
|
||||
rcClient *rockscache.Client
|
||||
hashCode func(ctx context.Context, groupID string) (uint64, error)
|
||||
@ -92,7 +83,6 @@ func NewGroupCacheRedis(
|
||||
groupDB relationtb.GroupModelInterface,
|
||||
groupMemberDB relationtb.GroupMemberModelInterface,
|
||||
groupRequestDB relationtb.GroupRequestModelInterface,
|
||||
mongoClient unrelationtb.SuperGroupModelInterface,
|
||||
hashCode func(ctx context.Context, groupID string) (uint64, error),
|
||||
opts rockscache.Options,
|
||||
) GroupCache {
|
||||
@ -101,7 +91,6 @@ func NewGroupCacheRedis(
|
||||
return &GroupCacheRedis{
|
||||
rcClient: rcClient, expireTime: groupExpireTime,
|
||||
groupDB: groupDB, groupMemberDB: groupMemberDB, groupRequestDB: groupRequestDB,
|
||||
mongoDB: mongoClient,
|
||||
hashCode: hashCode,
|
||||
metaCache: NewMetaCacheRedis(rcClient),
|
||||
}
|
||||
@ -114,7 +103,6 @@ func (g *GroupCacheRedis) NewCache() GroupCache {
|
||||
groupDB: g.groupDB,
|
||||
groupMemberDB: g.groupMemberDB,
|
||||
groupRequestDB: g.groupRequestDB,
|
||||
mongoDB: g.mongoDB,
|
||||
metaCache: NewMetaCacheRedis(g.rcClient, g.metaCache.GetPreDelKeys()...),
|
||||
}
|
||||
}
|
||||
@ -123,18 +111,10 @@ func (g *GroupCacheRedis) getGroupInfoKey(groupID string) string {
|
||||
return groupInfoKey + groupID
|
||||
}
|
||||
|
||||
func (g *GroupCacheRedis) getJoinedSuperGroupsIDKey(userID string) string {
|
||||
return joinedSuperGroupsKey + userID
|
||||
}
|
||||
|
||||
func (g *GroupCacheRedis) getJoinedGroupsKey(userID string) string {
|
||||
return joinedGroupsKey + userID
|
||||
}
|
||||
|
||||
func (g *GroupCacheRedis) getSuperGroupMemberIDsKey(groupID string) string {
|
||||
return SuperGroupMemberIDsKey + groupID
|
||||
}
|
||||
|
||||
func (g *GroupCacheRedis) getGroupMembersHashKey(groupID string) string {
|
||||
return groupMembersHashKey + groupID
|
||||
}
|
||||
@ -175,13 +155,6 @@ func (g *GroupCacheRedis) GetGroupMemberIndex(groupMember *relationtb.GroupMembe
|
||||
|
||||
// / groupInfo.
|
||||
func (g *GroupCacheRedis) GetGroupsInfo(ctx context.Context, groupIDs []string) (groups []*relationtb.GroupModel, err error) {
|
||||
//var keys []string
|
||||
//for _, group := range groupIDs {
|
||||
// keys = append(keys, g.getGroupInfoKey(group))
|
||||
//}
|
||||
//return batchGetCache(ctx, g.rcClient, keys, g.expireTime, g.GetGroupIndex, func(ctx context.Context) ([]*relationtb.GroupModel, error) {
|
||||
// return g.groupDB.Find(ctx, groupIDs)
|
||||
//})
|
||||
return batchGetCache2(ctx, g.rcClient, g.expireTime, groupIDs, func(groupID string) string {
|
||||
return g.getGroupInfoKey(groupID)
|
||||
}, func(ctx context.Context, groupID string) (*relationtb.GroupModel, error) {
|
||||
@ -206,120 +179,11 @@ func (g *GroupCacheRedis) DelGroupsInfo(groupIDs ...string) GroupCache {
|
||||
return newGroupCache
|
||||
}
|
||||
|
||||
func (g *GroupCacheRedis) GetJoinedSuperGroupIDs(ctx context.Context, userID string) (joinedSuperGroupIDs []string, err error) {
|
||||
return getCache(ctx, g.rcClient, g.getJoinedSuperGroupsIDKey(userID), g.expireTime, func(ctx context.Context) ([]string, error) {
|
||||
userGroup, err := g.mongoDB.GetSuperGroupByUserID(ctx, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return userGroup.GroupIDs, nil
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (g *GroupCacheRedis) GetSuperGroupMemberIDs(ctx context.Context, groupIDs ...string) (models []*unrelationtb.SuperGroupModel, err error) {
|
||||
//var keys []string
|
||||
//for _, group := range groupIDs {
|
||||
// keys = append(keys, g.getSuperGroupMemberIDsKey(group))
|
||||
//}
|
||||
//return batchGetCache(ctx, g.rcClient, keys, g.expireTime, func(model *unrelationtb.SuperGroupModel, keys []string) (int, error) {
|
||||
// for i, key := range keys {
|
||||
// if g.getSuperGroupMemberIDsKey(model.GroupID) == key {
|
||||
// return i, nil
|
||||
// }
|
||||
// }
|
||||
// return 0, errIndex
|
||||
//},
|
||||
// func(ctx context.Context) ([]*unrelationtb.SuperGroupModel, error) {
|
||||
// return g.mongoDB.FindSuperGroup(ctx, groupIDs)
|
||||
// })
|
||||
return batchGetCache2(ctx, g.rcClient, g.expireTime, groupIDs, func(groupID string) string {
|
||||
return g.getSuperGroupMemberIDsKey(groupID)
|
||||
}, func(ctx context.Context, groupID string) (*unrelationtb.SuperGroupModel, error) {
|
||||
return g.mongoDB.TakeSuperGroup(ctx, groupID)
|
||||
})
|
||||
}
|
||||
|
||||
// userJoinSuperGroup.
|
||||
func (g *GroupCacheRedis) DelJoinedSuperGroupIDs(userIDs ...string) GroupCache {
|
||||
newGroupCache := g.NewCache()
|
||||
keys := make([]string, 0, len(userIDs))
|
||||
for _, userID := range userIDs {
|
||||
keys = append(keys, g.getJoinedSuperGroupsIDKey(userID))
|
||||
}
|
||||
newGroupCache.AddKeys(keys...)
|
||||
|
||||
return newGroupCache
|
||||
}
|
||||
|
||||
func (g *GroupCacheRedis) DelSuperGroupMemberIDs(groupIDs ...string) GroupCache {
|
||||
newGroupCache := g.NewCache()
|
||||
keys := make([]string, 0, len(groupIDs))
|
||||
for _, groupID := range groupIDs {
|
||||
keys = append(keys, g.getSuperGroupMemberIDsKey(groupID))
|
||||
}
|
||||
newGroupCache.AddKeys(keys...)
|
||||
|
||||
return newGroupCache
|
||||
}
|
||||
|
||||
// groupMembersHash.
|
||||
func (g *GroupCacheRedis) GetGroupMembersHash(ctx context.Context, groupID string) (hashCode uint64, err error) {
|
||||
return getCache(ctx, g.rcClient, g.getGroupMembersHashKey(groupID), g.expireTime, func(ctx context.Context) (uint64, error) {
|
||||
return g.hashCode(ctx, groupID)
|
||||
})
|
||||
|
||||
//return getCache(ctx, g.rcClient, g.getGroupMembersHashKey(groupID), g.expireTime,
|
||||
// func(ctx context.Context) (uint64, error) {
|
||||
// userIDs, err := g.GetGroupMemberIDs(ctx, groupID)
|
||||
// if err != nil {
|
||||
// return 0, err
|
||||
// }
|
||||
// log.ZInfo(ctx, "GetGroupMembersHash", "groupID", groupID, "userIDs", userIDs)
|
||||
// var members []*relationtb.GroupMemberModel
|
||||
// if len(userIDs) > 0 {
|
||||
// members, err = g.GetGroupMembersInfo(ctx, groupID, userIDs)
|
||||
// if err != nil {
|
||||
// return 0, err
|
||||
// }
|
||||
// utils.Sort(userIDs, true)
|
||||
// }
|
||||
// memberMap := make(map[string]*relationtb.GroupMemberModel)
|
||||
// for i, member := range members {
|
||||
// memberMap[member.UserID] = members[i]
|
||||
// }
|
||||
// data := make([]string, 0, len(members)*11)
|
||||
// for _, userID := range userIDs {
|
||||
// member, ok := memberMap[userID]
|
||||
// if !ok {
|
||||
// continue
|
||||
// }
|
||||
// data = append(data,
|
||||
// member.GroupID,
|
||||
// member.UserID,
|
||||
// member.Nickname,
|
||||
// member.FaceURL,
|
||||
// strconv.Itoa(int(member.RoleLevel)),
|
||||
// strconv.FormatInt(member.JoinTime.UnixMilli(), 10),
|
||||
// strconv.Itoa(int(member.JoinSource)),
|
||||
// member.InviterUserID,
|
||||
// member.OperatorUserID,
|
||||
// strconv.FormatInt(member.MuteEndTime.UnixMilli(), 10),
|
||||
// member.Ex,
|
||||
// )
|
||||
// }
|
||||
// log.ZInfo(ctx, "hash data info", "userIDs.len", len(userIDs), "hash.data.len", len(data))
|
||||
// log.ZInfo(ctx, "json hash data", "groupID", groupID, "data", data)
|
||||
// val, err := json.Marshal(data)
|
||||
// if err != nil {
|
||||
// return 0, err
|
||||
// }
|
||||
// sum := md5.Sum(val)
|
||||
// code := binary.BigEndian.Uint64(sum[:])
|
||||
// log.ZInfo(ctx, "GetGroupMembersHash", "groupID", groupID, "hashCode", code, "num", len(members))
|
||||
// return code, nil
|
||||
// },
|
||||
//)
|
||||
}
|
||||
|
||||
func (g *GroupCacheRedis) GetGroupMemberHashMap(ctx context.Context, groupIDs []string) (map[string]*relationtb.GroupSimpleUserID, error) {
|
||||
@ -398,13 +262,6 @@ func (g *GroupCacheRedis) GetGroupMemberInfo(ctx context.Context, groupID, userI
|
||||
}
|
||||
|
||||
func (g *GroupCacheRedis) GetGroupMembersInfo(ctx context.Context, groupID string, userIDs []string) ([]*relationtb.GroupMemberModel, error) {
|
||||
//var keys []string
|
||||
//for _, userID := range userIDs {
|
||||
// keys = append(keys, g.getGroupMemberInfoKey(groupID, userID))
|
||||
//}
|
||||
//return batchGetCache(ctx, g.rcClient, keys, g.expireTime, g.GetGroupMemberIndex, func(ctx context.Context) ([]*relationtb.GroupMemberModel, error) {
|
||||
// return g.groupMemberDB.Find(ctx, []string{groupID}, userIDs, nil)
|
||||
//})
|
||||
return batchGetCache2(ctx, g.rcClient, g.expireTime, userIDs, func(userID string) string {
|
||||
return g.getGroupMemberInfoKey(groupID, userID)
|
||||
}, func(ctx context.Context, userID string) (*relationtb.GroupMemberModel, error) {
|
||||
@ -446,13 +303,6 @@ func (g *GroupCacheRedis) GetAllGroupMemberInfo(ctx context.Context, groupID str
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//var keys []string
|
||||
//for _, groupMemberID := range groupMemberIDs {
|
||||
// keys = append(keys, g.getGroupMemberInfoKey(groupID, groupMemberID))
|
||||
//}
|
||||
//return batchGetCache(ctx, g.rcClient, keys, g.expireTime, g.GetGroupMemberIndex, func(ctx context.Context) ([]*relationtb.GroupMemberModel, error) {
|
||||
// return g.groupMemberDB.Find(ctx, []string{groupID}, groupMemberIDs, nil)
|
||||
//})
|
||||
return g.GetGroupMembersInfo(ctx, groupID, groupMemberIDs)
|
||||
}
|
||||
|
||||
|
||||
@ -17,22 +17,17 @@ package controller
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/dtm-labs/rockscache"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"gorm.io/gorm"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/pagination"
|
||||
"time"
|
||||
|
||||
"github.com/OpenIMSDK/protocol/constant"
|
||||
"github.com/OpenIMSDK/tools/tx"
|
||||
"github.com/OpenIMSDK/tools/utils"
|
||||
"github.com/redis/go-redis/v9"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/relation"
|
||||
relationtb "github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||
unrelationtb "github.com/openimsdk/open-im-server/v3/pkg/common/db/table/unrelation"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/unrelation"
|
||||
)
|
||||
|
||||
type GroupDatabase interface {
|
||||
@ -40,11 +35,11 @@ type GroupDatabase interface {
|
||||
CreateGroup(ctx context.Context, groups []*relationtb.GroupModel, groupMembers []*relationtb.GroupMemberModel) error
|
||||
TakeGroup(ctx context.Context, groupID string) (group *relationtb.GroupModel, err error)
|
||||
FindGroup(ctx context.Context, groupIDs []string) (groups []*relationtb.GroupModel, err error)
|
||||
FindNotDismissedGroup(ctx context.Context, groupIDs []string) (groups []*relationtb.GroupModel, err error)
|
||||
SearchGroup(ctx context.Context, keyword string, pageNumber, showNumber int32) (uint32, []*relationtb.GroupModel, error)
|
||||
//FindNotDismissedGroup(ctx context.Context, groupIDs []string) (groups []*relationtb.GroupModel, err error)
|
||||
SearchGroup(ctx context.Context, keyword string, pagination pagination.Pagination) (int64, []*relationtb.GroupModel, error)
|
||||
UpdateGroup(ctx context.Context, groupID string, data map[string]any) error
|
||||
DismissGroup(ctx context.Context, groupID string, deleteMember bool) error // 解散群,并删除群成员
|
||||
GetGroupIDsByGroupType(ctx context.Context, groupType int) (groupIDs []string, err error)
|
||||
//GetGroupIDsByGroupType(ctx context.Context, groupType int) (groupIDs []string, err error)
|
||||
// GroupMember
|
||||
TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relationtb.GroupMemberModel, err error)
|
||||
TakeGroupOwner(ctx context.Context, groupID string) (*relationtb.GroupMemberModel, error)
|
||||
@ -52,11 +47,11 @@ type GroupDatabase interface {
|
||||
FindGroupMemberUserID(ctx context.Context, groupID string) ([]string, error)
|
||||
FindGroupMemberNum(ctx context.Context, groupID string) (uint32, error)
|
||||
FindUserManagedGroupID(ctx context.Context, userID string) (groupIDs []string, err error)
|
||||
PageGroupRequest(ctx context.Context, groupIDs []string, pageNumber, showNumber int32) (uint32, []*relationtb.GroupRequestModel, error)
|
||||
PageGroupRequest(ctx context.Context, groupIDs []string, pagination pagination.Pagination) (int64, []*relationtb.GroupRequestModel, error)
|
||||
|
||||
PageGetJoinGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (total uint32, totalGroupMembers []*relationtb.GroupMemberModel, err error)
|
||||
PageGetGroupMember(ctx context.Context, groupID string, pageNumber, showNumber int32) (total uint32, totalGroupMembers []*relationtb.GroupMemberModel, err error)
|
||||
SearchGroupMember(ctx context.Context, keyword string, groupIDs []string, userIDs []string, roleLevels []int32, pageNumber, showNumber int32) (uint32, []*relationtb.GroupMemberModel, error)
|
||||
PageGetJoinGroup(ctx context.Context, userID string, pagination pagination.Pagination) (total int64, totalGroupMembers []*relationtb.GroupMemberModel, err error)
|
||||
PageGetGroupMember(ctx context.Context, groupID string, pagination pagination.Pagination) (total int64, totalGroupMembers []*relationtb.GroupMemberModel, err error)
|
||||
SearchGroupMember(ctx context.Context, keyword string, groupIDs []string, userIDs []string, roleLevels []int32, pagination pagination.Pagination) (int64, []*relationtb.GroupMemberModel, error)
|
||||
HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relationtb.GroupMemberModel) error
|
||||
DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
||||
MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string]*relationtb.GroupSimpleUserID, error)
|
||||
@ -68,14 +63,7 @@ type GroupDatabase interface {
|
||||
CreateGroupRequest(ctx context.Context, requests []*relationtb.GroupRequestModel) error
|
||||
TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relationtb.GroupRequestModel, error)
|
||||
FindGroupRequests(ctx context.Context, groupID string, userIDs []string) (int64, []*relationtb.GroupRequestModel, error)
|
||||
PageGroupRequestUser(ctx context.Context, userID string, pageNumber, showNumber int32) (uint32, []*relationtb.GroupRequestModel, error)
|
||||
// SuperGroupModelInterface
|
||||
FindSuperGroup(ctx context.Context, groupIDs []string) ([]*unrelationtb.SuperGroupModel, error)
|
||||
FindJoinSuperGroup(ctx context.Context, userID string) ([]string, 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
|
||||
PageGroupRequestUser(ctx context.Context, userID string, pagination pagination.Pagination) (int64, []*relationtb.GroupRequestModel, error)
|
||||
|
||||
// 获取群总数
|
||||
CountTotal(ctx context.Context, before *time.Time) (count int64, err error)
|
||||
@ -84,63 +72,30 @@ type GroupDatabase interface {
|
||||
DeleteGroupMemberHash(ctx context.Context, groupIDs []string) error
|
||||
}
|
||||
|
||||
func NewGroupDatabase(
|
||||
group relationtb.GroupModelInterface,
|
||||
member relationtb.GroupMemberModelInterface,
|
||||
request relationtb.GroupRequestModelInterface,
|
||||
tx tx.Tx,
|
||||
ctxTx tx.CtxTx,
|
||||
superGroup unrelationtb.SuperGroupModelInterface,
|
||||
cache cache.GroupCache,
|
||||
) GroupDatabase {
|
||||
database := &groupDatabase{
|
||||
groupDB: group,
|
||||
groupMemberDB: member,
|
||||
groupRequestDB: request,
|
||||
tx: tx,
|
||||
ctxTx: ctxTx,
|
||||
cache: cache,
|
||||
mongoDB: superGroup,
|
||||
}
|
||||
return database
|
||||
}
|
||||
|
||||
func InitGroupDatabase(db *gorm.DB, rdb redis.UniversalClient, database *mongo.Database, hashCode func(ctx context.Context, groupID string) (uint64, error)) GroupDatabase {
|
||||
func NewGroupDatabase(rdb redis.UniversalClient, groupDB relationtb.GroupModelInterface, groupMemberDB relationtb.GroupMemberModelInterface, groupRequestDB relationtb.GroupRequestModelInterface, ctxTx tx.CtxTx, hashCode func(ctx context.Context, groupID string) (uint64, error)) GroupDatabase {
|
||||
rcOptions := rockscache.NewDefaultOptions()
|
||||
rcOptions.StrongConsistency = true
|
||||
rcOptions.RandomExpireAdjustment = 0.2
|
||||
return NewGroupDatabase(
|
||||
relation.NewGroupDB(db),
|
||||
relation.NewGroupMemberDB(db),
|
||||
relation.NewGroupRequest(db),
|
||||
tx.NewGorm(db),
|
||||
tx.NewMongo(database.Client()),
|
||||
unrelation.NewSuperGroupMongoDriver(database),
|
||||
cache.NewGroupCacheRedis(
|
||||
rdb,
|
||||
relation.NewGroupDB(db),
|
||||
relation.NewGroupMemberDB(db),
|
||||
relation.NewGroupRequest(db),
|
||||
unrelation.NewSuperGroupMongoDriver(database),
|
||||
hashCode,
|
||||
rcOptions,
|
||||
),
|
||||
)
|
||||
return &groupDatabase{
|
||||
groupDB: groupDB,
|
||||
groupMemberDB: groupMemberDB,
|
||||
groupRequestDB: groupRequestDB,
|
||||
ctxTx: ctxTx,
|
||||
cache: cache.NewGroupCacheRedis(rdb, groupDB, groupMemberDB, groupRequestDB, hashCode, rcOptions),
|
||||
}
|
||||
}
|
||||
|
||||
type groupDatabase struct {
|
||||
groupDB relationtb.GroupModelInterface
|
||||
groupMemberDB relationtb.GroupMemberModelInterface
|
||||
groupRequestDB relationtb.GroupRequestModelInterface
|
||||
tx tx.Tx
|
||||
ctxTx tx.CtxTx
|
||||
cache cache.GroupCache
|
||||
mongoDB unrelationtb.SuperGroupModelInterface
|
||||
}
|
||||
|
||||
func (g *groupDatabase) GetGroupIDsByGroupType(ctx context.Context, groupType int) (groupIDs []string, err error) {
|
||||
return g.groupDB.GetGroupIDsByGroupType(ctx, groupType)
|
||||
}
|
||||
//func (g *groupDatabase) GetGroupIDsByGroupType(ctx context.Context, groupType int) (groupIDs []string, err error) {
|
||||
// return g.groupDB.GetGroupIDsByGroupType(ctx, groupType)
|
||||
//}
|
||||
|
||||
func (g *groupDatabase) FindGroupMemberUserID(ctx context.Context, groupID string) ([]string, error) {
|
||||
return g.cache.GetGroupMemberIDs(ctx, groupID)
|
||||
@ -154,41 +109,41 @@ func (g *groupDatabase) FindGroupMemberNum(ctx context.Context, groupID string)
|
||||
return uint32(num), nil
|
||||
}
|
||||
|
||||
func (g *groupDatabase) CreateGroup(
|
||||
ctx context.Context,
|
||||
groups []*relationtb.GroupModel,
|
||||
groupMembers []*relationtb.GroupMemberModel,
|
||||
) error {
|
||||
cache := g.cache.NewCache()
|
||||
if err := g.tx.Transaction(func(tx any) error {
|
||||
func (g *groupDatabase) CreateGroup(ctx context.Context, groups []*relationtb.GroupModel, groupMembers []*relationtb.GroupMemberModel) error {
|
||||
if len(groups)+len(groupMembers) == 0 {
|
||||
return nil
|
||||
}
|
||||
return g.ctxTx.Transaction(ctx, func(ctx context.Context) error {
|
||||
c := g.cache.NewCache()
|
||||
if len(groups) > 0 {
|
||||
if err := g.groupDB.NewTx(tx).Create(ctx, groups); err != nil {
|
||||
if err := g.groupDB.Create(ctx, groups); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, group := range groups {
|
||||
c = c.DelGroupsInfo(group.GroupID)
|
||||
c = c.DelGroupMembersHash(group.GroupID)
|
||||
c = c.DelGroupsMemberNum(group.GroupID)
|
||||
c = c.DelGroupMemberIDs(group.GroupID)
|
||||
}
|
||||
}
|
||||
if len(groupMembers) > 0 {
|
||||
if err := g.groupMemberDB.NewTx(tx).Create(ctx, groupMembers); err != nil {
|
||||
if err := g.groupMemberDB.Create(ctx, groupMembers); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
createGroupIDs := utils.DistinctAnyGetComparable(groups, func(group *relationtb.GroupModel) string {
|
||||
return group.GroupID
|
||||
})
|
||||
m := make(map[string]struct{})
|
||||
|
||||
for _, groupMember := range groupMembers {
|
||||
if _, ok := m[groupMember.GroupID]; !ok {
|
||||
m[groupMember.GroupID] = struct{}{}
|
||||
cache = cache.DelGroupMemberIDs(groupMember.GroupID).DelGroupMembersHash(groupMember.GroupID).DelGroupsMemberNum(groupMember.GroupID)
|
||||
temp := make(map[string]struct{})
|
||||
for _, groupMember := range groupMembers {
|
||||
if _, ok := temp[groupMember.GroupID]; !ok {
|
||||
temp[groupMember.GroupID] = struct{}{}
|
||||
c = c.DelGroupMembersHash(groupMember.GroupID)
|
||||
c = c.DelGroupsMemberNum(groupMember.GroupID)
|
||||
c = c.DelGroupMemberIDs(groupMember.GroupID)
|
||||
}
|
||||
c = c.DelJoinedGroupID(groupMember.UserID)
|
||||
c = c.DelGroupMembersInfo(groupMember.GroupID, groupMember.UserID)
|
||||
}
|
||||
cache = cache.DelJoinedGroupID(groupMember.UserID).DelGroupMembersInfo(groupMember.GroupID, groupMember.UserID)
|
||||
}
|
||||
cache = cache.DelGroupsInfo(createGroupIDs...)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return cache.ExecDel(ctx)
|
||||
return c.ExecDel(ctx)
|
||||
})
|
||||
}
|
||||
|
||||
func (g *groupDatabase) TakeGroup(ctx context.Context, groupID string) (group *relationtb.GroupModel, err error) {
|
||||
@ -199,12 +154,8 @@ func (g *groupDatabase) FindGroup(ctx context.Context, groupIDs []string) (group
|
||||
return g.cache.GetGroupsInfo(ctx, groupIDs)
|
||||
}
|
||||
|
||||
func (g *groupDatabase) SearchGroup(
|
||||
ctx context.Context,
|
||||
keyword string,
|
||||
pageNumber, showNumber int32,
|
||||
) (uint32, []*relationtb.GroupModel, error) {
|
||||
return g.groupDB.Search(ctx, keyword, pageNumber, showNumber)
|
||||
func (g *groupDatabase) SearchGroup(ctx context.Context, keyword string, pagination pagination.Pagination) (int64, []*relationtb.GroupModel, error) {
|
||||
return g.groupDB.Search(ctx, keyword, pagination)
|
||||
}
|
||||
|
||||
func (g *groupDatabase) UpdateGroup(ctx context.Context, groupID string, data map[string]any) error {
|
||||
@ -254,12 +205,8 @@ func (g *groupDatabase) FindUserManagedGroupID(ctx context.Context, userID strin
|
||||
return g.groupMemberDB.FindUserManagedGroupID(ctx, userID)
|
||||
}
|
||||
|
||||
func (g *groupDatabase) PageGroupRequest(
|
||||
ctx context.Context,
|
||||
groupIDs []string,
|
||||
pageNumber, showNumber int32,
|
||||
) (uint32, []*relationtb.GroupRequestModel, error) {
|
||||
return g.groupRequestDB.PageGroup(ctx, groupIDs, pageNumber, showNumber)
|
||||
func (g *groupDatabase) PageGroupRequest(ctx context.Context, groupIDs []string, pagination pagination.Pagination) (int64, []*relationtb.GroupRequestModel, error) {
|
||||
return g.groupRequestDB.PageGroup(ctx, groupIDs, pagination)
|
||||
}
|
||||
|
||||
func (g *groupDatabase) FindGroupMember(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32) (totalGroupMembers []*relationtb.GroupMemberModel, err error) {
|
||||
@ -294,8 +241,8 @@ func (g *groupDatabase) FindGroupMember(ctx context.Context, groupIDs []string,
|
||||
func (g *groupDatabase) PageGetJoinGroup(
|
||||
ctx context.Context,
|
||||
userID string,
|
||||
pageNumber, showNumber int32,
|
||||
) (total uint32, totalGroupMembers []*relationtb.GroupMemberModel, err error) {
|
||||
pagination pagination.Pagination,
|
||||
) (total int64, totalGroupMembers []*relationtb.GroupMemberModel, err error) {
|
||||
groupIDs, err := g.cache.GetJoinedGroupIDs(ctx, userID)
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
@ -313,8 +260,8 @@ func (g *groupDatabase) PageGetJoinGroup(
|
||||
func (g *groupDatabase) PageGetGroupMember(
|
||||
ctx context.Context,
|
||||
groupID string,
|
||||
pageNumber, showNumber int32,
|
||||
) (total uint32, totalGroupMembers []*relationtb.GroupMemberModel, err error) {
|
||||
pagination pagination.Pagination,
|
||||
) (total int64, totalGroupMembers []*relationtb.GroupMemberModel, err error) {
|
||||
groupMemberIDs, err := g.cache.GetGroupMemberIDs(ctx, groupID)
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
@ -330,15 +277,8 @@ func (g *groupDatabase) PageGetGroupMember(
|
||||
return uint32(len(groupMemberIDs)), members, nil
|
||||
}
|
||||
|
||||
func (g *groupDatabase) SearchGroupMember(
|
||||
ctx context.Context,
|
||||
keyword string,
|
||||
groupIDs []string,
|
||||
userIDs []string,
|
||||
roleLevels []int32,
|
||||
pageNumber, showNumber int32,
|
||||
) (uint32, []*relationtb.GroupMemberModel, error) {
|
||||
return g.groupMemberDB.SearchMember(ctx, keyword, groupIDs, userIDs, roleLevels, pageNumber, showNumber)
|
||||
func (g *groupDatabase) SearchGroupMember(ctx context.Context, keyword string, groupIDs []string, userIDs []string, roleLevels []int32, pagination pagination.Pagination) (int64, []*relationtb.GroupMemberModel, error) {
|
||||
return g.groupMemberDB.SearchMember(ctx, keyword, groupIDs, userIDs, roleLevels, pagination)
|
||||
}
|
||||
|
||||
func (g *groupDatabase) HandlerGroupRequest(
|
||||
@ -484,64 +424,11 @@ func (g *groupDatabase) TakeGroupRequest(
|
||||
func (g *groupDatabase) PageGroupRequestUser(
|
||||
ctx context.Context,
|
||||
userID string,
|
||||
pageNumber, showNumber int32,
|
||||
) (uint32, []*relationtb.GroupRequestModel, error) {
|
||||
pagination pagination.Pagination,
|
||||
) (int64, []*relationtb.GroupRequestModel, error) {
|
||||
return g.groupRequestDB.Page(ctx, userID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
func (g *groupDatabase) FindSuperGroup(
|
||||
ctx context.Context,
|
||||
groupIDs []string,
|
||||
) (models []*unrelationtb.SuperGroupModel, err error) {
|
||||
return g.cache.GetSuperGroupMemberIDs(ctx, groupIDs...)
|
||||
}
|
||||
|
||||
func (g *groupDatabase) FindJoinSuperGroup(ctx context.Context, userID string) ([]string, error) {
|
||||
return g.cache.GetJoinedSuperGroupIDs(ctx, userID)
|
||||
}
|
||||
|
||||
func (g *groupDatabase) CreateSuperGroup(ctx context.Context, groupID string, initMemberIDs []string) error {
|
||||
if err := g.mongoDB.CreateSuperGroup(ctx, groupID, initMemberIDs); err != nil {
|
||||
return err
|
||||
}
|
||||
return g.cache.DelSuperGroupMemberIDs(groupID).DelJoinedSuperGroupIDs(initMemberIDs...).ExecDel(ctx)
|
||||
}
|
||||
|
||||
func (g *groupDatabase) DeleteSuperGroup(ctx context.Context, groupID string) error {
|
||||
cache := g.cache.NewCache()
|
||||
if err := g.ctxTx.Transaction(ctx, func(ctx context.Context) error {
|
||||
if err := g.mongoDB.DeleteSuperGroup(ctx, groupID); err != nil {
|
||||
return err
|
||||
}
|
||||
models, err := g.cache.GetSuperGroupMemberIDs(ctx, groupID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cache = cache.DelSuperGroupMemberIDs(groupID)
|
||||
if len(models) > 0 {
|
||||
cache = cache.DelJoinedSuperGroupIDs(models[0].MemberIDs...)
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return cache.ExecDel(ctx)
|
||||
}
|
||||
|
||||
func (g *groupDatabase) DeleteSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
||||
if err := g.mongoDB.RemoverUserFromSuperGroup(ctx, groupID, userIDs); err != nil {
|
||||
return err
|
||||
}
|
||||
return g.cache.DelSuperGroupMemberIDs(groupID).DelJoinedSuperGroupIDs(userIDs...).ExecDel(ctx)
|
||||
}
|
||||
|
||||
func (g *groupDatabase) CreateSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
||||
if err := g.mongoDB.AddUserToSuperGroup(ctx, groupID, userIDs); err != nil {
|
||||
return err
|
||||
}
|
||||
return g.cache.DelSuperGroupMemberIDs(groupID).DelJoinedSuperGroupIDs(userIDs...).ExecDel(ctx)
|
||||
}
|
||||
|
||||
func (g *groupDatabase) CountTotal(ctx context.Context, before *time.Time) (count int64, err error) {
|
||||
return g.groupDB.CountTotal(ctx, before)
|
||||
}
|
||||
@ -554,10 +441,6 @@ func (g *groupDatabase) FindGroupRequests(ctx context.Context, groupID string, u
|
||||
return g.groupRequestDB.FindGroupRequests(ctx, groupID, userIDs)
|
||||
}
|
||||
|
||||
func (g *groupDatabase) FindNotDismissedGroup(ctx context.Context, groupIDs []string) (groups []*relationtb.GroupModel, err error) {
|
||||
return g.groupDB.FindNotDismissedGroup(ctx, groupIDs)
|
||||
}
|
||||
|
||||
func (g *groupDatabase) DeleteGroupMemberHash(ctx context.Context, groupIDs []string) error {
|
||||
if len(groupIDs) == 0 {
|
||||
return nil
|
||||
|
||||
56
pkg/common/db/newmgo/group.go
Normal file
56
pkg/common/db/newmgo/group.go
Normal file
@ -0,0 +1,56 @@
|
||||
package newmgo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/newmgo/mgotool"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/pagination"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"time"
|
||||
)
|
||||
|
||||
func NewGroupMongo(db *mongo.Database) (relation.GroupModelInterface, error) {
|
||||
return &GroupMgo{
|
||||
coll: db.Collection("user"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
type GroupMgo struct {
|
||||
coll *mongo.Collection
|
||||
}
|
||||
|
||||
func (g *GroupMgo) Create(ctx context.Context, groups []*relation.GroupModel) (err error) {
|
||||
return mgotool.InsertMany(ctx, g.coll, groups)
|
||||
}
|
||||
|
||||
func (g *GroupMgo) UpdateMap(ctx context.Context, groupID string, args map[string]any) (err error) {
|
||||
if len(args) == 0 {
|
||||
return nil
|
||||
}
|
||||
return mgotool.UpdateOne(ctx, g.coll, bson.M{"group_id": groupID}, bson.M{"$set": args}, true)
|
||||
}
|
||||
|
||||
func (g *GroupMgo) Find(ctx context.Context, groupIDs []string) (groups []*relation.GroupModel, err error) {
|
||||
return mgotool.Find[*relation.GroupModel](ctx, g.coll, bson.M{"group_id": bson.M{"$in": groupIDs}})
|
||||
}
|
||||
|
||||
func (g *GroupMgo) Take(ctx context.Context, groupID string) (group *relation.GroupModel, err error) {
|
||||
return mgotool.FindOne[*relation.GroupModel](ctx, g.coll, bson.M{"group_id": groupID})
|
||||
}
|
||||
|
||||
func (g *GroupMgo) Search(ctx context.Context, keyword string, pagination pagination.Pagination) (total int64, groups []*relation.GroupModel, err error) {
|
||||
return mgotool.FindPage[*relation.GroupModel](ctx, g.coll, bson.M{"group_name": bson.M{"$regex": keyword}}, pagination)
|
||||
}
|
||||
|
||||
func (g *GroupMgo) CountTotal(ctx context.Context, before *time.Time) (count int64, err error) {
|
||||
if before == nil {
|
||||
return mgotool.Count(ctx, g.coll, bson.M{})
|
||||
}
|
||||
return mgotool.Count(ctx, g.coll, bson.M{"create_time": bson.M{"$lt": before}})
|
||||
}
|
||||
|
||||
func (g *GroupMgo) CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
72
pkg/common/db/newmgo/group_member.go
Normal file
72
pkg/common/db/newmgo/group_member.go
Normal file
@ -0,0 +1,72 @@
|
||||
package newmgo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/protocol/constant"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/newmgo/mgotool"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/pagination"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
func NewGroupMember(db *mongo.Database) (relation.GroupMemberModelInterface, error) {
|
||||
return &GroupMemberMgo{coll: db.Collection("group_member")}, nil
|
||||
}
|
||||
|
||||
type GroupMemberMgo struct {
|
||||
coll *mongo.Collection
|
||||
}
|
||||
|
||||
func (g *GroupMemberMgo) Create(ctx context.Context, groupMembers []*relation.GroupMemberModel) (err error) {
|
||||
return mgotool.InsertMany(ctx, g.coll, groupMembers)
|
||||
}
|
||||
|
||||
func (g *GroupMemberMgo) Delete(ctx context.Context, groupID string, userIDs []string) (err error) {
|
||||
return mgotool.DeleteMany(ctx, g.coll, bson.M{"group_id": groupID, "user_id": bson.M{"$in": userIDs}})
|
||||
}
|
||||
|
||||
func (g *GroupMemberMgo) Update(ctx context.Context, groupID string, userID string, data map[string]any) (err error) {
|
||||
return mgotool.UpdateOne(ctx, g.coll, bson.M{"group_id": groupID, "user_id": userID}, bson.M{"$set": data}, true)
|
||||
}
|
||||
|
||||
func (g *GroupMemberMgo) Find(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32) (groupMembers []*relation.GroupMemberModel, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupMemberMgo) FindMemberUserID(ctx context.Context, groupID string) (userIDs []string, err error) {
|
||||
return mgotool.Find[string](ctx, g.coll, bson.M{"group_id": groupID}, options.Find().SetProjection(bson.M{"user_id": 1}))
|
||||
}
|
||||
|
||||
func (g *GroupMemberMgo) Take(ctx context.Context, groupID string, userID string) (groupMember *relation.GroupMemberModel, err error) {
|
||||
return mgotool.FindOne[*relation.GroupMemberModel](ctx, g.coll, bson.M{"group_id": groupID, "user_id": userID})
|
||||
}
|
||||
|
||||
func (g *GroupMemberMgo) TakeOwner(ctx context.Context, groupID string) (groupMember *relation.GroupMemberModel, err error) {
|
||||
return mgotool.FindOne[*relation.GroupMemberModel](ctx, g.coll, bson.M{"group_id": groupID, "role_level": constant.GroupOwner})
|
||||
}
|
||||
|
||||
func (g *GroupMemberMgo) SearchMember(ctx context.Context, keyword string, groupIDs []string, userIDs []string, roleLevels []int32, pagination pagination.Pagination) (total int64, groupList []*relation.GroupMemberModel, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupMemberMgo) FindUserJoinedGroupID(ctx context.Context, userID string) (groupIDs []string, err error) {
|
||||
return mgotool.Find[string](ctx, g.coll, bson.M{"user_id": userID}, options.Find().SetProjection(bson.M{"group_id": 1}))
|
||||
}
|
||||
|
||||
func (g *GroupMemberMgo) TakeGroupMemberNum(ctx context.Context, groupID string) (count int64, err error) {
|
||||
return mgotool.Count(ctx, g.coll, bson.M{"group_id": groupID})
|
||||
}
|
||||
|
||||
func (g *GroupMemberMgo) FindUserManagedGroupID(ctx context.Context, userID string) (groupIDs []string, err error) {
|
||||
filter := bson.M{
|
||||
"user_id": userID,
|
||||
"role_level": bson.M{
|
||||
"$in": []int{constant.GroupOwner, constant.GroupAdmin},
|
||||
},
|
||||
}
|
||||
return mgotool.Find[string](ctx, g.coll, filter, options.Find().SetProjection(bson.M{"group_id": 1}))
|
||||
}
|
||||
51
pkg/common/db/newmgo/group_request.go
Normal file
51
pkg/common/db/newmgo/group_request.go
Normal file
@ -0,0 +1,51 @@
|
||||
package newmgo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/pagination"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
func NewGroupRequestMgo(db *mongo.Database) (relation.GroupRequestModelInterface, error) {
|
||||
return &GroupRequestMgo{coll: db.Collection("group_request")}, nil
|
||||
}
|
||||
|
||||
type GroupRequestMgo struct {
|
||||
coll *mongo.Collection
|
||||
}
|
||||
|
||||
func (g *GroupRequestMgo) Create(ctx context.Context, groupRequests []*relation.GroupRequestModel) (err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupRequestMgo) Delete(ctx context.Context, groupID string, userID string) (err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupRequestMgo) UpdateHandler(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32) (err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupRequestMgo) Take(ctx context.Context, groupID string, userID string) (groupRequest *relation.GroupRequestModel, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupRequestMgo) FindGroupRequests(ctx context.Context, groupID string, userIDs []string) (int64, []*relation.GroupRequestModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupRequestMgo) Page(ctx context.Context, userID string, pagination pagination.Pagination) (total int64, groups []*relation.GroupRequestModel, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupRequestMgo) PageGroup(ctx context.Context, groupIDs []string, pagination pagination.Pagination) (total int64, groups []*relation.GroupRequestModel, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
@ -14,93 +14,93 @@
|
||||
|
||||
package relation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/OpenIMSDK/protocol/constant"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/OpenIMSDK/tools/errs"
|
||||
"github.com/OpenIMSDK/tools/ormutil"
|
||||
"github.com/OpenIMSDK/tools/utils"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||
)
|
||||
|
||||
var _ relation.GroupModelInterface = (*GroupGorm)(nil)
|
||||
|
||||
type GroupGorm struct {
|
||||
*MetaDB
|
||||
}
|
||||
|
||||
func NewGroupDB(db *gorm.DB) relation.GroupModelInterface {
|
||||
return &GroupGorm{NewMetaDB(db, &relation.GroupModel{})}
|
||||
}
|
||||
|
||||
func (g *GroupGorm) NewTx(tx any) relation.GroupModelInterface {
|
||||
return &GroupGorm{NewMetaDB(tx.(*gorm.DB), &relation.GroupModel{})}
|
||||
}
|
||||
|
||||
func (g *GroupGorm) Create(ctx context.Context, groups []*relation.GroupModel) (err error) {
|
||||
return utils.Wrap(g.DB.Create(&groups).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupGorm) UpdateMap(ctx context.Context, groupID string, args map[string]any) (err error) {
|
||||
return utils.Wrap(g.DB.Where("group_id = ?", groupID).Model(&relation.GroupModel{}).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupGorm) UpdateStatus(ctx context.Context, groupID string, status int32) (err error) {
|
||||
return utils.Wrap(g.DB.Where("group_id = ?", groupID).Model(&relation.GroupModel{}).Updates(map[string]any{"status": status}).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupGorm) Find(ctx context.Context, groupIDs []string) (groups []*relation.GroupModel, err error) {
|
||||
return groups, utils.Wrap(g.DB.Where("group_id in (?)", groupIDs).Find(&groups).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupGorm) Take(ctx context.Context, groupID string) (group *relation.GroupModel, err error) {
|
||||
group = &relation.GroupModel{}
|
||||
return group, utils.Wrap(g.DB.Where("group_id = ?", groupID).Take(group).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupGorm) Search(ctx context.Context, keyword string, pageNumber, showNumber int32) (total uint32, groups []*relation.GroupModel, err error) {
|
||||
db := g.DB
|
||||
db = db.WithContext(ctx).Where("status!=?", constant.GroupStatusDismissed)
|
||||
return ormutil.GormSearch[relation.GroupModel](db, []string{"name"}, keyword, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
func (g *GroupGorm) GetGroupIDsByGroupType(ctx context.Context, groupType int) (groupIDs []string, err error) {
|
||||
return groupIDs, utils.Wrap(g.DB.Model(&relation.GroupModel{}).Where("group_type = ? ", groupType).Pluck("group_id", &groupIDs).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupGorm) CountTotal(ctx context.Context, before *time.Time) (count int64, err error) {
|
||||
db := g.db(ctx).Model(&relation.GroupModel{})
|
||||
if before != nil {
|
||||
db = db.Where("create_time < ?", before)
|
||||
}
|
||||
if err := db.Count(&count).Error; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (g *GroupGorm) CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error) {
|
||||
var res []struct {
|
||||
Date time.Time `gorm:"column:date"`
|
||||
Count int64 `gorm:"column:count"`
|
||||
}
|
||||
err := g.db(ctx).Model(&relation.GroupModel{}).Select("DATE(create_time) AS date, count(1) AS count").Where("create_time >= ? and create_time < ?", start, end).Group("date").Find(&res).Error
|
||||
if err != nil {
|
||||
return nil, errs.Wrap(err)
|
||||
}
|
||||
v := make(map[string]int64)
|
||||
for _, r := range res {
|
||||
v[r.Date.Format("2006-01-02")] = r.Count
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func (g *GroupGorm) FindNotDismissedGroup(ctx context.Context, groupIDs []string) (groups []*relation.GroupModel, err error) {
|
||||
return groups, utils.Wrap(g.DB.Where("group_id in (?) and status != ?", groupIDs, constant.GroupStatusDismissed).Find(&groups).Error, "")
|
||||
}
|
||||
//import (
|
||||
// "context"
|
||||
// "time"
|
||||
//
|
||||
// "github.com/OpenIMSDK/protocol/constant"
|
||||
//
|
||||
// "gorm.io/gorm"
|
||||
//
|
||||
// "github.com/OpenIMSDK/tools/errs"
|
||||
// "github.com/OpenIMSDK/tools/ormutil"
|
||||
// "github.com/OpenIMSDK/tools/utils"
|
||||
//
|
||||
// "github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||
//)
|
||||
//
|
||||
//var _ relation.GroupModelInterface = (*GroupGorm)(nil)
|
||||
//
|
||||
//type GroupGorm struct {
|
||||
// *MetaDB
|
||||
//}
|
||||
//
|
||||
//func NewGroupDB(db *gorm.DB) relation.GroupModelInterface {
|
||||
// return &GroupGorm{NewMetaDB(db, &relation.GroupModel{})}
|
||||
//}
|
||||
//
|
||||
//func (g *GroupGorm) NewTx(tx any) relation.GroupModelInterface {
|
||||
// return &GroupGorm{NewMetaDB(tx.(*gorm.DB), &relation.GroupModel{})}
|
||||
//}
|
||||
//
|
||||
//func (g *GroupGorm) Create(ctx context.Context, groups []*relation.GroupModel) (err error) {
|
||||
// return utils.Wrap(g.DB.Create(&groups).Error, "")
|
||||
//}
|
||||
//
|
||||
//func (g *GroupGorm) UpdateMap(ctx context.Context, groupID string, args map[string]any) (err error) {
|
||||
// return utils.Wrap(g.DB.Where("group_id = ?", groupID).Model(&relation.GroupModel{}).Updates(args).Error, "")
|
||||
//}
|
||||
//
|
||||
//func (g *GroupGorm) UpdateStatus(ctx context.Context, groupID string, status int32) (err error) {
|
||||
// return utils.Wrap(g.DB.Where("group_id = ?", groupID).Model(&relation.GroupModel{}).Updates(map[string]any{"status": status}).Error, "")
|
||||
//}
|
||||
//
|
||||
//func (g *GroupGorm) Find(ctx context.Context, groupIDs []string) (groups []*relation.GroupModel, err error) {
|
||||
// return groups, utils.Wrap(g.DB.Where("group_id in (?)", groupIDs).Find(&groups).Error, "")
|
||||
//}
|
||||
//
|
||||
//func (g *GroupGorm) Take(ctx context.Context, groupID string) (group *relation.GroupModel, err error) {
|
||||
// group = &relation.GroupModel{}
|
||||
// return group, utils.Wrap(g.DB.Where("group_id = ?", groupID).Take(group).Error, "")
|
||||
//}
|
||||
//
|
||||
//func (g *GroupGorm) Search(ctx context.Context, keyword string, pageNumber, showNumber int32) (total uint32, groups []*relation.GroupModel, err error) {
|
||||
// db := g.DB
|
||||
// db = db.WithContext(ctx).Where("status!=?", constant.GroupStatusDismissed)
|
||||
// return ormutil.GormSearch[relation.GroupModel](db, []string{"name"}, keyword, pageNumber, showNumber)
|
||||
//}
|
||||
//
|
||||
//func (g *GroupGorm) GetGroupIDsByGroupType(ctx context.Context, groupType int) (groupIDs []string, err error) {
|
||||
// return groupIDs, utils.Wrap(g.DB.Model(&relation.GroupModel{}).Where("group_type = ? ", groupType).Pluck("group_id", &groupIDs).Error, "")
|
||||
//}
|
||||
//
|
||||
//func (g *GroupGorm) CountTotal(ctx context.Context, before *time.Time) (count int64, err error) {
|
||||
// db := g.db(ctx).Model(&relation.GroupModel{})
|
||||
// if before != nil {
|
||||
// db = db.Where("create_time < ?", before)
|
||||
// }
|
||||
// if err := db.Count(&count).Error; err != nil {
|
||||
// return 0, err
|
||||
// }
|
||||
// return count, nil
|
||||
//}
|
||||
//
|
||||
//func (g *GroupGorm) CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error) {
|
||||
// var res []struct {
|
||||
// Date time.Time `gorm:"column:date"`
|
||||
// Count int64 `gorm:"column:count"`
|
||||
// }
|
||||
// err := g.db(ctx).Model(&relation.GroupModel{}).Select("DATE(create_time) AS date, count(1) AS count").Where("create_time >= ? and create_time < ?", start, end).Group("date").Find(&res).Error
|
||||
// if err != nil {
|
||||
// return nil, errs.Wrap(err)
|
||||
// }
|
||||
// v := make(map[string]int64)
|
||||
// for _, r := range res {
|
||||
// v[r.Date.Format("2006-01-02")] = r.Count
|
||||
// }
|
||||
// return v, nil
|
||||
//}
|
||||
//
|
||||
//func (g *GroupGorm) FindNotDismissedGroup(ctx context.Context, groupIDs []string) (groups []*relation.GroupModel, err error) {
|
||||
// return groups, utils.Wrap(g.DB.Where("group_id in (?) and status != ?", groupIDs, constant.GroupStatusDismissed).Find(&groups).Error, "")
|
||||
//}
|
||||
|
||||
@ -16,6 +16,7 @@ package relation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/pagination"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -23,22 +24,40 @@ const (
|
||||
GroupModelTableName = "groups"
|
||||
)
|
||||
|
||||
//type GroupModel struct {
|
||||
// GroupID string `gorm:"column:group_id;primary_key;size:64" json:"groupID" binding:"required"`
|
||||
// GroupName string `gorm:"column:name;size:255" json:"groupName"`
|
||||
// Notification string `gorm:"column:notification;size:255" json:"notification"`
|
||||
// Introduction string `gorm:"column:introduction;size:255" json:"introduction"`
|
||||
// FaceURL string `gorm:"column:face_url;size:255" json:"faceURL"`
|
||||
// CreateTime time.Time `gorm:"column:create_time;index:create_time;autoCreateTime"`
|
||||
// Ex string `gorm:"column:ex" json:"ex;size:1024"`
|
||||
// Status int32 `gorm:"column:status"`
|
||||
// CreatorUserID string `gorm:"column:creator_user_id;size:64"`
|
||||
// GroupType int32 `gorm:"column:group_type"`
|
||||
// NeedVerification int32 `gorm:"column:need_verification"`
|
||||
// LookMemberInfo int32 `gorm:"column:look_member_info" json:"lookMemberInfo"`
|
||||
// ApplyMemberFriend int32 `gorm:"column:apply_member_friend" json:"applyMemberFriend"`
|
||||
// NotificationUpdateTime time.Time `gorm:"column:notification_update_time"`
|
||||
// NotificationUserID string `gorm:"column:notification_user_id;size:64"`
|
||||
//}
|
||||
|
||||
type GroupModel struct {
|
||||
GroupID string `gorm:"column:group_id;primary_key;size:64" json:"groupID" binding:"required"`
|
||||
GroupName string `gorm:"column:name;size:255" json:"groupName"`
|
||||
Notification string `gorm:"column:notification;size:255" json:"notification"`
|
||||
Introduction string `gorm:"column:introduction;size:255" json:"introduction"`
|
||||
FaceURL string `gorm:"column:face_url;size:255" json:"faceURL"`
|
||||
CreateTime time.Time `gorm:"column:create_time;index:create_time;autoCreateTime"`
|
||||
Ex string `gorm:"column:ex" json:"ex;size:1024"`
|
||||
Status int32 `gorm:"column:status"`
|
||||
CreatorUserID string `gorm:"column:creator_user_id;size:64"`
|
||||
GroupType int32 `gorm:"column:group_type"`
|
||||
NeedVerification int32 `gorm:"column:need_verification"`
|
||||
LookMemberInfo int32 `gorm:"column:look_member_info" json:"lookMemberInfo"`
|
||||
ApplyMemberFriend int32 `gorm:"column:apply_member_friend" json:"applyMemberFriend"`
|
||||
NotificationUpdateTime time.Time `gorm:"column:notification_update_time"`
|
||||
NotificationUserID string `gorm:"column:notification_user_id;size:64"`
|
||||
GroupID string `bson:"group_id"`
|
||||
GroupName string `bson:"group_name"`
|
||||
Notification string `bson:"notification"`
|
||||
Introduction string `bson:"introduction"`
|
||||
FaceURL string `bson:"face_url"`
|
||||
CreateTime time.Time `bson:"create_time"`
|
||||
Ex string `bson:"ex"`
|
||||
Status int32 `bson:"status"`
|
||||
CreatorUserID string `bson:"creator_user_id"`
|
||||
GroupType int32 `bson:"group_type"`
|
||||
NeedVerification int32 `bson:"need_verification"`
|
||||
LookMemberInfo int32 `bson:"look_member_info"`
|
||||
ApplyMemberFriend int32 `bson:"apply_member_friend"`
|
||||
NotificationUpdateTime time.Time `bson:"notification_update_time"`
|
||||
NotificationUserID string `bson:"notification_user_id"`
|
||||
}
|
||||
|
||||
func (GroupModel) TableName() string {
|
||||
@ -46,19 +65,14 @@ func (GroupModel) TableName() string {
|
||||
}
|
||||
|
||||
type GroupModelInterface interface {
|
||||
NewTx(tx any) GroupModelInterface
|
||||
Create(ctx context.Context, groups []*GroupModel) (err error)
|
||||
UpdateMap(ctx context.Context, groupID string, args map[string]any) (err error)
|
||||
UpdateStatus(ctx context.Context, groupID string, status int32) (err error)
|
||||
//UpdateStatus(ctx context.Context, groupID string, status int32) (err error)
|
||||
Find(ctx context.Context, groupIDs []string) (groups []*GroupModel, err error)
|
||||
FindNotDismissedGroup(ctx context.Context, groupIDs []string) (groups []*GroupModel, err error)
|
||||
//FindNotDismissedGroup(ctx context.Context, groupIDs []string) (groups []*GroupModel, err error)
|
||||
Take(ctx context.Context, groupID string) (group *GroupModel, err error)
|
||||
Search(
|
||||
ctx context.Context,
|
||||
keyword string,
|
||||
pageNumber, showNumber int32,
|
||||
) (total uint32, groups []*GroupModel, err error)
|
||||
GetGroupIDsByGroupType(ctx context.Context, groupType int) (groupIDs []string, err error)
|
||||
Search(ctx context.Context, keyword string, pagination pagination.Pagination) (total int64, groups []*GroupModel, err error)
|
||||
//GetGroupIDsByGroupType(ctx context.Context, groupType int) (groupIDs []string, err error)
|
||||
// 获取群总数
|
||||
CountTotal(ctx context.Context, before *time.Time) (count int64, err error)
|
||||
// 获取范围内群增量
|
||||
|
||||
@ -16,6 +16,7 @@ package relation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/pagination"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -23,18 +24,32 @@ const (
|
||||
GroupMemberModelTableName = "group_members"
|
||||
)
|
||||
|
||||
//type GroupMemberModel struct {
|
||||
// GroupID string `gorm:"column:group_id;primary_key;size:64"`
|
||||
// UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
// Nickname string `gorm:"column:nickname;size:255"`
|
||||
// FaceURL string `gorm:"column:user_group_face_url;size:255"`
|
||||
// RoleLevel int32 `gorm:"column:role_level"`
|
||||
// JoinTime time.Time `gorm:"column:join_time"`
|
||||
// JoinSource int32 `gorm:"column:join_source"`
|
||||
// InviterUserID string `gorm:"column:inviter_user_id;size:64"`
|
||||
// OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||
// MuteEndTime time.Time `gorm:"column:mute_end_time"`
|
||||
// Ex string `gorm:"column:ex;size:1024"`
|
||||
//}
|
||||
|
||||
type GroupMemberModel struct {
|
||||
GroupID string `gorm:"column:group_id;primary_key;size:64"`
|
||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
Nickname string `gorm:"column:nickname;size:255"`
|
||||
FaceURL string `gorm:"column:user_group_face_url;size:255"`
|
||||
RoleLevel int32 `gorm:"column:role_level"`
|
||||
JoinTime time.Time `gorm:"column:join_time"`
|
||||
JoinSource int32 `gorm:"column:join_source"`
|
||||
InviterUserID string `gorm:"column:inviter_user_id;size:64"`
|
||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||
MuteEndTime time.Time `gorm:"column:mute_end_time"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
GroupID string `bson:"group_id"`
|
||||
UserID string `bson:"user_id"`
|
||||
Nickname string `bson:"nickname"`
|
||||
FaceURL string `bson:"face_url"`
|
||||
RoleLevel int32 `bson:"role_level"`
|
||||
JoinTime time.Time `bson:"join_time"`
|
||||
JoinSource int32 `bson:"join_source"`
|
||||
InviterUserID string `bson:"inviter_user_id"`
|
||||
OperatorUserID string `bson:"operator_user_id"`
|
||||
MuteEndTime time.Time `bson:"mute_end_time"`
|
||||
Ex string `bson:"ex"`
|
||||
}
|
||||
|
||||
func (GroupMemberModel) TableName() string {
|
||||
@ -42,33 +57,21 @@ func (GroupMemberModel) TableName() string {
|
||||
}
|
||||
|
||||
type GroupMemberModelInterface interface {
|
||||
NewTx(tx any) GroupMemberModelInterface
|
||||
//NewTx(tx any) GroupMemberModelInterface
|
||||
Create(ctx context.Context, groupMembers []*GroupMemberModel) (err error)
|
||||
Delete(ctx context.Context, groupID string, userIDs []string) (err error)
|
||||
DeleteGroup(ctx context.Context, groupIDs []string) (err error)
|
||||
//DeleteGroup(ctx context.Context, groupIDs []string) (err error)
|
||||
Update(ctx context.Context, groupID string, userID string, data map[string]any) (err error)
|
||||
UpdateRoleLevel(ctx context.Context, groupID string, userID string, roleLevel int32) (rowsAffected int64, err error)
|
||||
Find(
|
||||
ctx context.Context,
|
||||
groupIDs []string,
|
||||
userIDs []string,
|
||||
roleLevels []int32,
|
||||
) (groupMembers []*GroupMemberModel, err error)
|
||||
//UpdateRoleLevel(ctx context.Context, groupID string, userID string, roleLevel int32) (rowsAffected int64, err error)
|
||||
Find(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32) (groupMembers []*GroupMemberModel, err error)
|
||||
FindMemberUserID(ctx context.Context, groupID string) (userIDs []string, err error)
|
||||
Take(ctx context.Context, groupID string, userID string) (groupMember *GroupMemberModel, err error)
|
||||
TakeOwner(ctx context.Context, groupID string) (groupMember *GroupMemberModel, err error)
|
||||
SearchMember(
|
||||
ctx context.Context,
|
||||
keyword string,
|
||||
groupIDs []string,
|
||||
userIDs []string,
|
||||
roleLevels []int32,
|
||||
pageNumber, showNumber int32,
|
||||
) (total uint32, groupList []*GroupMemberModel, err error)
|
||||
MapGroupMemberNum(ctx context.Context, groupIDs []string) (count map[string]uint32, err error)
|
||||
FindJoinUserID(ctx context.Context, groupIDs []string) (groupUsers map[string][]string, err error)
|
||||
SearchMember(ctx context.Context, keyword string, groupIDs []string, userIDs []string, roleLevels []int32, pagination pagination.Pagination) (total int64, groupList []*GroupMemberModel, err error)
|
||||
//MapGroupMemberNum(ctx context.Context, groupIDs []string) (count map[string]uint32, err error)
|
||||
//FindJoinUserID(ctx context.Context, groupIDs []string) (groupUsers map[string][]string, err error)
|
||||
FindUserJoinedGroupID(ctx context.Context, userID string) (groupIDs []string, err error)
|
||||
TakeGroupMemberNum(ctx context.Context, groupID string) (count int64, err error)
|
||||
FindUsersJoinedGroupID(ctx context.Context, userIDs []string) (map[string][]string, error)
|
||||
//FindUsersJoinedGroupID(ctx context.Context, userIDs []string) (map[string][]string, error)
|
||||
FindUserManagedGroupID(ctx context.Context, userID string) (groupIDs []string, err error)
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ package relation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/pagination"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -23,18 +24,32 @@ const (
|
||||
GroupRequestModelTableName = "group_requests"
|
||||
)
|
||||
|
||||
//type GroupRequestModel struct {
|
||||
// UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
// GroupID string `gorm:"column:group_id;primary_key;size:64"`
|
||||
// HandleResult int32 `gorm:"column:handle_result"`
|
||||
// ReqMsg string `gorm:"column:req_msg;size:1024"`
|
||||
// HandledMsg string `gorm:"column:handle_msg;size:1024"`
|
||||
// ReqTime time.Time `gorm:"column:req_time"`
|
||||
// HandleUserID string `gorm:"column:handle_user_id;size:64"`
|
||||
// HandledTime time.Time `gorm:"column:handle_time"`
|
||||
// JoinSource int32 `gorm:"column:join_source"`
|
||||
// InviterUserID string `gorm:"column:inviter_user_id;size:64"`
|
||||
// Ex string `gorm:"column:ex;size:1024"`
|
||||
//}
|
||||
|
||||
type GroupRequestModel struct {
|
||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
GroupID string `gorm:"column:group_id;primary_key;size:64"`
|
||||
HandleResult int32 `gorm:"column:handle_result"`
|
||||
ReqMsg string `gorm:"column:req_msg;size:1024"`
|
||||
HandledMsg string `gorm:"column:handle_msg;size:1024"`
|
||||
ReqTime time.Time `gorm:"column:req_time"`
|
||||
HandleUserID string `gorm:"column:handle_user_id;size:64"`
|
||||
HandledTime time.Time `gorm:"column:handle_time"`
|
||||
JoinSource int32 `gorm:"column:join_source"`
|
||||
InviterUserID string `gorm:"column:inviter_user_id;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
UserID string `bson:"user_id"`
|
||||
GroupID string `bson:"group_id"`
|
||||
HandleResult int32 `bson:"handle_result"`
|
||||
ReqMsg string `bson:"req_msg"`
|
||||
HandledMsg string `bson:"handled_msg"`
|
||||
ReqTime time.Time `bson:"req_time"`
|
||||
HandleUserID string `bson:"handle_user_id"`
|
||||
HandledTime time.Time `bson:"handled_time"`
|
||||
JoinSource int32 `bson:"join_source"`
|
||||
InviterUserID string `bson:"inviter_user_id"`
|
||||
Ex string `bson:"ex"`
|
||||
}
|
||||
|
||||
func (GroupRequestModel) TableName() string {
|
||||
@ -42,20 +57,12 @@ func (GroupRequestModel) TableName() string {
|
||||
}
|
||||
|
||||
type GroupRequestModelInterface interface {
|
||||
NewTx(tx any) GroupRequestModelInterface
|
||||
//NewTx(tx any) GroupRequestModelInterface
|
||||
Create(ctx context.Context, groupRequests []*GroupRequestModel) (err error)
|
||||
Delete(ctx context.Context, groupID string, userID string) (err error)
|
||||
UpdateHandler(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32) (err error)
|
||||
Take(ctx context.Context, groupID string, userID string) (groupRequest *GroupRequestModel, err error)
|
||||
FindGroupRequests(ctx context.Context, groupID string, userIDs []string) (int64, []*GroupRequestModel, error)
|
||||
Page(
|
||||
ctx context.Context,
|
||||
userID string,
|
||||
pageNumber, showNumber int32,
|
||||
) (total uint32, groups []*GroupRequestModel, err error)
|
||||
PageGroup(
|
||||
ctx context.Context,
|
||||
groupIDs []string,
|
||||
pageNumber, showNumber int32,
|
||||
) (total uint32, groups []*GroupRequestModel, err error)
|
||||
Page(ctx context.Context, userID string, pagination pagination.Pagination) (total int64, groups []*GroupRequestModel, err error)
|
||||
PageGroup(ctx context.Context, groupIDs []string, pagination pagination.Pagination) (total int64, groups []*GroupRequestModel, err error)
|
||||
}
|
||||
|
||||
@ -14,40 +14,40 @@
|
||||
|
||||
package unrelation
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const (
|
||||
CSuperGroup = "super_group"
|
||||
CUserToSuperGroup = "user_to_super_group"
|
||||
)
|
||||
|
||||
type SuperGroupModel struct {
|
||||
GroupID string `bson:"group_id" json:"groupID"`
|
||||
MemberIDs []string `bson:"member_id_list" json:"memberIDList"`
|
||||
}
|
||||
|
||||
func (SuperGroupModel) TableName() string {
|
||||
return CSuperGroup
|
||||
}
|
||||
|
||||
type UserToSuperGroupModel struct {
|
||||
UserID string `bson:"user_id" json:"userID"`
|
||||
GroupIDs []string `bson:"group_id_list" json:"groupIDList"`
|
||||
}
|
||||
|
||||
func (UserToSuperGroupModel) TableName() string {
|
||||
return CUserToSuperGroup
|
||||
}
|
||||
|
||||
type SuperGroupModelInterface interface {
|
||||
CreateSuperGroup(ctx context.Context, groupID string, initMemberIDs []string) error
|
||||
TakeSuperGroup(ctx context.Context, groupID string) (group *SuperGroupModel, err error)
|
||||
FindSuperGroup(ctx context.Context, groupIDs []string) (groups []*SuperGroupModel, err error)
|
||||
AddUserToSuperGroup(ctx context.Context, groupID string, userIDs []string) error
|
||||
RemoverUserFromSuperGroup(ctx context.Context, groupID string, userIDs []string) error
|
||||
GetSuperGroupByUserID(ctx context.Context, userID string) (*UserToSuperGroupModel, error)
|
||||
DeleteSuperGroup(ctx context.Context, groupID string) error
|
||||
RemoveGroupFromUser(ctx context.Context, groupID string, userIDs []string) error
|
||||
}
|
||||
//import (
|
||||
// "context"
|
||||
//)
|
||||
//
|
||||
//const (
|
||||
// CSuperGroup = "super_group"
|
||||
// CUserToSuperGroup = "user_to_super_group"
|
||||
//)
|
||||
//
|
||||
//type SuperGroupModel struct {
|
||||
// GroupID string `bson:"group_id" json:"groupID"`
|
||||
// MemberIDs []string `bson:"member_id_list" json:"memberIDList"`
|
||||
//}
|
||||
//
|
||||
//func (SuperGroupModel) TableName() string {
|
||||
// return CSuperGroup
|
||||
//}
|
||||
//
|
||||
//type UserToSuperGroupModel struct {
|
||||
// UserID string `bson:"user_id" json:"userID"`
|
||||
// GroupIDs []string `bson:"group_id_list" json:"groupIDList"`
|
||||
//}
|
||||
//
|
||||
//func (UserToSuperGroupModel) TableName() string {
|
||||
// return CUserToSuperGroup
|
||||
//}
|
||||
//
|
||||
//type SuperGroupModelInterface interface {
|
||||
// CreateSuperGroup(ctx context.Context, groupID string, initMemberIDs []string) error
|
||||
// TakeSuperGroup(ctx context.Context, groupID string) (group *SuperGroupModel, err error)
|
||||
// FindSuperGroup(ctx context.Context, groupIDs []string) (groups []*SuperGroupModel, err error)
|
||||
// AddUserToSuperGroup(ctx context.Context, groupID string, userIDs []string) error
|
||||
// RemoverUserFromSuperGroup(ctx context.Context, groupID string, userIDs []string) error
|
||||
// GetSuperGroupByUserID(ctx context.Context, userID string) (*UserToSuperGroupModel, error)
|
||||
// DeleteSuperGroup(ctx context.Context, groupID string) error
|
||||
// RemoveGroupFromUser(ctx context.Context, groupID string, userIDs []string) error
|
||||
//}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user