mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-19 00:09:02 +08:00
Merge remote-tracking branch 'origin/errcode' into errcode
# Conflicts: # go.mod # go.sum
This commit is contained in:
Vendored
+212
-42
@@ -1,10 +1,14 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/table"
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/dtm-labs/rockscache"
|
||||
"github.com/go-redis/redis/v8"
|
||||
"golang.org/x/tools/go/ssa/testdata/src/strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -26,61 +30,227 @@ func NewConversationRedis(rcClient *rockscache.Client) *ConversationRedis {
|
||||
return &ConversationRedis{rcClient: rcClient}
|
||||
}
|
||||
|
||||
func (c *ConversationRedis) GetUserConversationIDListFromCache(userID string, fn DBFun) ([]string, error) {
|
||||
conversationIDListStr, err := c.rcClient.Fetch(conversationIDListCache+userID, time.Second*30*60, fn)
|
||||
var conversationIDList []string
|
||||
err = json.Unmarshal([]byte(conversationIDListStr), &conversationIDList)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
return conversationIDList, nil
|
||||
func NewConversationCache(rdb redis.UniversalClient, conversationDB *relation.ConversationGorm, options rockscache.Options) *ConversationCache {
|
||||
return &ConversationCache{conversationDB: conversationDB, expireTime: conversationExpireTime, rcClient: rockscache.NewClient(rdb, options)}
|
||||
}
|
||||
|
||||
func (c *ConversationRedis) DelUserConversationIDListFromCache(userID string) error {
|
||||
return utils.Wrap(c.rcClient.TagAsDeleted(conversationIDListCache+userID), "DelUserConversationIDListFromCache err")
|
||||
func (c *ConversationCache) getConversationKey(ownerUserID, conversationID string) string {
|
||||
return conversationKey + ownerUserID + ":" + conversationID
|
||||
}
|
||||
|
||||
func (c *ConversationRedis) GetConversationFromCache(ownerUserID, conversationID string, fn DBFun) (*table.ConversationModel, error) {
|
||||
conversationStr, err := c.rcClient.Fetch(conversationCache+ownerUserID+":"+conversationID, time.Second*30*60, fn)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "Fetch failed")
|
||||
}
|
||||
conversation := table.ConversationModel{}
|
||||
err = json.Unmarshal([]byte(conversationStr), &conversation)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "Unmarshal failed")
|
||||
}
|
||||
return &conversation, nil
|
||||
func (c *ConversationCache) getConversationIDsKey(ownerUserID string) string {
|
||||
return conversationIDsKey + ownerUserID
|
||||
}
|
||||
|
||||
func (c *ConversationRedis) GetConversationsFromCache(ownerUserID string, conversationIDList []string, fn DBFun) ([]*table.ConversationModel, error) {
|
||||
var conversationList []*table.ConversationModel
|
||||
for _, conversationID := range conversationIDList {
|
||||
conversation, err := c.GetConversationFromCache(ownerUserID, conversationID, fn)
|
||||
func (c *ConversationCache) getRecvMsgOptKey(ownerUserID, conversationID string) string {
|
||||
return recvMsgOptKey + ownerUserID + ":" + conversationID
|
||||
}
|
||||
|
||||
func (c *ConversationCache) getSuperGroupRecvNotNotifyUserIDsKey(groupID string) string {
|
||||
return superGroupRecvMsgNotNotifyUserIDsKey + groupID
|
||||
}
|
||||
|
||||
func (c *ConversationCache) GetUserConversationIDs(ctx context.Context, ownerUserID string, f func(userID string) ([]string, error)) (conversationIDs []string, err error) {
|
||||
//getConversationIDs := func() (string, error) {
|
||||
// conversationIDs, err := relation.GetConversationIDsByUserID(ownerUserID)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// bytes, err := json.Marshal(conversationIDs)
|
||||
// if err != nil {
|
||||
// return "", utils.Wrap(err, "")
|
||||
// }
|
||||
// return string(bytes), nil
|
||||
//}
|
||||
//defer func() {
|
||||
// tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "conversationIDs", conversationIDs)
|
||||
//}()
|
||||
//conversationIDsStr, err := c.rcClient.Fetch(c.getConversationIDsKey(ownerUserID), time.Second*30*60, getConversationIDs)
|
||||
//err = json.Unmarshal([]byte(conversationIDsStr), &conversationIDs)
|
||||
//if err != nil {
|
||||
// return nil, utils.Wrap(err, "")
|
||||
//}
|
||||
//return conversationIDs, nil
|
||||
return GetCache(c.rcClient, c.getConversationIDsKey(ownerUserID), time.Second*30*60, func() ([]string, error) {
|
||||
return f(ownerUserID)
|
||||
})
|
||||
}
|
||||
|
||||
func (c *ConversationCache) GetUserConversationIDs1(ctx context.Context, ownerUserID string) (conversationIDs []string, err error) {
|
||||
//getConversationIDs := func() (string, error) {
|
||||
// conversationIDs, err := relation.GetConversationIDsByUserID(ownerUserID)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// bytes, err := json.Marshal(conversationIDs)
|
||||
// if err != nil {
|
||||
// return "", utils.Wrap(err, "")
|
||||
// }
|
||||
// return string(bytes), nil
|
||||
//}
|
||||
//defer func() {
|
||||
// tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "conversationIDs", conversationIDs)
|
||||
//}()
|
||||
//conversationIDsStr, err := c.rcClient.Fetch(c.getConversationIDsKey(ownerUserID), time.Second*30*60, getConversationIDs)
|
||||
//err = json.Unmarshal([]byte(conversationIDsStr), &conversationIDs)
|
||||
//if err != nil {
|
||||
// return nil, utils.Wrap(err, "")
|
||||
//}
|
||||
//return conversationIDs, nil
|
||||
return GetCache1[[]string](c.rcClient, c.getConversationIDsKey(ownerUserID), time.Second*30*60, fn)
|
||||
}
|
||||
|
||||
func GetCache1[T any](rcClient *rockscache.Client, key string, expire time.Duration, fn func() (any, error)) (T, error) {
|
||||
v, err := rcClient.Fetch(key, expire, func() (string, error) {
|
||||
v, err := fn()
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "GetConversationFromCache failed")
|
||||
return "", err
|
||||
}
|
||||
conversationList = append(conversationList, conversation)
|
||||
bs, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "")
|
||||
}
|
||||
return string(bs), nil
|
||||
})
|
||||
var t T
|
||||
if err != nil {
|
||||
return t, err
|
||||
}
|
||||
return conversationList, nil
|
||||
err = json.Unmarshal([]byte(v), &t)
|
||||
if err != nil {
|
||||
return t, utils.Wrap(err, "")
|
||||
}
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func (c *ConversationRedis) GetUserAllConversationList(ownerUserID string, fn DBFun) ([]*table.ConversationModel, error) {
|
||||
IDList, err := c.GetUserConversationIDListFromCache(ownerUserID, fn)
|
||||
func GetCache[T any](rcClient *rockscache.Client, key string, expire time.Duration, fn func() (T, error)) (T, error) {
|
||||
v, err := rcClient.Fetch(key, expire, func() (string, error) {
|
||||
v, err := fn()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
bs, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "")
|
||||
}
|
||||
return string(bs), nil
|
||||
})
|
||||
var t T
|
||||
if err != nil {
|
||||
return t, err
|
||||
}
|
||||
err = json.Unmarshal([]byte(v), &t)
|
||||
if err != nil {
|
||||
return t, utils.Wrap(err, "")
|
||||
}
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func (c *ConversationCache) DelUserConversationIDs(ctx context.Context, ownerUserID string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID)
|
||||
}()
|
||||
return utils.Wrap(c.rcClient.TagAsDeleted(c.getConversationIDsKey(ownerUserID)), "DelUserConversationIDs err")
|
||||
}
|
||||
|
||||
func (c *ConversationCache) GetConversation(ctx context.Context, ownerUserID, conversationID string) (conversation *relation2.ConversationModel, err error) {
|
||||
getConversation := func() (string, error) {
|
||||
conversation, err := relation.GetConversation(ownerUserID, conversationID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
bytes, err := json.Marshal(conversation)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "conversation Marshal failed")
|
||||
}
|
||||
return string(bytes), nil
|
||||
}
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "conversationID", conversationID, "conversation", *conversation)
|
||||
}()
|
||||
conversationStr, err := c.rcClient.Fetch(c.getConversationKey(ownerUserID, conversationID), c.expireTime, getConversation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var conversationList []*table.ConversationModel
|
||||
for _, conversationID := range IDList {
|
||||
conversation, err := c.GetConversationFromCache(ownerUserID, conversationID, fn)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "GetConversationFromCache failed")
|
||||
}
|
||||
conversationList = append(conversationList, conversation)
|
||||
}
|
||||
return conversationList, nil
|
||||
conversation = &relation2.ConversationModel{}
|
||||
err = json.Unmarshal([]byte(conversationStr), &conversation)
|
||||
return conversation, utils.Wrap(err, "Unmarshal failed")
|
||||
}
|
||||
|
||||
func (c *ConversationRedis) DelConversationFromCache(ownerUserID, conversationID string) error {
|
||||
return utils.Wrap(c.rcClient.TagAsDeleted(conversationCache+ownerUserID+":"+conversationID), "DelConversationFromCache err")
|
||||
func (c *ConversationCache) DelConversation(ctx context.Context, ownerUserID, conversationID string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "conversationID", conversationID)
|
||||
}()
|
||||
return utils.Wrap(c.rcClient.TagAsDeleted(c.getConversationKey(ownerUserID, conversationID)), "DelConversation err")
|
||||
}
|
||||
|
||||
func (c *ConversationCache) GetConversations(ctx context.Context, ownerUserID string, conversationIDs []string) (conversations []relation2.ConversationModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "conversationIDs", conversationIDs, "conversations", conversations)
|
||||
}()
|
||||
for _, conversationID := range conversationIDs {
|
||||
conversation, err := c.GetConversation(ctx, ownerUserID, conversationID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
conversations = append(conversations, *conversation)
|
||||
}
|
||||
return conversations, nil
|
||||
}
|
||||
|
||||
func (c *ConversationCache) GetUserAllConversations(ctx context.Context, ownerUserID string) (conversations []relation2.ConversationModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "conversations", conversations)
|
||||
}()
|
||||
IDs, err := c.GetUserConversationIDs(ctx, ownerUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var conversationIDs []relation2.ConversationModel
|
||||
for _, conversationID := range IDs {
|
||||
conversation, err := c.GetConversation(ctx, ownerUserID, conversationID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
conversationIDs = append(conversationIDs, *conversation)
|
||||
}
|
||||
return conversationIDs, nil
|
||||
}
|
||||
|
||||
func (c *ConversationCache) GetUserRecvMsgOpt(ctx context.Context, ownerUserID, conversationID string) (opt int, err error) {
|
||||
getConversation := func() (string, error) {
|
||||
conversation, err := relation.GetConversation(ownerUserID, conversationID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return strconv.Itoa(int(conversation.RecvMsgOpt)), nil
|
||||
}
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "conversationID", conversationID, "opt", opt)
|
||||
}()
|
||||
optStr, err := c.rcClient.Fetch(c.getConversationKey(ownerUserID, conversationID), c.expireTime, getConversation)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return strconv.Atoi(optStr)
|
||||
}
|
||||
|
||||
func (c *ConversationCache) DelUserRecvMsgOpt(ctx context.Context, ownerUserID, conversationID string) error {
|
||||
return utils.Wrap(c.rcClient.TagAsDeleted(c.getConversationKey(ownerUserID, conversationID)), "DelUserRecvMsgOpt failed")
|
||||
}
|
||||
|
||||
func (c *ConversationCache) GetSuperGroupRecvMsgNotNotifyUserIDs(ctx context.Context, groupID string) (userIDs []string, err error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (c *ConversationCache) DelSuperGroupRecvMsgNotNotifyUserIDs(ctx context.Context, groupID string) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ConversationCache) GetSuperGroupRecvMsgNotNotifyUserIDsHash(ctx context.Context, groupID string) (hash uint32, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (c *ConversationCache) DelSuperGroupRecvMsgNotNotifyUserIDsHash(ctx context.Context, groupID string) {
|
||||
return
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"github.com/dtm-labs/rockscache"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ExtendMsgSetCache struct {
|
||||
friendDB *relation.FriendGorm
|
||||
expireTime time.Duration
|
||||
rcClient *rockscache.Client
|
||||
}
|
||||
+422
-138
@@ -1,10 +1,13 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/cache"
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
relation2 "Open_IM/pkg/common/db/table/relation"
|
||||
unrelation2 "Open_IM/pkg/common/db/table/unrelation"
|
||||
"Open_IM/pkg/common/db/unrelation"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/dtm-labs/rockscache"
|
||||
_ "github.com/dtm-labs/rockscache"
|
||||
@@ -14,29 +17,43 @@ import (
|
||||
)
|
||||
|
||||
type GroupInterface interface {
|
||||
FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error)
|
||||
// group
|
||||
FindGroup(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error)
|
||||
SearchGroup(ctx context.Context, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error)
|
||||
TakeGroup(ctx context.Context, groupID string) (group *relation2.GroupModel, err error)
|
||||
FindJoinedGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error)
|
||||
UpdateGroup(ctx context.Context, groupID string, data map[string]any) error
|
||||
DismissGroup(ctx context.Context, groupID string) error // 解散群,并删除群成员
|
||||
// groupMember
|
||||
CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMember []*relation2.GroupMemberModel) error
|
||||
DeleteGroupByIDs(ctx context.Context, groupIDs []string) error
|
||||
TakeGroupByID(ctx context.Context, groupID string) (group *relation2.GroupModel, err error)
|
||||
TakeGroupMemberByID(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupModel, err error)
|
||||
GetJoinedGroupList(ctx context.Context, userID string) ([]*relation2.GroupModel, error)
|
||||
GetGroupMemberList(ctx context.Context, groupID string) ([]*relation2.GroupMemberModel, error)
|
||||
GetGroupMemberListByUserID(ctx context.Context, groupID string, userIDs []string) ([]*relation2.GroupMemberModel, error)
|
||||
GetGroupMemberFilterList(ctx context.Context, groupID string, filter int32, begin int32, maxNumber int32) ([]*relation2.GroupModel, error) // relation.GetGroupMemberByGroupID(req.GroupID, req.Filter, req.NextSeq, 30)
|
||||
FindGroupMembersByID(ctx context.Context, groupID string, userIDs []string) (groups []*relation2.GroupMemberModel, err error)
|
||||
DelGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
||||
GetGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error)
|
||||
GetGroupOwnerUserID(ctx context.Context, groupIDs []string) (map[string]string, error)
|
||||
GetGroupRecvApplicationList(ctx context.Context, userID string) ([]*relation2.GroupRequestModel, error)
|
||||
|
||||
TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupMemberModel, err error)
|
||||
FindGroupMember(ctx context.Context, groupID string, userIDs []string) ([]*relation2.GroupMemberModel, error)
|
||||
FindGroupMemberAll(ctx context.Context, groupID string) ([]*relation2.GroupMemberModel, error)
|
||||
FindGroupMemberFilterList(ctx context.Context, groupID string, filter int32, begin int32, maxNumber int32) ([]*relation2.GroupMemberModel, error) // relation.GetGroupMemberByGroupID(req.GroupID, req.Filter, req.NextSeq, 30)
|
||||
SearchGroupMember(ctx context.Context, groupID, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error)
|
||||
TakeGroupOwner(ctx context.Context, groupID string) (*relation2.GroupMemberModel, error)
|
||||
FindGroupOwnerUser(ctx context.Context, groupID []string) ([]*relation2.GroupMemberModel, error)
|
||||
CreateGroupMember(ctx context.Context, groupMember []*relation2.GroupMemberModel) error
|
||||
CreateGroupRequest(ctx context.Context, requests []*relation2.GroupRequestModel) error
|
||||
HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relation2.GroupMemberModel) error
|
||||
DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
||||
MapGroupHash(ctx context.Context, groupIDs []string) (map[string]uint64, error)
|
||||
MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error)
|
||||
MapGroupOwnerUserID(ctx context.Context, groupIDs []string) (map[string]string, error)
|
||||
TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string) error // 转让群
|
||||
UpdateGroupMember(ctx context.Context, groupID, userID string, data map[string]any) error
|
||||
|
||||
//mongo
|
||||
CreateGroupRequest(ctx context.Context, requests []*relation2.GroupRequestModel) error
|
||||
GetGroupRecvApplicationList(ctx context.Context, userID string) ([]*relation2.GroupRequestModel, error) // ?
|
||||
TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relation2.GroupRequestModel, error)
|
||||
FindUserGroupRequest(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupRequestModel, error)
|
||||
// superGroup
|
||||
TakeSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation2.SuperGroupModel, err error)
|
||||
CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error
|
||||
DelSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
||||
DeleteSuperGroup(ctx context.Context, groupID string) error
|
||||
DeleteSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
||||
AddUserToSuperGroup(ctx context.Context, groupID string, userIDs []string) error
|
||||
GetSuperGroupByID(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error)
|
||||
FindJoinSuperGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (total int32, groupIDs []string, err error)
|
||||
MapSuperGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error)
|
||||
}
|
||||
|
||||
var _ GroupInterface = (*GroupController)(nil)
|
||||
@@ -45,82 +62,112 @@ type GroupController struct {
|
||||
database GroupDataBaseInterface
|
||||
}
|
||||
|
||||
func (g *GroupController) TakeGroupMemberByID(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupModel, err error) {
|
||||
func (g *GroupController) FindGroup(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) FindGroupMembersByID(ctx context.Context, groupID string, userIDs []string) (groups []*relation2.GroupModel, err error) {
|
||||
func (g *GroupController) SearchGroup(ctx context.Context, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) DelGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
||||
func (g *GroupController) TakeGroup(ctx context.Context, groupID string) (group *relation2.GroupModel, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) GetGroupRecvApplicationList(ctx context.Context, userID string) ([]*relation2.GroupRequestModel, error) {
|
||||
/*
|
||||
var groupRequestList []db.GroupRequest
|
||||
memberList, err := GetGroupMemberListByUserID(userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range memberList {
|
||||
if v.RoleLevel > constant.GroupOrdinaryUsers {
|
||||
list, err := GetGroupRequestByGroupID(v.GroupID)
|
||||
if err != nil {
|
||||
// fmt.Println("111 GetGroupRequestByGroupID failed ", err.Error())
|
||||
continue
|
||||
}
|
||||
// fmt.Println("222 GetGroupRequestByGroupID ok ", list)
|
||||
groupRequestList = append(groupRequestList, list...)
|
||||
// fmt.Println("333 GetGroupRequestByGroupID ok ", groupRequestList)
|
||||
}
|
||||
}
|
||||
return groupRequestList, nil
|
||||
*/
|
||||
func (g *GroupController) FindJoinedGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) DelSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
||||
func (g *GroupController) UpdateGroup(ctx context.Context, groupID string, data map[string]any) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) GetJoinedGroupList(ctx context.Context, userID string) ([]*relation2.GroupModel, error) {
|
||||
func (g *GroupController) DismissGroup(ctx context.Context, groupID string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) GetGroupMemberList(ctx context.Context, groupID string) ([]*relation2.GroupModel, error) {
|
||||
func (g *GroupController) CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMember []*relation2.GroupMemberModel) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) GetGroupMemberListByUserID(ctx context.Context, groupID string, userIDs []string) ([]*relation2.GroupModel, error) {
|
||||
func (g *GroupController) TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupMemberModel, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) GetGroupMemberFilterList(ctx context.Context, groupID string, filter int32, begin int32, maxNumber int32) ([]*relation2.GroupModel, error) {
|
||||
func (g *GroupController) FindGroupMember(ctx context.Context, groupID string, userIDs []string) ([]*relation2.GroupMemberModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) GetGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error) {
|
||||
func (g *GroupController) FindGroupMemberAll(ctx context.Context, groupID string) ([]*relation2.GroupMemberModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) GetGroupOwnerUserID(ctx context.Context, groupIDs []string) (map[string]string, error) {
|
||||
func (g *GroupController) FindGroupMemberFilterList(ctx context.Context, groupID string, filter int32, begin int32, maxNumber int32) ([]*relation2.GroupMemberModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) CreateGroupMember(ctx context.Context, groupMember []*relation2.GroupModel) error {
|
||||
func (g *GroupController) SearchGroupMember(ctx context.Context, groupID, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) TakeGroupOwner(ctx context.Context, groupID string) (*relation2.GroupMemberModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) FindGroupOwnerUser(ctx context.Context, groupID []string) ([]*relation2.GroupMemberModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) CreateGroupMember(ctx context.Context, groupMember []*relation2.GroupMemberModel) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relation2.GroupMemberModel) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) MapGroupHash(ctx context.Context, groupIDs []string) (map[string]uint64, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) MapGroupOwnerUserID(ctx context.Context, groupIDs []string) (map[string]string, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) UpdateGroupMember(ctx context.Context, groupID, userID string, data map[string]any) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
@@ -130,49 +177,98 @@ func (g *GroupController) CreateGroupRequest(ctx context.Context, requests []*re
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) GetGroupRecvApplicationList(ctx context.Context, userID string) ([]*relation2.GroupRequestModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relation2.GroupRequestModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) FindUserGroupRequest(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupRequestModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) TakeSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation2.SuperGroupModel, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) DeleteSuperGroup(ctx context.Context, groupID string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) DeleteSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) AddUserToSuperGroup(ctx context.Context, groupID string, userIDs []string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func NewGroupController(db *gorm.DB, rdb redis.UniversalClient, mgoClient *mongo.Client) GroupInterface {
|
||||
groupController := &GroupController{database: newGroupDatabase(db, rdb, mgoClient)}
|
||||
return groupController
|
||||
func (g *GroupController) FindJoinSuperGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (total int32, groupIDs []string, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error) {
|
||||
return g.database.FindGroupsByID(ctx, groupIDs)
|
||||
}
|
||||
|
||||
func (g *GroupController) CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMember []*relation2.GroupModel) error {
|
||||
return g.database.CreateGroup(ctx, groups, groupMember)
|
||||
}
|
||||
|
||||
func (g *GroupController) DeleteGroupByIDs(ctx context.Context, groupIDs []string) error {
|
||||
return g.database.DeleteGroupByIDs(ctx, groupIDs)
|
||||
}
|
||||
|
||||
func (g *GroupController) TakeGroupByID(ctx context.Context, groupID string) (group *relation2.GroupModel, err error) {
|
||||
return g.database.TakeGroupByID(ctx, groupID)
|
||||
}
|
||||
|
||||
func (g *GroupController) GetSuperGroupByID(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error) {
|
||||
return g.database.GetSuperGroupByID(ctx, groupID)
|
||||
}
|
||||
|
||||
func (g *GroupController) CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error {
|
||||
return g.database.CreateSuperGroup(ctx, groupID, initMemberIDList)
|
||||
func (g *GroupController) MapSuperGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
type GroupDataBaseInterface interface {
|
||||
FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error)
|
||||
CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMember []*relation2.GroupModel) error
|
||||
DeleteGroupByIDs(ctx context.Context, groupIDs []string) error
|
||||
TakeGroupByID(ctx context.Context, groupID string) (group *relation2.GroupModel, err error)
|
||||
GetSuperGroupByID(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error)
|
||||
// group
|
||||
FindGroup(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error)
|
||||
SearchGroup(ctx context.Context, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error)
|
||||
TakeGroup(ctx context.Context, groupID string) (group *relation2.GroupModel, err error)
|
||||
FindJoinedGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error)
|
||||
UpdateGroup(ctx context.Context, groupID string, data map[string]any) error
|
||||
DismissGroup(ctx context.Context, groupID string) error // 解散群,并删除群成员
|
||||
// groupMember
|
||||
CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMember []*relation2.GroupMemberModel) error
|
||||
TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupMemberModel, err error)
|
||||
FindGroupMember(ctx context.Context, groupID string, userIDs []string) ([]*relation2.GroupMemberModel, error)
|
||||
FindGroupMemberAll(ctx context.Context, groupID string) ([]*relation2.GroupMemberModel, error)
|
||||
FindGroupMemberFilterList(ctx context.Context, groupID string, filter int32, begin int32, maxNumber int32) ([]*relation2.GroupMemberModel, error) // relation.GetGroupMemberByGroupID(req.GroupID, req.Filter, req.NextSeq, 30)
|
||||
SearchGroupMember(ctx context.Context, groupID, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error)
|
||||
TakeGroupOwner(ctx context.Context, groupID string) (*relation2.GroupMemberModel, error)
|
||||
FindGroupOwnerUser(ctx context.Context, groupID []string) ([]*relation2.GroupMemberModel, error)
|
||||
CreateGroupMember(ctx context.Context, groupMember []*relation2.GroupMemberModel) error
|
||||
HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relation2.GroupMemberModel) error
|
||||
DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
||||
MapGroupHash(ctx context.Context, groupIDs []string) (map[string]uint64, error)
|
||||
MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error)
|
||||
MapGroupOwnerUserID(ctx context.Context, groupIDs []string) (map[string]string, error)
|
||||
TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string) error // 转让群
|
||||
UpdateGroupMember(ctx context.Context, groupID, userID string, data map[string]any) error
|
||||
|
||||
CreateGroupRequest(ctx context.Context, requests []*relation2.GroupRequestModel) error
|
||||
GetGroupRecvApplicationList(ctx context.Context, userID string) ([]*relation2.GroupRequestModel, error) // ?
|
||||
TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relation2.GroupRequestModel, error)
|
||||
FindUserGroupRequest(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupRequestModel, error)
|
||||
// superGroup
|
||||
TakeSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation2.SuperGroupModel, err error)
|
||||
CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error
|
||||
DeleteSuperGroup(ctx context.Context, groupID string) error
|
||||
DeleteSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
||||
AddUserToSuperGroup(ctx context.Context, groupID string, userIDs []string) error
|
||||
FindJoinSuperGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (total int32, groupIDs []string, err error)
|
||||
MapSuperGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error)
|
||||
}
|
||||
|
||||
var _ *GroupDataBase = (GroupDataBaseInterface)(nil)
|
||||
|
||||
type GroupDataBase struct {
|
||||
groupDB *relation.GroupGorm
|
||||
groupMemberDB *relation.GroupMemberGorm
|
||||
@@ -205,82 +301,270 @@ func newGroupDatabase(db *gorm.DB, rdb redis.UniversalClient, mgoClient *mongo.C
|
||||
return database
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error) {
|
||||
return g.cache.GetGroupsInfo(ctx, groupIDs)
|
||||
//func (g *GroupDataBase) FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error) {
|
||||
// return g.cache.GetGroupsInfo(ctx, groupIDs)
|
||||
//}
|
||||
//
|
||||
//func (g *GroupDataBase) CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMembers []*relation2.GroupMemberModel) error {
|
||||
// return g.db.Transaction(func(tx *gorm.DB) error {
|
||||
// if len(groups) > 0 {
|
||||
// if err := g.groupDB.Create(ctx, groups, tx); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
// if len(groupMembers) > 0 {
|
||||
// if err := g.groupMemberDB.Create(ctx, groupMembers, tx); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
// return nil
|
||||
// })
|
||||
//}
|
||||
//
|
||||
//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 {
|
||||
return g.db.Transaction(func(tx *gorm.DB) error {
|
||||
if len(groups) > 0 {
|
||||
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
|
||||
}
|
||||
}
|
||||
if len(groupMembers) > 0 {
|
||||
if err := g.groupMemberDB.Create(ctx, groupMembers, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
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) 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) TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupMemberModel, err error) {
|
||||
return g.groupMemberDB.Take(ctx, groupID, userID)
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) TakeGroupByID(ctx context.Context, groupID string) (group *relation2.GroupModel, err error) {
|
||||
return g.cache.GetGroupInfo(ctx, groupID)
|
||||
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) 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) FindGroupMemberAll(ctx context.Context, groupID string) ([]*relation2.GroupMemberModel, error) {
|
||||
return g.groupMemberDB.FindGroupUser(ctx, []string{groupID}, nil, nil)
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) GetJoinedGroupList(ctx context.Context, userID string) ([]*relation2.GroupModel, error) {
|
||||
func (g *GroupDataBase) FindGroupMemberFilterList(ctx context.Context, groupID string, filter int32, begin int32, maxNumber int32) ([]*relation2.GroupMemberModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
func (g *GroupDataBase) SearchGroupMember(ctx context.Context, groupID string, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error) {
|
||||
return g.groupMemberDB.SearchMember(ctx, groupID, name, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) TakeGroupOwner(ctx context.Context, groupID string) (*relation2.GroupMemberModel, error) {
|
||||
return g.groupMemberDB.TakeOwner(ctx, groupID)
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) FindGroupOwnerUser(ctx context.Context, groupIDs []string) ([]*relation2.GroupMemberModel, error) {
|
||||
return g.groupMemberDB.FindGroupUser(ctx, groupIDs, nil, []int32{constant.GroupOwner})
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) CreateGroupMember(ctx context.Context, groupMember []*relation2.GroupMemberModel) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relation2.GroupMemberModel) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) MapGroupHash(ctx context.Context, groupIDs []string) (map[string]uint64, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) MapGroupOwnerUserID(ctx context.Context, groupIDs []string) (map[string]string, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) UpdateGroupMember(ctx context.Context, groupID, userID string, data map[string]any) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) CreateGroupRequest(ctx context.Context, requests []*relation2.GroupRequestModel) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) GetGroupRecvApplicationList(ctx context.Context, userID string) ([]*relation2.GroupRequestModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relation2.GroupRequestModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) FindUserGroupRequest(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupRequestModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) TakeSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation2.SuperGroupModel, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
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)
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) GetSuperGroupByID(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error) {
|
||||
return g.mongoDB.GetSuperGroup(ctx, groupID)
|
||||
func (g *GroupDataBase) DeleteSuperGroup(ctx context.Context, groupID string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) DeleteSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) AddUserToSuperGroup(ctx context.Context, groupID string, userIDs []string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) FindJoinSuperGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (total int32, groupIDs []string, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) MapSuperGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package localcache
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/proto/group"
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
@@ -27,12 +28,31 @@ func NewGroupMemberIDsLocalCache(rpc *grpc.ClientConn) GroupLocalCache {
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GroupLocalCache) GetGroupMemberIDs(ctx context.Context, groupID string) []string {
|
||||
func (g *GroupLocalCache) GetGroupMemberIDs(ctx context.Context, groupID string) ([]string, error) {
|
||||
g.lock.Lock()
|
||||
defer g.lock.Unlock()
|
||||
resp, err := g.group.GetGroupAbstractInfo(ctx, &group.GetGroupAbstractInfoReq{
|
||||
GroupIDs: nil,
|
||||
GroupIDs: []string{groupID},
|
||||
})
|
||||
if err != nil {
|
||||
return nil
|
||||
return nil, err
|
||||
}
|
||||
return []string{}
|
||||
if len(resp.GroupAbstractInfos) < 0 {
|
||||
return nil, constant.ErrGroupIDNotFound
|
||||
}
|
||||
localHashInfo, ok := g.cache[groupID]
|
||||
if ok && localHashInfo.memberListHash == resp.GroupAbstractInfos[0].GroupMemberListHash {
|
||||
return localHashInfo.userIDs, nil
|
||||
}
|
||||
groupMembersResp, err := g.group.GetGroupMemberList(ctx, &group.GetGroupMemberListReq{
|
||||
GroupID: groupID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
g.cache[groupID] = GroupMemberIDsHash{
|
||||
memberListHash: resp.GroupAbstractInfos[0].GroupMemberListHash,
|
||||
userIDs: groupMembersResp.Members,
|
||||
}
|
||||
return g.cache[groupID].userIDs, nil
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ package relation
|
||||
//
|
||||
//}
|
||||
//
|
||||
//func GetGroupMemberListByUserID(userID string) ([]GroupMember, error) {
|
||||
//func FindGroupMember(userID string) ([]GroupMember, error) {
|
||||
// var groupMemberList []GroupMember
|
||||
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("user_id=?", userID).Find(&groupMemberList).Error
|
||||
// if err != nil {
|
||||
@@ -167,7 +167,7 @@ package relation
|
||||
//}
|
||||
//
|
||||
//func GetJoinedGroupIDListByUserID(userID string) ([]string, error) {
|
||||
// memberList, err := GetGroupMemberListByUserID(userID)
|
||||
// memberList, err := FindGroupMember(userID)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
@@ -31,6 +31,13 @@ func (g *GroupMemberGorm) Delete(ctx context.Context, groupMembers []*relation.G
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Delete(groupMembers).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMemberGorm) DeleteGroup(ctx context.Context, groupIDs []string, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupIDs", groupIDs)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Where("group_id in (?)", groupIDs).Delete(&relation.GroupMemberModel{}).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMemberGorm) UpdateByMap(ctx context.Context, groupID string, userID string, args map[string]interface{}, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID, "args", args)
|
||||
@@ -54,6 +61,23 @@ func (g *GroupMemberGorm) Find(ctx context.Context, groupMembers []*relation.Gro
|
||||
return groupList, utils.Wrap(getDBConn(g.DB, tx).Where("(group_id, user_id) in ?", where).Find(&groupList).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMemberGorm) FindGroupUser(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32, tx ...*gorm.DB) (groupList []*relation.GroupMemberModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupIDs", groupIDs, "userIDs", userIDs, "groupList", groupList)
|
||||
}()
|
||||
db := getDBConn(g.DB, tx)
|
||||
if len(groupList) > 0 {
|
||||
db = db.Where("group_id in (?)", groupIDs)
|
||||
}
|
||||
if len(userIDs) > 0 {
|
||||
db = db.Where("user_id in (?)", userIDs)
|
||||
}
|
||||
if len(roleLevels) > 0 {
|
||||
db = db.Where("role_level in (?)", roleLevels)
|
||||
}
|
||||
return groupList, utils.Wrap(db.Find(&groupList).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMemberGorm) Take(ctx context.Context, groupID string, userID string, tx ...*gorm.DB) (groupMember *relation.GroupMemberModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID, "groupMember", *groupMember)
|
||||
@@ -62,7 +86,7 @@ func (g *GroupMemberGorm) Take(ctx context.Context, groupID string, userID strin
|
||||
return groupMember, utils.Wrap(getDBConn(g.DB, tx).Where("group_id = ? and user_id = ?", groupID, userID).Take(groupMember).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMemberGorm) TakeOwnerInfo(ctx context.Context, groupID string, tx ...*gorm.DB) (groupMember *relation.GroupMemberModel, err error) {
|
||||
func (g *GroupMemberGorm) TakeOwner(ctx context.Context, groupID string, tx ...*gorm.DB) (groupMember *relation.GroupMemberModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "groupMember", *groupMember)
|
||||
}()
|
||||
@@ -70,214 +94,16 @@ func (g *GroupMemberGorm) TakeOwnerInfo(ctx context.Context, groupID string, tx
|
||||
return groupMember, utils.Wrap(getDBConn(g.DB, tx).Where("group_id = ? and role_level = ?", groupID, constant.GroupOwner).Take(groupMember).Error, "")
|
||||
}
|
||||
|
||||
//func InsertIntoGroupMember(toInsertInfo GroupMemberModel) error {
|
||||
// toInsertInfo.JoinTime = time.Now()
|
||||
// if toInsertInfo.RoleLevel == 0 {
|
||||
// toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
|
||||
// }
|
||||
// toInsertInfo.MuteEndTime = time.Unix(int64(time.Now().Second()), 0)
|
||||
// err := GroupMemberDB.Table("group_members").Create(toInsertInfo).Error
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// return nil
|
||||
//}
|
||||
//
|
||||
//func BatchInsertIntoGroupMember(toInsertInfoList []*GroupMemberModel) error {
|
||||
// for _, toInsertInfo := range toInsertInfoList {
|
||||
// toInsertInfo.JoinTime = time.Now()
|
||||
// if toInsertInfo.RoleLevel == 0 {
|
||||
// toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
|
||||
// }
|
||||
// toInsertInfo.MuteEndTime = time.Unix(int64(time.Now().Second()), 0)
|
||||
// }
|
||||
// return GroupMemberDB.Create(toInsertInfoList).Error
|
||||
//
|
||||
//}
|
||||
//
|
||||
//func GetGroupMemberListByUserID(userID string) ([]GroupMemberModel, error) {
|
||||
// var groupMemberList []GroupMemberModel
|
||||
// err := GroupMemberDB.Table("group_members").Where("user_id=?", userID).Find(&groupMemberList).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return groupMemberList, nil
|
||||
//}
|
||||
//
|
||||
//func GetGroupMemberListByGroupID(groupID string) ([]GroupMemberModel, error) {
|
||||
// var groupMemberList []GroupMemberModel
|
||||
// err := GroupMemberDB.Table("group_members").Where("group_id=?", groupID).Find(&groupMemberList).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return groupMemberList, nil
|
||||
//}
|
||||
//
|
||||
//func GetGroupMemberIDListByGroupID(groupID string) ([]string, error) {
|
||||
// var groupMemberIDList []string
|
||||
// err := GroupMemberDB.Table("group_members").Where("group_id=?", groupID).Pluck("user_id", &groupMemberIDList).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return groupMemberIDList, nil
|
||||
//}
|
||||
//
|
||||
//func GetGroupMemberListByGroupIDAndRoleLevel(groupID string, roleLevel int32) ([]GroupMemberModel, error) {
|
||||
// var groupMemberList []GroupMemberModel
|
||||
// err := GroupMemberDB.Table("group_members").Where("group_id=? and role_level=?", groupID, roleLevel).Find(&groupMemberList).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return groupMemberList, nil
|
||||
//}
|
||||
//
|
||||
//func GetGroupMemberInfoByGroupIDAndUserID(groupID, userID string) (*GroupMemberModel, error) {
|
||||
// var groupMember GroupMemberModel
|
||||
// err := GroupMemberDB.Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Limit(1).Take(&groupMember).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return &groupMember, nil
|
||||
//}
|
||||
//
|
||||
//func DeleteGroupMemberByGroupIDAndUserID(groupID, userID string) error {
|
||||
// return GroupMemberDB.Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Delete(GroupMemberModel{}).Error
|
||||
//}
|
||||
//
|
||||
//func DeleteGroupMemberByGroupID(groupID string) error {
|
||||
// return GroupMemberDB.Table("group_members").Where("group_id=? ", groupID).Delete(GroupMemberModel{}).Error
|
||||
//}
|
||||
//
|
||||
//func UpdateGroupMemberInfo(groupMemberInfo GroupMemberModel) error {
|
||||
// return GroupMemberDB.Table("group_members").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Updates(&groupMemberInfo).Error
|
||||
//}
|
||||
//
|
||||
//func UpdateGroupMemberInfoByMap(groupMemberInfo GroupMemberModel, m map[string]interface{}) error {
|
||||
// return GroupMemberDB.Table("group_members").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Updates(m).Error
|
||||
//}
|
||||
//
|
||||
//func GetOwnerManagerByGroupID(groupID string) ([]GroupMemberModel, error) {
|
||||
// var groupMemberList []GroupMemberModel
|
||||
// err := GroupMemberDB.Table("group_members").Where("group_id=? and role_level>?", groupID, constant.GroupOrdinaryUsers).Find(&groupMemberList).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return groupMemberList, nil
|
||||
//}
|
||||
//
|
||||
//func GetGroupMemberNumByGroupID(groupID string) (int64, error) {
|
||||
// var number int64
|
||||
// err := GroupMemberDB.Table("group_members").Where("group_id=?", groupID).Count(&number).Error
|
||||
// if err != nil {
|
||||
// return 0, utils.Wrap(err, "")
|
||||
// }
|
||||
// return number, nil
|
||||
//}
|
||||
//
|
||||
//func GetGroupOwnerInfoByGroupID(groupID string) (*GroupMemberModel, error) {
|
||||
// omList, err := GetOwnerManagerByGroupID(groupID)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// for _, v := range omList {
|
||||
// if v.RoleLevel == constant.GroupOwner {
|
||||
// return &v, nil
|
||||
// }
|
||||
// }
|
||||
// return nil, utils.Wrap(constant.ErrGroupNoOwner, "")
|
||||
//}
|
||||
//
|
||||
//func IsExistGroupMember(groupID, userID string) bool {
|
||||
// var number int64
|
||||
// err := GroupMemberDB.Table("group_members").Where("group_id = ? and user_id = ?", groupID, userID).Count(&number).Error
|
||||
// if err != nil {
|
||||
// return false
|
||||
// }
|
||||
// if number != 1 {
|
||||
// return false
|
||||
// }
|
||||
// return true
|
||||
//}
|
||||
//
|
||||
//func CheckIsExistGroupMember(ctx context.Context, groupID, userID string) error {
|
||||
// var number int64
|
||||
// err := GroupMemberDB.Table("group_members").Where("group_id = ? and user_id = ?", groupID, userID).Count(&number).Error
|
||||
// if err != nil {
|
||||
// return constant.ErrDB.Wrap()
|
||||
// }
|
||||
// if number != 1 {
|
||||
// return constant.ErrData.Wrap()
|
||||
// }
|
||||
// return nil
|
||||
//}
|
||||
//
|
||||
//func GetGroupMemberByGroupID(groupID string, filter int32, begin int32, maxNumber int32) ([]GroupMember, error) {
|
||||
// var memberList []GroupMember
|
||||
// var err error
|
||||
// if filter >= 0 {
|
||||
// memberList, err = GetGroupMemberListByGroupIDAndRoleLevel(groupID, filter) //sorted by join time
|
||||
// } else {
|
||||
// memberList, err = GetGroupMemberListByGroupID(groupID)
|
||||
// }
|
||||
//
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// if begin >= int32(len(memberList)) {
|
||||
// return nil, nil
|
||||
// }
|
||||
//
|
||||
// var end int32
|
||||
// if begin+int32(maxNumber) < int32(len(memberList)) {
|
||||
// end = begin + maxNumber
|
||||
// } else {
|
||||
// end = int32(len(memberList))
|
||||
// }
|
||||
// return memberList[begin:end], nil
|
||||
//}
|
||||
//
|
||||
//func GetJoinedGroupIDListByUserID(userID string) ([]string, error) {
|
||||
// memberList, err := GetGroupMemberListByUserID(userID)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// var groupIDList []string
|
||||
// for _, v := range memberList {
|
||||
// groupIDList = append(groupIDList, v.GroupID)
|
||||
// }
|
||||
// return groupIDList, nil
|
||||
//}
|
||||
//
|
||||
//func IsGroupOwnerAdmin(groupID, UserID string) bool {
|
||||
// groupMemberList, err := GetOwnerManagerByGroupID(groupID)
|
||||
// if err != nil {
|
||||
// return false
|
||||
// }
|
||||
// for _, v := range groupMemberList {
|
||||
// if v.UserID == UserID && v.RoleLevel > constant.GroupOrdinaryUsers {
|
||||
// return true
|
||||
// }
|
||||
// }
|
||||
// return false
|
||||
//}
|
||||
//
|
||||
//func GetGroupMembersByGroupIdCMS(groupId string, userName string, showNumber, pageNumber int32) ([]GroupMember, error) {
|
||||
// var groupMembers []GroupMember
|
||||
// err := GroupMemberDB.Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groupMembers).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return groupMembers, nil
|
||||
//}
|
||||
//
|
||||
//func GetGroupMembersCount(groupID, userName string) (int64, error) {
|
||||
// var count int64
|
||||
// if err := GroupMemberDB.Table("group_members").Where("group_id=?", groupID).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Count(&count).Error; err != nil {
|
||||
// return count, err
|
||||
// }
|
||||
// return count, nil
|
||||
//}
|
||||
//
|
||||
//func UpdateGroupMemberInfoDefaultZero(groupMemberInfo GroupMember, args map[string]interface{}) error {
|
||||
// return GroupMemberDB.Model(groupMemberInfo).Updates(args).Error
|
||||
//}
|
||||
func (g *GroupMemberGorm) PageByUser(ctx context.Context, userID string, pageNumber, showNumber int32, tx ...*gorm.DB) (total int32, groupList []*relation.GroupMemberModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "total", total, "groupList", groupList)
|
||||
}()
|
||||
return gormPage[relation.GroupMemberModel](getDBConn(g.DB, tx).Where("user_id = ?", userID), pageNumber, showNumber)
|
||||
}
|
||||
|
||||
func (g *GroupMemberGorm) SearchMember(ctx context.Context, groupID string, name string, pageNumber, showNumber int32, tx ...*gorm.DB) (total int32, groupList []*relation.GroupMemberModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "name", name, "pageNumber", pageNumber, "showNumber", showNumber, "total", total, "groupList", groupList)
|
||||
}()
|
||||
return gormSearch[relation.GroupMemberModel](getDBConn(g.DB, tx).Where("group_id = ?", groupID), "nickname", name, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
@@ -30,20 +30,27 @@ func (g *GroupGorm) Delete(ctx context.Context, groupIDs []string, tx ...*gorm.D
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Where("group_id in (?)", groupIDs).Delete(&relation.GroupModel{}).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupGorm) UpdateByMap(ctx context.Context, groupID string, args map[string]interface{}, tx ...*gorm.DB) (err error) {
|
||||
func (g *GroupGorm) UpdateMap(ctx context.Context, groupID string, args map[string]interface{}, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Where("group_id = ?", groupID).Model(g).Updates(args).Error, "")
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Where("group_id = ?", groupID).Model(&relation.GroupModel{}).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupGorm) Update(ctx context.Context, groups []*relation.GroupModel, tx ...*gorm.DB) (err error) {
|
||||
func (g *GroupGorm) UpdateStatus(ctx context.Context, groupID string, status int32, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groups", groups)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "status", status)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Updates(&groups).Error, "")
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Where("group_id = ?", groupID).Model(&relation.GroupModel{}).Updates(map[string]any{"status": status}).Error, "")
|
||||
}
|
||||
|
||||
//func (g *GroupGorm) Update(ctx context.Context, groups []*relation.GroupModel, tx ...*gorm.DB) (err error) {
|
||||
// defer func() {
|
||||
// tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groups", groups)
|
||||
// }()
|
||||
// return utils.Wrap(getDBConn(g.DB, tx).Updates(&groups).Error, "")
|
||||
//}
|
||||
|
||||
func (g *GroupGorm) Find(ctx context.Context, groupIDs []string, tx ...*gorm.DB) (groups []*relation.GroupModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupIDs", groupIDs, "groups", groups)
|
||||
@@ -54,7 +61,14 @@ func (g *GroupGorm) Find(ctx context.Context, groupIDs []string, tx ...*gorm.DB)
|
||||
func (g *GroupGorm) Take(ctx context.Context, groupID string, tx ...*gorm.DB) (group *relation.GroupModel, err error) {
|
||||
group = &relation.GroupModel{}
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "group", *group)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "group", group)
|
||||
}()
|
||||
return group, utils.Wrap(getDBConn(g.DB, tx).Where("group_id = ?", groupID).Take(group).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupGorm) Search(ctx context.Context, name string, pageNumber, showNumber int32, tx ...*gorm.DB) (total int32, groups []*relation.GroupModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "name", name, "pageNumber", pageNumber, "showNumber", showNumber, "total", total, "groups", groups)
|
||||
}()
|
||||
return gormSearch[relation.GroupModel](getDBConn(g.DB, tx), "name", name, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ package relation
|
||||
//received
|
||||
//func GetRecvGroupApplicationList(userID string) ([]GroupRequest, error) {
|
||||
// var groupRequestList []GroupRequest
|
||||
// memberList, err := GetGroupMemberListByUserID(userID)
|
||||
// memberList, err := FindGroupMember(userID)
|
||||
// if err != nil {
|
||||
// return nil, utils.Wrap(err, utils.GetSelfFuncName())
|
||||
// }
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/utils"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func gormPage[E any](db *gorm.DB, pageNumber, showNumber int32) (int32, []*E, error) {
|
||||
var count int64
|
||||
if err := db.Model(new(E)).Count(&count).Error; err != nil {
|
||||
return 0, nil, utils.Wrap(err, "")
|
||||
}
|
||||
var es []*E
|
||||
if err := db.Limit(int(showNumber)).Offset(int(pageNumber * showNumber)).Find(&es).Error; err != nil {
|
||||
return 0, nil, utils.Wrap(err, "")
|
||||
}
|
||||
return int32(count), es, nil
|
||||
}
|
||||
|
||||
func gormSearch[E any](db *gorm.DB, field string, value string, pageNumber, showNumber int32) (int32, []*E, error) {
|
||||
if field != "" && value != "" {
|
||||
db = db.Where(field+" like ?", "%"+value+"%")
|
||||
}
|
||||
return gormPage[E](db, pageNumber, showNumber)
|
||||
}
|
||||
@@ -12,7 +12,7 @@ type GroupModel struct {
|
||||
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"`
|
||||
CreateTime time.Time `gorm:"column:create_time;index:create_time;autoCreateTime"`
|
||||
Ex string `gorm:"column:ex" json:"ex;size:1024" json:"ex"`
|
||||
Status int32 `gorm:"column:status"`
|
||||
CreatorUserID string `gorm:"column:creator_user_id;size:64"`
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package unrelation
|
||||
|
||||
import (
|
||||
commonPb "Open_IM/pkg/proto/sdk_ws"
|
||||
"context"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@@ -51,3 +53,17 @@ func (e *ExtendMsgSet) SplitSourceIDAndGetIndex() int32 {
|
||||
index, _ := strconv.Atoi(l[len(l)-1])
|
||||
return int32(index)
|
||||
}
|
||||
|
||||
type GetAllExtendMsgSetOpts struct {
|
||||
ExcludeExtendMsgs bool
|
||||
}
|
||||
|
||||
type ExtendMsgSetInterface interface {
|
||||
CreateExtendMsgSet(ctx context.Context, set *ExtendMsgSet) error
|
||||
GetAllExtendMsgSet(ctx context.Context, ID string, opts *GetAllExtendMsgSetOpts) (sets []*ExtendMsgSet, err error)
|
||||
GetExtendMsgSet(ctx context.Context, sourceID string, sessionType int32, maxMsgUpdateTime int64) (*ExtendMsgSet, error)
|
||||
InsertExtendMsg(ctx context.Context, sourceID string, sessionType int32, msg *ExtendMsg) error
|
||||
InsertOrUpdateReactionExtendMsgSet(ctx context.Context, sourceID string, sessionType int32, clientMsgID string, msgFirstModifyTime int64, reactionExtensionList map[string]*commonPb.KeyValue) error
|
||||
DeleteReactionExtendMsgSet(ctx context.Context, sourceID string, sessionType int32, clientMsgID string, msgFirstModifyTime int64, reactionExtensionList map[string]*commonPb.KeyValue) error
|
||||
GetExtendMsg(ctx context.Context, sourceID string, sessionType int32, clientMsgID string, maxMsgUpdateTime int64) (extendMsg *ExtendMsg, err error)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package unrelation
|
||||
|
||||
import "go.mongodb.org/mongo-driver/mongo"
|
||||
|
||||
const (
|
||||
CSuperGroup = "super_group"
|
||||
CUserToSuperGroup = "user_to_super_group"
|
||||
@@ -24,4 +26,5 @@ func (UserToSuperGroupModel) TableName() string {
|
||||
}
|
||||
|
||||
type SuperGroupModelInterface interface {
|
||||
CreateSuperGroup(sCtx mongo.SessionContext, groupID string, initMemberIDs []string) error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user