|
|
@ -16,7 +16,6 @@ package controller
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/dtm-labs/rockscache"
|
|
|
|
"github.com/dtm-labs/rockscache"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/pagination"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/pagination"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
@ -95,16 +94,24 @@ type groupDatabase struct {
|
|
|
|
cache cache.GroupCache
|
|
|
|
cache cache.GroupCache
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) FindGroupMemberUserID(ctx context.Context, groupID string) ([]string, error) {
|
|
|
|
func (g *groupDatabase) FindGroupMembers(ctx context.Context, groupID string, userIDs []string) ([]*relationtb.GroupMemberModel, error) {
|
|
|
|
return g.cache.GetGroupMemberIDs(ctx, groupID)
|
|
|
|
return g.cache.GetGroupMembersInfo(ctx, groupID, userIDs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) FindGroupMemberNum(ctx context.Context, groupID string) (uint32, error) {
|
|
|
|
func (g *groupDatabase) FindGroupMemberUser(ctx context.Context, groupIDs []string, userID string) ([]*relationtb.GroupMemberModel, error) {
|
|
|
|
num, err := g.cache.GetGroupMemberNum(ctx, groupID)
|
|
|
|
return g.cache.FindGroupMemberUser(ctx, groupIDs, userID)
|
|
|
|
if err != nil {
|
|
|
|
}
|
|
|
|
return 0, err
|
|
|
|
|
|
|
|
}
|
|
|
|
func (g *groupDatabase) FindGroupMemberRoleLevels(ctx context.Context, groupID string, roleLevels []int32) ([]*relationtb.GroupMemberModel, error) {
|
|
|
|
return uint32(num), nil
|
|
|
|
return g.cache.GetGroupRolesLevelMemberInfo(ctx, groupID, roleLevels)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) FindGroupMemberAll(ctx context.Context, groupID string) ([]*relationtb.GroupMemberModel, error) {
|
|
|
|
|
|
|
|
return g.cache.GetAllGroupMembersInfo(ctx, groupID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) FindGroupsOwner(ctx context.Context, groupIDs []string) ([]*relationtb.GroupMemberModel, error) {
|
|
|
|
|
|
|
|
return g.cache.GetGroupsOwner(ctx, groupIDs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) CreateGroup(ctx context.Context, groups []*relationtb.GroupModel, groupMembers []*relationtb.GroupMemberModel) error {
|
|
|
|
func (g *groupDatabase) CreateGroup(ctx context.Context, groups []*relationtb.GroupModel, groupMembers []*relationtb.GroupMemberModel) error {
|
|
|
@ -118,37 +125,48 @@ func (g *groupDatabase) CreateGroup(ctx context.Context, groups []*relationtb.Gr
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, group := range groups {
|
|
|
|
for _, group := range groups {
|
|
|
|
c = c.DelGroupsInfo(group.GroupID)
|
|
|
|
c = c.DelGroupsInfo(group.GroupID).
|
|
|
|
c = c.DelGroupMembersHash(group.GroupID)
|
|
|
|
DelGroupMembersHash(group.GroupID).
|
|
|
|
c = c.DelGroupsMemberNum(group.GroupID)
|
|
|
|
DelGroupMembersHash(group.GroupID).
|
|
|
|
c = c.DelGroupMemberIDs(group.GroupID)
|
|
|
|
DelGroupsMemberNum(group.GroupID).
|
|
|
|
|
|
|
|
DelGroupMemberIDs(group.GroupID).
|
|
|
|
|
|
|
|
DelGroupAllRoleLevel(group.GroupID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(groupMembers) > 0 {
|
|
|
|
if len(groupMembers) > 0 {
|
|
|
|
if err := g.groupMemberDB.Create(ctx, groupMembers); err != nil {
|
|
|
|
if err := g.groupMemberDB.Create(ctx, groupMembers); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
temp := make(map[string]struct{})
|
|
|
|
|
|
|
|
for _, groupMember := range groupMembers {
|
|
|
|
for _, groupMember := range groupMembers {
|
|
|
|
if _, ok := temp[groupMember.GroupID]; !ok {
|
|
|
|
c = c.DelGroupMembersHash(groupMember.GroupID).
|
|
|
|
temp[groupMember.GroupID] = struct{}{}
|
|
|
|
DelGroupsMemberNum(groupMember.GroupID).
|
|
|
|
c = c.DelGroupMembersHash(groupMember.GroupID)
|
|
|
|
DelGroupMemberIDs(groupMember.GroupID).
|
|
|
|
c = c.DelGroupsMemberNum(groupMember.GroupID)
|
|
|
|
DelJoinedGroupID(groupMember.UserID).
|
|
|
|
c = c.DelGroupMemberIDs(groupMember.GroupID)
|
|
|
|
DelGroupMembersInfo(groupMember.GroupID, groupMember.UserID).
|
|
|
|
}
|
|
|
|
DelGroupAllRoleLevel(groupMember.GroupID)
|
|
|
|
c = c.DelJoinedGroupID(groupMember.UserID)
|
|
|
|
|
|
|
|
c = c.DelGroupMembersInfo(groupMember.GroupID, groupMember.UserID)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return c.ExecDel(ctx)
|
|
|
|
return c.ExecDel(ctx, true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) TakeGroup(ctx context.Context, groupID string) (group *relationtb.GroupModel, err error) {
|
|
|
|
func (g *groupDatabase) FindGroupMemberUserID(ctx context.Context, groupID string) ([]string, error) {
|
|
|
|
|
|
|
|
return g.cache.GetGroupMemberIDs(ctx, groupID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) FindGroupMemberNum(ctx context.Context, groupID string) (uint32, error) {
|
|
|
|
|
|
|
|
num, err := g.cache.GetGroupMemberNum(ctx, groupID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return 0, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return uint32(num), nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) TakeGroup(ctx context.Context, groupID string) (*relationtb.GroupModel, error) {
|
|
|
|
return g.cache.GetGroupInfo(ctx, groupID)
|
|
|
|
return g.cache.GetGroupInfo(ctx, groupID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) FindGroup(ctx context.Context, groupIDs []string) (groups []*relationtb.GroupModel, err error) {
|
|
|
|
func (g *groupDatabase) FindGroup(ctx context.Context, groupIDs []string) ([]*relationtb.GroupModel, error) {
|
|
|
|
return g.cache.GetGroupsInfo(ctx, groupIDs)
|
|
|
|
return g.cache.GetGroupsInfo(ctx, groupIDs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -164,39 +182,36 @@ func (g *groupDatabase) UpdateGroup(ctx context.Context, groupID string, data ma
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) DismissGroup(ctx context.Context, groupID string, deleteMember bool) error {
|
|
|
|
func (g *groupDatabase) DismissGroup(ctx context.Context, groupID string, deleteMember bool) error {
|
|
|
|
cache := g.cache.NewCache()
|
|
|
|
return g.ctxTx.Transaction(ctx, func(ctx context.Context) error {
|
|
|
|
if err := g.tx.Transaction(func(tx any) error {
|
|
|
|
c := g.cache.NewCache()
|
|
|
|
if err := g.groupDB.NewTx(tx).UpdateStatus(ctx, groupID, constant.GroupStatusDismissed); err != nil {
|
|
|
|
if err := g.groupDB.UpdateState(ctx, groupID, constant.GroupStatusDismissed); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if deleteMember {
|
|
|
|
if deleteMember {
|
|
|
|
if err := g.groupMemberDB.NewTx(tx).DeleteGroup(ctx, []string{groupID}); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
userIDs, err := g.cache.GetGroupMemberIDs(ctx, groupID)
|
|
|
|
userIDs, err := g.cache.GetGroupMemberIDs(ctx, groupID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cache = cache.DelJoinedGroupID(userIDs...).DelGroupMemberIDs(groupID).DelGroupsMemberNum(groupID).DelGroupMembersHash(groupID)
|
|
|
|
if err := g.groupMemberDB.Delete(ctx, groupID, nil); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
c = c.DelJoinedGroupID(userIDs...).
|
|
|
|
|
|
|
|
DelGroupMemberIDs(groupID).
|
|
|
|
|
|
|
|
DelGroupsMemberNum(groupID).
|
|
|
|
|
|
|
|
DelGroupMembersHash(groupID).
|
|
|
|
|
|
|
|
DelGroupAllRoleLevel(groupID).
|
|
|
|
|
|
|
|
DelGroupMembersInfo(groupID, userIDs...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cache = cache.DelGroupsInfo(groupID)
|
|
|
|
return c.DelGroupsInfo(groupID).ExecDel(ctx)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return cache.ExecDel(ctx)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) TakeGroupMember(
|
|
|
|
func (g *groupDatabase) TakeGroupMember(ctx context.Context, groupID string, userID string) (*relationtb.GroupMemberModel, error) {
|
|
|
|
ctx context.Context,
|
|
|
|
|
|
|
|
groupID string,
|
|
|
|
|
|
|
|
userID string,
|
|
|
|
|
|
|
|
) (groupMember *relationtb.GroupMemberModel, err error) {
|
|
|
|
|
|
|
|
return g.cache.GetGroupMemberInfo(ctx, groupID, userID)
|
|
|
|
return g.cache.GetGroupMemberInfo(ctx, groupID, userID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) TakeGroupOwner(ctx context.Context, groupID string) (*relationtb.GroupMemberModel, error) {
|
|
|
|
func (g *groupDatabase) TakeGroupOwner(ctx context.Context, groupID string) (*relationtb.GroupMemberModel, error) {
|
|
|
|
return g.groupMemberDB.TakeOwner(ctx, groupID) // todo cache group owner
|
|
|
|
return g.cache.GetGroupOwner(ctx, groupID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) FindUserManagedGroupID(ctx context.Context, userID string) (groupIDs []string, err error) {
|
|
|
|
func (g *groupDatabase) FindUserManagedGroupID(ctx context.Context, userID string) (groupIDs []string, err error) {
|
|
|
@ -207,112 +222,57 @@ func (g *groupDatabase) PageGroupRequest(ctx context.Context, groupIDs []string,
|
|
|
|
return g.groupRequestDB.PageGroup(ctx, groupIDs, pagination)
|
|
|
|
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) {
|
|
|
|
func (g *groupDatabase) PageGetJoinGroup(ctx context.Context, userID string, pagination pagination.Pagination) (total int64, totalGroupMembers []*relationtb.GroupMemberModel, err error) {
|
|
|
|
if len(groupIDs) == 0 && len(roleLevels) == 0 && len(userIDs) == 1 {
|
|
|
|
|
|
|
|
gIDs, err := g.cache.GetJoinedGroupIDs(ctx, userIDs[0])
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var res []*relationtb.GroupMemberModel
|
|
|
|
|
|
|
|
for _, groupID := range gIDs {
|
|
|
|
|
|
|
|
v, err := g.cache.GetGroupMemberInfo(ctx, groupID, userIDs[0])
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
res = append(res, v)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(roleLevels) == 0 {
|
|
|
|
|
|
|
|
for _, groupID := range groupIDs {
|
|
|
|
|
|
|
|
groupMembers, err := g.cache.GetGroupMembersInfo(ctx, groupID, userIDs)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
totalGroupMembers = append(totalGroupMembers, groupMembers...)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return totalGroupMembers, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return g.groupMemberDB.Find(ctx, groupIDs, userIDs, roleLevels)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) PageGetJoinGroup(
|
|
|
|
|
|
|
|
ctx context.Context,
|
|
|
|
|
|
|
|
userID string,
|
|
|
|
|
|
|
|
pagination pagination.Pagination,
|
|
|
|
|
|
|
|
) (total int64, totalGroupMembers []*relationtb.GroupMemberModel, err error) {
|
|
|
|
|
|
|
|
groupIDs, err := g.cache.GetJoinedGroupIDs(ctx, userID)
|
|
|
|
groupIDs, err := g.cache.GetJoinedGroupIDs(ctx, userID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return 0, nil, err
|
|
|
|
return 0, nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, groupID := range utils.Paginate(groupIDs, int(pageNumber), int(showNumber)) {
|
|
|
|
for _, groupID := range utils.Paginate(groupIDs, int(pagination.GetPageNumber()), int(pagination.GetShowNumber())) {
|
|
|
|
groupMembers, err := g.cache.GetGroupMembersInfo(ctx, groupID, []string{userID})
|
|
|
|
groupMembers, err := g.cache.GetGroupMembersInfo(ctx, groupID, []string{userID})
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return 0, nil, err
|
|
|
|
return 0, nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
totalGroupMembers = append(totalGroupMembers, groupMembers...)
|
|
|
|
totalGroupMembers = append(totalGroupMembers, groupMembers...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return uint32(len(groupIDs)), totalGroupMembers, nil
|
|
|
|
return int64(len(groupIDs)), totalGroupMembers, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) PageGetGroupMember(
|
|
|
|
func (g *groupDatabase) PageGetGroupMember(ctx context.Context, groupID string, pagination pagination.Pagination) (total int64, totalGroupMembers []*relationtb.GroupMemberModel, err error) {
|
|
|
|
ctx context.Context,
|
|
|
|
|
|
|
|
groupID string,
|
|
|
|
|
|
|
|
pagination pagination.Pagination,
|
|
|
|
|
|
|
|
) (total int64, totalGroupMembers []*relationtb.GroupMemberModel, err error) {
|
|
|
|
|
|
|
|
groupMemberIDs, err := g.cache.GetGroupMemberIDs(ctx, groupID)
|
|
|
|
groupMemberIDs, err := g.cache.GetGroupMemberIDs(ctx, groupID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return 0, nil, err
|
|
|
|
return 0, nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pageIDs := utils.Paginate(groupMemberIDs, int(pageNumber), int(showNumber))
|
|
|
|
pageIDs := utils.Paginate(groupMemberIDs, int(pagination.GetPageNumber()), int(pagination.GetShowNumber()))
|
|
|
|
if len(pageIDs) == 0 {
|
|
|
|
if len(pageIDs) == 0 {
|
|
|
|
return uint32(len(groupMemberIDs)), nil, nil
|
|
|
|
return int64(len(groupMemberIDs)), nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
members, err := g.cache.GetGroupMembersInfo(ctx, groupID, pageIDs)
|
|
|
|
members, err := g.cache.GetGroupMembersInfo(ctx, groupID, pageIDs)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return 0, nil, err
|
|
|
|
return 0, nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return uint32(len(groupMemberIDs)), members, nil
|
|
|
|
return int64(len(groupMemberIDs)), members, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) SearchGroupMember(ctx context.Context, keyword string, groupID string, pagination pagination.Pagination) (int64, []*relationtb.GroupMemberModel, error) {
|
|
|
|
func (g *groupDatabase) SearchGroupMember(ctx context.Context, keyword string, groupID string, pagination pagination.Pagination) (int64, []*relationtb.GroupMemberModel, error) {
|
|
|
|
return g.groupMemberDB.SearchMember(ctx, keyword, groupIDs, userIDs, roleLevels, pagination)
|
|
|
|
return g.groupMemberDB.SearchMember(ctx, keyword, groupID, pagination)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) HandlerGroupRequest(
|
|
|
|
func (g *groupDatabase) HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relationtb.GroupMemberModel) error {
|
|
|
|
ctx context.Context,
|
|
|
|
return g.ctxTx.Transaction(ctx, func(ctx context.Context) error {
|
|
|
|
groupID string,
|
|
|
|
if err := g.groupRequestDB.UpdateHandler(ctx, groupID, userID, handledMsg, handleResult); err != nil {
|
|
|
|
userID string,
|
|
|
|
|
|
|
|
handledMsg string,
|
|
|
|
|
|
|
|
handleResult int32,
|
|
|
|
|
|
|
|
member *relationtb.GroupMemberModel,
|
|
|
|
|
|
|
|
) error {
|
|
|
|
|
|
|
|
//cache := g.cache.NewCache()
|
|
|
|
|
|
|
|
//if err := g.tx.Transaction(func(tx any) error {
|
|
|
|
|
|
|
|
// if err := g.groupRequestDB.NewTx(tx).UpdateHandler(ctx, groupID, userID, handledMsg, handleResult); err != nil {
|
|
|
|
|
|
|
|
// return err
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if member != nil {
|
|
|
|
|
|
|
|
// if err := g.groupMemberDB.NewTx(tx).Create(ctx, []*relationtb.GroupMemberModel{member}); err != nil {
|
|
|
|
|
|
|
|
// return err
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// cache = cache.DelGroupMembersHash(groupID).DelGroupMemberIDs(groupID).DelGroupsMemberNum(groupID).DelJoinedGroupID(member.UserID)
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return nil
|
|
|
|
|
|
|
|
//}); err != nil {
|
|
|
|
|
|
|
|
// return err
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//return cache.ExecDel(ctx)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return g.tx.Transaction(func(tx any) error {
|
|
|
|
|
|
|
|
if err := g.groupRequestDB.NewTx(tx).UpdateHandler(ctx, groupID, userID, handledMsg, handleResult); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if member != nil {
|
|
|
|
if member != nil {
|
|
|
|
if err := g.groupMemberDB.NewTx(tx).Create(ctx, []*relationtb.GroupMemberModel{member}); err != nil {
|
|
|
|
if err := g.groupMemberDB.Create(ctx, []*relationtb.GroupMemberModel{member}); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := g.cache.NewCache().DelGroupMembersHash(groupID).DelGroupMembersInfo(groupID, member.UserID).DelGroupMemberIDs(groupID).DelGroupsMemberNum(groupID).DelJoinedGroupID(member.UserID).ExecDel(ctx); err != nil {
|
|
|
|
c := g.cache.DelGroupMembersHash(groupID).
|
|
|
|
|
|
|
|
DelGroupMembersInfo(groupID, member.UserID).
|
|
|
|
|
|
|
|
DelGroupMemberIDs(groupID).
|
|
|
|
|
|
|
|
DelGroupsMemberNum(groupID).
|
|
|
|
|
|
|
|
DelJoinedGroupID(member.UserID).
|
|
|
|
|
|
|
|
DelGroupRoleLevel(groupID, []int32{member.RoleLevel})
|
|
|
|
|
|
|
|
if err := c.ExecDel(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -329,13 +289,11 @@ func (g *groupDatabase) DeleteGroupMember(ctx context.Context, groupID string, u
|
|
|
|
DelGroupsMemberNum(groupID).
|
|
|
|
DelGroupsMemberNum(groupID).
|
|
|
|
DelJoinedGroupID(userIDs...).
|
|
|
|
DelJoinedGroupID(userIDs...).
|
|
|
|
DelGroupMembersInfo(groupID, userIDs...).
|
|
|
|
DelGroupMembersInfo(groupID, userIDs...).
|
|
|
|
|
|
|
|
DelGroupAllRoleLevel(groupID).
|
|
|
|
ExecDel(ctx)
|
|
|
|
ExecDel(ctx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) MapGroupMemberUserID(
|
|
|
|
func (g *groupDatabase) MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string]*relationtb.GroupSimpleUserID, error) {
|
|
|
|
ctx context.Context,
|
|
|
|
|
|
|
|
groupIDs []string,
|
|
|
|
|
|
|
|
) (map[string]*relationtb.GroupSimpleUserID, error) {
|
|
|
|
|
|
|
|
return g.cache.GetGroupMemberHashMap(ctx, groupIDs)
|
|
|
|
return g.cache.GetGroupMemberHashMap(ctx, groupIDs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -352,62 +310,54 @@ func (g *groupDatabase) MapGroupMemberNum(ctx context.Context, groupIDs []string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string, roleLevel int32) error {
|
|
|
|
func (g *groupDatabase) TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string, roleLevel int32) error {
|
|
|
|
return g.tx.Transaction(func(tx any) error {
|
|
|
|
return g.ctxTx.Transaction(ctx, func(ctx context.Context) error {
|
|
|
|
rowsAffected, err := g.groupMemberDB.NewTx(tx).UpdateRoleLevel(ctx, groupID, oldOwnerUserID, roleLevel)
|
|
|
|
if err := g.groupMemberDB.UpdateRoleLevel(ctx, groupID, oldOwnerUserID, roleLevel); err != nil {
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if rowsAffected != 1 {
|
|
|
|
if err := g.groupMemberDB.UpdateRoleLevel(ctx, groupID, newOwnerUserID, constant.GroupOwner); err != nil {
|
|
|
|
return utils.Wrap(fmt.Errorf("oldOwnerUserID %s rowsAffected = %d", oldOwnerUserID, rowsAffected), "")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
rowsAffected, err = g.groupMemberDB.NewTx(tx).UpdateRoleLevel(ctx, groupID, newOwnerUserID, constant.GroupOwner)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if rowsAffected != 1 {
|
|
|
|
return g.cache.DelGroupMembersInfo(groupID, oldOwnerUserID, newOwnerUserID).
|
|
|
|
return utils.Wrap(fmt.Errorf("newOwnerUserID %s rowsAffected = %d", newOwnerUserID, rowsAffected), "")
|
|
|
|
DelGroupAllRoleLevel(groupID).
|
|
|
|
}
|
|
|
|
DelGroupMembersHash(groupID).ExecDel(ctx)
|
|
|
|
return g.cache.DelGroupMembersInfo(groupID, oldOwnerUserID, newOwnerUserID).DelGroupMembersHash(groupID).ExecDel(ctx)
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) UpdateGroupMember(
|
|
|
|
func (g *groupDatabase) UpdateGroupMember(ctx context.Context, groupID string, userID string, data map[string]any) error {
|
|
|
|
ctx context.Context,
|
|
|
|
|
|
|
|
groupID string,
|
|
|
|
|
|
|
|
userID string,
|
|
|
|
|
|
|
|
data map[string]any,
|
|
|
|
|
|
|
|
) error {
|
|
|
|
|
|
|
|
if err := g.groupMemberDB.Update(ctx, groupID, userID, data); err != nil {
|
|
|
|
if err := g.groupMemberDB.Update(ctx, groupID, userID, data); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return g.cache.DelGroupMembersInfo(groupID, userID).ExecDel(ctx)
|
|
|
|
c := g.cache.DelGroupMembersInfo(groupID, userID)
|
|
|
|
|
|
|
|
if g.groupMemberDB.IsUpdateRoleLevel(data) {
|
|
|
|
|
|
|
|
c = c.DelGroupAllRoleLevel(groupID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.ExecDel(ctx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) UpdateGroupMembers(ctx context.Context, data []*relationtb.BatchUpdateGroupMember) error {
|
|
|
|
func (g *groupDatabase) UpdateGroupMembers(ctx context.Context, data []*relationtb.BatchUpdateGroupMember) error {
|
|
|
|
cache := g.cache.NewCache()
|
|
|
|
return g.ctxTx.Transaction(ctx, func(ctx context.Context) error {
|
|
|
|
if err := g.tx.Transaction(func(tx any) error {
|
|
|
|
c := g.cache.NewCache()
|
|
|
|
for _, item := range data {
|
|
|
|
for _, item := range data {
|
|
|
|
if err := g.groupMemberDB.NewTx(tx).Update(ctx, item.GroupID, item.UserID, item.Map); err != nil {
|
|
|
|
if err := g.groupMemberDB.Update(ctx, item.GroupID, item.UserID, item.Map); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cache = cache.DelGroupMembersInfo(item.GroupID, item.UserID)
|
|
|
|
if g.groupMemberDB.IsUpdateRoleLevel(item.Map) {
|
|
|
|
|
|
|
|
c = c.DelGroupAllRoleLevel(item.GroupID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
c = c.DelGroupMembersInfo(item.GroupID, item.UserID).DelGroupMembersHash(item.GroupID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
return c.ExecDel(ctx, true)
|
|
|
|
}); err != nil {
|
|
|
|
})
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return cache.ExecDel(ctx)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) CreateGroupRequest(ctx context.Context, requests []*relationtb.GroupRequestModel) error {
|
|
|
|
func (g *groupDatabase) CreateGroupRequest(ctx context.Context, requests []*relationtb.GroupRequestModel) error {
|
|
|
|
return g.tx.Transaction(func(tx any) error {
|
|
|
|
return g.ctxTx.Transaction(ctx, func(ctx context.Context) error {
|
|
|
|
db := g.groupRequestDB.NewTx(tx)
|
|
|
|
|
|
|
|
for _, request := range requests {
|
|
|
|
for _, request := range requests {
|
|
|
|
if err := db.Delete(ctx, request.GroupID, request.UserID); err != nil {
|
|
|
|
if err := g.groupRequestDB.Delete(ctx, request.GroupID, request.UserID); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return db.Create(ctx, requests)
|
|
|
|
return g.groupRequestDB.Create(ctx, requests)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -419,12 +369,8 @@ func (g *groupDatabase) TakeGroupRequest(
|
|
|
|
return g.groupRequestDB.Take(ctx, groupID, userID)
|
|
|
|
return g.groupRequestDB.Take(ctx, groupID, userID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) PageGroupRequestUser(
|
|
|
|
func (g *groupDatabase) PageGroupRequestUser(ctx context.Context, userID string, pagination pagination.Pagination) (int64, []*relationtb.GroupRequestModel, error) {
|
|
|
|
ctx context.Context,
|
|
|
|
return g.groupRequestDB.Page(ctx, userID, pagination)
|
|
|
|
userID string,
|
|
|
|
|
|
|
|
pagination pagination.Pagination,
|
|
|
|
|
|
|
|
) (int64, []*relationtb.GroupRequestModel, error) {
|
|
|
|
|
|
|
|
return g.groupRequestDB.Page(ctx, userID, pageNumber, showNumber)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (g *groupDatabase) CountTotal(ctx context.Context, before *time.Time) (count int64, err error) {
|
|
|
|
func (g *groupDatabase) CountTotal(ctx context.Context, before *time.Time) (count int64, err error) {
|
|
|
@ -447,6 +393,5 @@ func (g *groupDatabase) DeleteGroupMemberHash(ctx context.Context, groupIDs []st
|
|
|
|
for _, groupID := range groupIDs {
|
|
|
|
for _, groupID := range groupIDs {
|
|
|
|
c = c.DelGroupMembersHash(groupID)
|
|
|
|
c = c.DelGroupMembersHash(groupID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return c.ExecDel(ctx)
|
|
|
|
return c.ExecDel(ctx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|