mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-08 11:05:59 +08:00
Merge remote-tracking branch 'origin/errcode' into errcode
# Conflicts: # pkg/common/db/cache/conversation.go # pkg/common/db/relation/conversation_model.go
This commit is contained in:
Vendored
+3
-3
@@ -2,7 +2,7 @@ package cache
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"Open_IM/pkg/common/db/table"
|
||||
relation2 "Open_IM/pkg/common/db/table/relation"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@@ -18,7 +18,7 @@ const (
|
||||
)
|
||||
|
||||
type BlackCache struct {
|
||||
blackDB *table.BlackModel
|
||||
blackDB *relation2.BlackModel
|
||||
expireTime time.Duration
|
||||
rcClient *rockscache.Client
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func (b *BlackCache) GetBlackIDs(ctx context.Context, userID string) (blackIDs [
|
||||
|
||||
func (b *BlackCache) DelBlackIDListFromCache(ctx context.Context, userID string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ctx", ctx)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID)
|
||||
}()
|
||||
return b.rcClient.TagAsDeleted(blackListCache + userID)
|
||||
}
|
||||
|
||||
Vendored
+3
-4
@@ -2,10 +2,9 @@ package cache
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"Open_IM/pkg/common/db/table"
|
||||
relation2 "Open_IM/pkg/common/db/table/relation"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/utils"
|
||||
"Open_IM/pkg/utilsv2"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/dtm-labs/rockscache"
|
||||
@@ -100,7 +99,7 @@ func (f *FriendCache) DelTwoWayFriendIDs(ctx context.Context, ownerUserID string
|
||||
return f.rcClient.TagAsDeleted(f.getTwoWayFriendsIDsKey(ownerUserID))
|
||||
}
|
||||
|
||||
func (f *FriendCache) GetFriend(ctx context.Context, ownerUserID, friendUserID string) (friend *table.FriendModel, err error) {
|
||||
func (f *FriendCache) GetFriend(ctx context.Context, ownerUserID, friendUserID string) (friend *relation2.FriendModel, err error) {
|
||||
getFriend := func() (string, error) {
|
||||
friend, err = f.friendDB.Take(ctx, ownerUserID, friendUserID)
|
||||
if err != nil {
|
||||
@@ -116,7 +115,7 @@ func (f *FriendCache) GetFriend(ctx context.Context, ownerUserID, friendUserID s
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
friend = &table.FriendModel{}
|
||||
friend = &relation2.FriendModel{}
|
||||
err = json.Unmarshal([]byte(friendStr), friend)
|
||||
return friend, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
Vendored
-2
@@ -37,8 +37,6 @@ type GroupCache struct {
|
||||
expireTime time.Duration
|
||||
redisClient *RedisClient
|
||||
rcClient *rockscache.Client
|
||||
|
||||
//local cache
|
||||
}
|
||||
|
||||
func NewGroupCache(rdb redis.UniversalClient, groupDB *relation.GroupGorm, groupMemberDB *relation.GroupMemberGorm, groupRequestDB *relation.GroupRequestGorm, mongoClient *unrelation.SuperGroupMongoDriver, opts rockscache.Options) *GroupCache {
|
||||
|
||||
Vendored
+5
-5
@@ -2,7 +2,7 @@ package cache
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"Open_IM/pkg/common/db/table"
|
||||
relation2 "Open_IM/pkg/common/db/table/relation"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@@ -44,7 +44,7 @@ func (u *UserCache) getUserGlobalRecvMsgOptKey(userID string) string {
|
||||
return userGlobalRecvMsgOptKey + userID
|
||||
}
|
||||
|
||||
func (u *UserCache) GetUserInfo(ctx context.Context, userID string) (userInfo *table.UserModel, err error) {
|
||||
func (u *UserCache) GetUserInfo(ctx context.Context, userID string) (userInfo *relation2.UserModel, err error) {
|
||||
getUserInfo := func() (string, error) {
|
||||
userInfo, err := u.userDB.Take(ctx, userID)
|
||||
if err != nil {
|
||||
@@ -63,13 +63,13 @@ func (u *UserCache) GetUserInfo(ctx context.Context, userID string) (userInfo *t
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
userInfo = &table.UserModel{}
|
||||
userInfo = &relation2.UserModel{}
|
||||
err = json.Unmarshal([]byte(userInfoStr), userInfo)
|
||||
return userInfo, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
func (u *UserCache) GetUsersInfo(ctx context.Context, userIDs []string) ([]*table.UserModel, error) {
|
||||
var users []*table.UserModel
|
||||
func (u *UserCache) GetUsersInfo(ctx context.Context, userIDs []string) ([]*relation2.UserModel, error) {
|
||||
var users []*relation2.UserModel
|
||||
for _, userID := range userIDs {
|
||||
user, err := GetUserInfoFromCache(ctx, userID)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/table"
|
||||
"Open_IM/pkg/common/db/table/relation"
|
||||
"context"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
@@ -9,11 +9,11 @@ import (
|
||||
|
||||
type BlackInterface interface {
|
||||
// Create 增加黑名单
|
||||
Create(ctx context.Context, blacks []*table.BlackModel) (err error)
|
||||
Create(ctx context.Context, blacks []*relation.BlackModel) (err error)
|
||||
// Delete 删除黑名单
|
||||
Delete(ctx context.Context, blacks []*table.BlackModel) (err error)
|
||||
Delete(ctx context.Context, blacks []*relation.BlackModel) (err error)
|
||||
// FindOwnerBlacks 获取黑名单列表
|
||||
FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*table.BlackModel, total int64, err error)
|
||||
FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*relation.BlackModel, total int64, err error)
|
||||
// CheckIn 检查user2是否在user1的黑名单列表中(inUser1Blacks==true) 检查user1是否在user2的黑名单列表中(inUser2Blacks==true)
|
||||
CheckIn(ctx context.Context, userID1, userID2 string) (inUser1Blacks bool, inUser2Blacks bool, err error)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package controller
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"Open_IM/pkg/common/db/table"
|
||||
relation2 "Open_IM/pkg/common/db/table/relation"
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -14,25 +14,25 @@ type FriendInterface interface {
|
||||
// AddFriendRequest 增加或者更新好友申请
|
||||
AddFriendRequest(ctx context.Context, fromUserID, toUserID string, reqMsg string, ex string) (err error)
|
||||
// BecomeFriend 先判断是否在好友表,如果在则不插入
|
||||
BecomeFriend(ctx context.Context, friends []*table.FriendModel, revFriends []*table.FriendModel) (err error)
|
||||
BecomeFriend(ctx context.Context, friends []*relation2.FriendModel, revFriends []*relation2.FriendModel) (err error)
|
||||
// RefuseFriendRequest 拒绝好友申请
|
||||
RefuseFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error)
|
||||
RefuseFriendRequest(ctx context.Context, friendRequest *relation2.FriendRequestModel) (err error)
|
||||
// AgreeFriendRequest 同意好友申请
|
||||
AgreeFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error)
|
||||
AgreeFriendRequest(ctx context.Context, friendRequest *relation2.FriendRequestModel) (err error)
|
||||
// Delete 删除好友
|
||||
Delete(ctx context.Context, ownerUserID string, friendUserIDs string) (err error)
|
||||
// UpdateRemark 更新好友备注
|
||||
UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error)
|
||||
// FindOwnerFriends 获取ownerUserID的好友列表
|
||||
FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*table.FriendModel, total int64, err error)
|
||||
FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*relation2.FriendModel, total int64, err error)
|
||||
// FindInWhoseFriends friendUserID在哪些人的好友列表中
|
||||
FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*table.FriendModel, total int64, err error)
|
||||
FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*relation2.FriendModel, total int64, err error)
|
||||
// FindFriendRequestFromMe 获取我发出去的好友申请
|
||||
FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*table.FriendRequestModel, total int64, err error)
|
||||
FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation2.FriendRequestModel, total int64, err error)
|
||||
// FindFriendRequestToMe 获取我收到的的好友申请
|
||||
FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*table.FriendRequestModel, total int64, err error)
|
||||
FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation2.FriendRequestModel, total int64, err error)
|
||||
// FindFriends 获取某人指定好友的信息 如果有一个不存在也返回错误
|
||||
FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*table.FriendModel, err error)
|
||||
FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*relation2.FriendModel, err error)
|
||||
}
|
||||
|
||||
type FriendController struct {
|
||||
@@ -52,15 +52,15 @@ func (f *FriendController) AddFriendRequest(ctx context.Context, fromUserID, toU
|
||||
}
|
||||
|
||||
// BecomeFriend 先判断是否在好友表,如果在则不插入
|
||||
func (f *FriendController) BecomeFriend(ctx context.Context, friends []*table.FriendModel) (err error) {
|
||||
func (f *FriendController) BecomeFriend(ctx context.Context, friends []*relation2.FriendModel) (err error) {
|
||||
}
|
||||
|
||||
// RefuseFriendRequest 拒绝好友申请
|
||||
func (f *FriendController) RefuseFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error) {
|
||||
func (f *FriendController) RefuseFriendRequest(ctx context.Context, friendRequest *relation2.FriendRequestModel) (err error) {
|
||||
}
|
||||
|
||||
// AgreeFriendRequest 同意好友申请
|
||||
func (f *FriendController) AgreeFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error) {
|
||||
func (f *FriendController) AgreeFriendRequest(ctx context.Context, friendRequest *relation2.FriendRequestModel) (err error) {
|
||||
}
|
||||
|
||||
// Delete 删除好友
|
||||
@@ -72,23 +72,23 @@ func (f *FriendController) UpdateRemark(ctx context.Context, ownerUserID, friend
|
||||
}
|
||||
|
||||
// FindOwnerFriends 获取ownerUserID的好友列表
|
||||
func (f *FriendController) FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*table.FriendModel, err error) {
|
||||
func (f *FriendController) FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*relation2.FriendModel, err error) {
|
||||
}
|
||||
|
||||
// FindInWhoseFriends friendUserID在哪些人的好友列表中
|
||||
func (f *FriendController) FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*table.FriendModel, err error) {
|
||||
func (f *FriendController) FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*relation2.FriendModel, err error) {
|
||||
}
|
||||
|
||||
// FindFriendRequestFromMe 获取我发出去的好友申请
|
||||
func (f *FriendController) FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*table.FriendRequestModel, err error) {
|
||||
func (f *FriendController) FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation2.FriendRequestModel, err error) {
|
||||
}
|
||||
|
||||
// FindFriendRequestToMe 获取我收到的的好友申请
|
||||
func (f *FriendController) FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*table.FriendRequestModel, err error) {
|
||||
func (f *FriendController) FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation2.FriendRequestModel, err error) {
|
||||
}
|
||||
|
||||
// FindFriends 获取某人指定好友的信息
|
||||
func (f *FriendController) FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*table.FriendModel, err error) {
|
||||
func (f *FriendController) FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*relation2.FriendModel, err error) {
|
||||
}
|
||||
|
||||
type FriendDatabaseInterface interface {
|
||||
@@ -97,25 +97,25 @@ type FriendDatabaseInterface interface {
|
||||
// AddFriendRequest 增加或者更新好友申请
|
||||
AddFriendRequest(ctx context.Context, fromUserID, toUserID string, reqMsg string, ex string) (err error)
|
||||
// BecomeFriend 先判断是否在好友表,如果在则不插入
|
||||
BecomeFriend(ctx context.Context, friends []*table.FriendModel) (err error)
|
||||
BecomeFriend(ctx context.Context, friends []*relation2.FriendModel) (err error)
|
||||
// RefuseFriendRequest 拒绝好友申请
|
||||
RefuseFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error)
|
||||
RefuseFriendRequest(ctx context.Context, friendRequest *relation2.FriendRequestModel) (err error)
|
||||
// AgreeFriendRequest 同意好友申请
|
||||
AgreeFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error)
|
||||
AgreeFriendRequest(ctx context.Context, friendRequest *relation2.FriendRequestModel) (err error)
|
||||
// Delete 删除好友
|
||||
Delete(ctx context.Context, ownerUserID string, friendUserIDs string) (err error)
|
||||
// UpdateRemark 更新好友备注
|
||||
UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error)
|
||||
// FindOwnerFriends 获取ownerUserID的好友列表
|
||||
FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*table.FriendModel, err error)
|
||||
FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*relation2.FriendModel, err error)
|
||||
// FindInWhoseFriends friendUserID在哪些人的好友列表中
|
||||
FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*table.FriendModel, err error)
|
||||
FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*relation2.FriendModel, err error)
|
||||
// FindFriendRequestFromMe 获取我发出去的好友申请
|
||||
FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*table.FriendRequestModel, err error)
|
||||
FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation2.FriendRequestModel, err error)
|
||||
// FindFriendRequestToMe 获取我收到的的好友申请
|
||||
FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*table.FriendRequestModel, err error)
|
||||
FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation2.FriendRequestModel, err error)
|
||||
// FindFriends 获取某人指定好友的信息
|
||||
FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*table.FriendModel, err error)
|
||||
FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*relation2.FriendModel, err error)
|
||||
}
|
||||
|
||||
type FriendDatabase struct {
|
||||
@@ -147,7 +147,7 @@ func (f *FriendDatabase) AddFriendRequest(ctx context.Context, fromUserID, toUse
|
||||
}
|
||||
|
||||
// BecomeFriend 先判断是否在好友表,如果在则不插入
|
||||
func (f *FriendDatabase) BecomeFriend(ctx context.Context, ownerUserID string, friends []*table.FriendModel) (err error) {
|
||||
func (f *FriendDatabase) BecomeFriend(ctx context.Context, ownerUserID string, friends []*relation2.FriendModel) (err error) {
|
||||
return f.friend.DB.Transaction(func(tx *gorm.DB) error {
|
||||
//先find 找出重复的 去掉重复的
|
||||
friendUserIDs := make([]string, 0, len(friends))
|
||||
@@ -169,11 +169,11 @@ func (f *FriendDatabase) BecomeFriend(ctx context.Context, ownerUserID string, f
|
||||
}
|
||||
|
||||
// RefuseFriendRequest 拒绝好友申请
|
||||
func (f *FriendDatabase) RefuseFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error) {
|
||||
func (f *FriendDatabase) RefuseFriendRequest(ctx context.Context, friendRequest *relation2.FriendRequestModel) (err error) {
|
||||
}
|
||||
|
||||
// AgreeFriendRequest 同意好友申请
|
||||
func (f *FriendDatabase) AgreeFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error) {
|
||||
func (f *FriendDatabase) AgreeFriendRequest(ctx context.Context, friendRequest *relation2.FriendRequestModel) (err error) {
|
||||
}
|
||||
|
||||
// Delete 删除好友
|
||||
@@ -185,23 +185,23 @@ func (f *FriendDatabase) UpdateRemark(ctx context.Context, ownerUserID, friendUs
|
||||
}
|
||||
|
||||
// FindOwnerFriends 获取ownerUserID的好友列表
|
||||
func (f *FriendDatabase) FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*table.FriendModel, err error) {
|
||||
func (f *FriendDatabase) FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*relation2.FriendModel, err error) {
|
||||
}
|
||||
|
||||
// FindInWhoseFriends friendUserID在哪些人的好友列表中
|
||||
func (f *FriendDatabase) FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*table.FriendModel, err error) {
|
||||
func (f *FriendDatabase) FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*relation2.FriendModel, err error) {
|
||||
}
|
||||
|
||||
// FindFriendRequestFromMe 获取我发出去的好友申请
|
||||
func (f *FriendDatabase) FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*table.FriendRequestModel, err error) {
|
||||
func (f *FriendDatabase) FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation2.FriendRequestModel, err error) {
|
||||
}
|
||||
|
||||
// FindFriendRequestToMe 获取我收到的的好友申请
|
||||
func (f *FriendDatabase) FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*table.FriendRequestModel, err error) {
|
||||
func (f *FriendDatabase) FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation2.FriendRequestModel, err error) {
|
||||
}
|
||||
|
||||
// FindFriends 获取某人指定好友的信息 如果有一个不存在也返回错误
|
||||
func (f *FriendDatabase) FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*table.FriendModel, err error) {
|
||||
func (f *FriendDatabase) FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*relation2.FriendModel, err error) {
|
||||
friends, err = f.friend.Find(ctx, ownerUserID, friendUserIDs)
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
@@ -3,7 +3,7 @@ package controller
|
||||
import (
|
||||
"Open_IM/pkg/common/db/cache"
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"Open_IM/pkg/common/db/table"
|
||||
relation2 "Open_IM/pkg/common/db/table/relation"
|
||||
"Open_IM/pkg/common/db/unrelation"
|
||||
"context"
|
||||
"github.com/dtm-labs/rockscache"
|
||||
@@ -14,23 +14,23 @@ import (
|
||||
)
|
||||
|
||||
type GroupInterface interface {
|
||||
FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*table.GroupModel, err error)
|
||||
CreateGroup(ctx context.Context, groups []*table.GroupModel, groupMember []*table.GroupMemberModel) error
|
||||
FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error)
|
||||
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 *table.GroupModel, err error)
|
||||
TakeGroupMemberByID(ctx context.Context, groupID string, userID string) (groupMember *table.GroupModel, err error)
|
||||
GetJoinedGroupList(ctx context.Context, userID string) ([]*table.GroupModel, error)
|
||||
GetGroupMemberList(ctx context.Context, groupID string) ([]*table.GroupMemberModel, error)
|
||||
GetGroupMemberListByUserID(ctx context.Context, groupID string, userIDs []string) ([]*table.GroupMemberModel, error)
|
||||
GetGroupMemberFilterList(ctx context.Context, groupID string, filter int32, begin int32, maxNumber int32) ([]*table.GroupModel, error) // relation.GetGroupMemberByGroupID(req.GroupID, req.Filter, req.NextSeq, 30)
|
||||
FindGroupMembersByID(ctx context.Context, groupID string, userIDs []string) (groups []*table.GroupMemberModel, err 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) ([]*table.GroupRequestModel, error)
|
||||
GetGroupRecvApplicationList(ctx context.Context, userID string) ([]*relation2.GroupRequestModel, error)
|
||||
|
||||
CreateGroupMember(ctx context.Context, groupMember []*table.GroupMemberModel) error
|
||||
CreateGroupRequest(ctx context.Context, requests []*table.GroupRequestModel) error
|
||||
CreateGroupMember(ctx context.Context, groupMember []*relation2.GroupMemberModel) error
|
||||
CreateGroupRequest(ctx context.Context, requests []*relation2.GroupRequestModel) error
|
||||
|
||||
//mongo
|
||||
CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error
|
||||
@@ -45,12 +45,12 @@ type GroupController struct {
|
||||
database GroupDataBaseInterface
|
||||
}
|
||||
|
||||
func (g *GroupController) TakeGroupMemberByID(ctx context.Context, groupID string, userID string) (groupMember *table.GroupModel, err error) {
|
||||
func (g *GroupController) TakeGroupMemberByID(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupModel, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) FindGroupMembersByID(ctx context.Context, groupID string, userIDs []string) (groups []*table.GroupModel, err error) {
|
||||
func (g *GroupController) FindGroupMembersByID(ctx context.Context, groupID string, userIDs []string) (groups []*relation2.GroupModel, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func (g *GroupController) DelGroupMember(ctx context.Context, groupID string, us
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) GetGroupRecvApplicationList(ctx context.Context, userID string) ([]*table.GroupRequestModel, error) {
|
||||
func (g *GroupController) GetGroupRecvApplicationList(ctx context.Context, userID string) ([]*relation2.GroupRequestModel, error) {
|
||||
/*
|
||||
var groupRequestList []db.GroupRequest
|
||||
memberList, err := GetGroupMemberListByUserID(userID)
|
||||
@@ -90,22 +90,22 @@ func (g *GroupController) DelSuperGroupMember(ctx context.Context, groupID strin
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) GetJoinedGroupList(ctx context.Context, userID string) ([]*table.GroupModel, error) {
|
||||
func (g *GroupController) GetJoinedGroupList(ctx context.Context, userID string) ([]*relation2.GroupModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) GetGroupMemberList(ctx context.Context, groupID string) ([]*table.GroupModel, error) {
|
||||
func (g *GroupController) GetGroupMemberList(ctx context.Context, groupID string) ([]*relation2.GroupModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) GetGroupMemberListByUserID(ctx context.Context, groupID string, userIDs []string) ([]*table.GroupModel, error) {
|
||||
func (g *GroupController) GetGroupMemberListByUserID(ctx context.Context, groupID string, userIDs []string) ([]*relation2.GroupModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) GetGroupMemberFilterList(ctx context.Context, groupID string, filter int32, begin int32, maxNumber int32) ([]*table.GroupModel, error) {
|
||||
func (g *GroupController) GetGroupMemberFilterList(ctx context.Context, groupID string, filter int32, begin int32, maxNumber int32) ([]*relation2.GroupModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
@@ -120,12 +120,12 @@ func (g *GroupController) GetGroupOwnerUserID(ctx context.Context, groupIDs []st
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) CreateGroupMember(ctx context.Context, groupMember []*table.GroupModel) error {
|
||||
func (g *GroupController) CreateGroupMember(ctx context.Context, groupMember []*relation2.GroupModel) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) CreateGroupRequest(ctx context.Context, requests []*table.GroupRequestModel) error {
|
||||
func (g *GroupController) CreateGroupRequest(ctx context.Context, requests []*relation2.GroupRequestModel) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
@@ -140,11 +140,11 @@ func NewGroupController(db *gorm.DB, rdb redis.UniversalClient, mgoClient *mongo
|
||||
return groupController
|
||||
}
|
||||
|
||||
func (g *GroupController) FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*table.GroupModel, err error) {
|
||||
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 []*table.GroupModel, groupMember []*table.GroupModel) error {
|
||||
func (g *GroupController) CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMember []*relation2.GroupModel) error {
|
||||
return g.database.CreateGroup(ctx, groups, groupMember)
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ func (g *GroupController) DeleteGroupByIDs(ctx context.Context, groupIDs []strin
|
||||
return g.database.DeleteGroupByIDs(ctx, groupIDs)
|
||||
}
|
||||
|
||||
func (g *GroupController) TakeGroupByID(ctx context.Context, groupID string) (group *table.GroupModel, err error) {
|
||||
func (g *GroupController) TakeGroupByID(ctx context.Context, groupID string) (group *relation2.GroupModel, err error) {
|
||||
return g.database.TakeGroupByID(ctx, groupID)
|
||||
}
|
||||
|
||||
@@ -165,10 +165,10 @@ func (g *GroupController) CreateSuperGroup(ctx context.Context, groupID string,
|
||||
}
|
||||
|
||||
type GroupDataBaseInterface interface {
|
||||
FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*table.GroupModel, err error)
|
||||
CreateGroup(ctx context.Context, groups []*table.GroupModel, groupMember []*table.GroupModel) error
|
||||
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 *table.GroupModel, err error)
|
||||
TakeGroupByID(ctx context.Context, groupID string) (group *relation2.GroupModel, err error)
|
||||
GetSuperGroupByID(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error)
|
||||
CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error
|
||||
}
|
||||
@@ -205,11 +205,11 @@ func newGroupDatabase(db *gorm.DB, rdb redis.UniversalClient, mgoClient *mongo.C
|
||||
return database
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*table.GroupModel, err error) {
|
||||
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 []*table.GroupModel, groupMembers []*table.GroupMemberModel) error {
|
||||
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 {
|
||||
@@ -237,11 +237,11 @@ func (g *GroupDataBase) DeleteGroupByIDs(ctx context.Context, groupIDs []string)
|
||||
})
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) TakeGroupByID(ctx context.Context, groupID string) (group *table.GroupModel, err error) {
|
||||
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 []*table.GroupModel) error {
|
||||
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
|
||||
@@ -257,7 +257,7 @@ func (g *GroupDataBase) Update(ctx context.Context, groups []*table.GroupModel)
|
||||
})
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) GetJoinedGroupList(ctx context.Context, userID string) ([]*table.GroupModel, error) {
|
||||
func (g *GroupDataBase) GetJoinedGroupList(ctx context.Context, userID string) ([]*relation2.GroupModel, error) {
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -3,26 +3,26 @@ package controller
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"Open_IM/pkg/common/db/table"
|
||||
relation2 "Open_IM/pkg/common/db/table/relation"
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UserInterface interface {
|
||||
//获取指定用户的信息 如果有记录未找到 也返回错误
|
||||
Find(ctx context.Context, userIDs []string) (users []*table.UserModel, err error)
|
||||
Find(ctx context.Context, userIDs []string) (users []*relation2.UserModel, err error)
|
||||
//插入
|
||||
Create(ctx context.Context, users []*table.UserModel) error
|
||||
Create(ctx context.Context, users []*relation2.UserModel) error
|
||||
//更新
|
||||
Update(ctx context.Context, users []*table.UserModel) (err error)
|
||||
Update(ctx context.Context, users []*relation2.UserModel) (err error)
|
||||
//更新带零值的
|
||||
UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error)
|
||||
//通过名字搜索
|
||||
GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*table.UserModel, count int64, err error)
|
||||
GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error)
|
||||
//通过名字和id搜索
|
||||
GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*table.UserModel, count int64, err error)
|
||||
GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error)
|
||||
//获取,如果没找到,不不返回错误
|
||||
Get(ctx context.Context, showNumber, pageNumber int32) (users []*table.UserModel, count int64, err error)
|
||||
Get(ctx context.Context, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error)
|
||||
//userIDs是否存在 只要有一个存在就为true
|
||||
IsExist(ctx context.Context, userIDs []string) (exist bool, err error)
|
||||
}
|
||||
@@ -31,29 +31,29 @@ type UserController struct {
|
||||
database UserDatabaseInterface
|
||||
}
|
||||
|
||||
func (u *UserController) Find(ctx context.Context, userIDs []string) (users []*table.UserModel, err error) {
|
||||
func (u *UserController) Find(ctx context.Context, userIDs []string) (users []*relation2.UserModel, err error) {
|
||||
return u.database.Find(ctx, userIDs)
|
||||
}
|
||||
func (u *UserController) Create(ctx context.Context, users []*table.UserModel) error {
|
||||
func (u *UserController) Create(ctx context.Context, users []*relation2.UserModel) error {
|
||||
return u.database.Create(ctx, users)
|
||||
}
|
||||
|
||||
func (u *UserController) Update(ctx context.Context, users []*table.UserModel) (err error) {
|
||||
func (u *UserController) Update(ctx context.Context, users []*relation2.UserModel) (err error) {
|
||||
return u.database.Update(ctx, users)
|
||||
}
|
||||
func (u *UserController) UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error) {
|
||||
return u.database.UpdateByMap(ctx, userID, args)
|
||||
}
|
||||
|
||||
func (u *UserController) GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*table.UserModel, count int64, err error) {
|
||||
func (u *UserController) GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error) {
|
||||
return u.database.GetByName(ctx, userName, showNumber, pageNumber)
|
||||
}
|
||||
|
||||
func (u *UserController) GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*table.UserModel, count int64, err error) {
|
||||
func (u *UserController) GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error) {
|
||||
return u.database.GetByNameAndID(ctx, content, showNumber, pageNumber)
|
||||
}
|
||||
|
||||
func (u *UserController) Get(ctx context.Context, showNumber, pageNumber int32) (users []*table.UserModel, count int64, err error) {
|
||||
func (u *UserController) Get(ctx context.Context, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error) {
|
||||
return u.database.Get(ctx, showNumber, pageNumber)
|
||||
}
|
||||
|
||||
@@ -66,13 +66,13 @@ func NewUserController(db *gorm.DB) *UserController {
|
||||
}
|
||||
|
||||
type UserDatabaseInterface interface {
|
||||
Find(ctx context.Context, userIDs []string) (users []*table.UserModel, err error)
|
||||
Create(ctx context.Context, users []*table.UserModel) error
|
||||
Update(ctx context.Context, users []*table.UserModel) (err error)
|
||||
Find(ctx context.Context, userIDs []string) (users []*relation2.UserModel, err error)
|
||||
Create(ctx context.Context, users []*relation2.UserModel) error
|
||||
Update(ctx context.Context, users []*relation2.UserModel) (err error)
|
||||
UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error)
|
||||
GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*table.UserModel, count int64, err error)
|
||||
GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*table.UserModel, count int64, err error)
|
||||
Get(ctx context.Context, showNumber, pageNumber int32) (users []*table.UserModel, count int64, err error)
|
||||
GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error)
|
||||
GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error)
|
||||
Get(ctx context.Context, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error)
|
||||
IsExist(ctx context.Context, userIDs []string) (exist bool, err error)
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ func newUserDatabase(db *gorm.DB) *UserDatabase {
|
||||
}
|
||||
|
||||
// 获取指定用户的信息 如果有记录未找到 也返回错误
|
||||
func (u *UserDatabase) Find(ctx context.Context, userIDs []string) (users []*table.UserModel, err error) {
|
||||
func (u *UserDatabase) Find(ctx context.Context, userIDs []string) (users []*relation2.UserModel, err error) {
|
||||
users, err = u.sqlDB.Find(ctx, userIDs)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -100,25 +100,25 @@ func (u *UserDatabase) Find(ctx context.Context, userIDs []string) (users []*tab
|
||||
return
|
||||
}
|
||||
|
||||
func (u *UserDatabase) Create(ctx context.Context, users []*table.UserModel) (err error) {
|
||||
func (u *UserDatabase) Create(ctx context.Context, users []*relation2.UserModel) (err error) {
|
||||
return u.sqlDB.Create(ctx, users)
|
||||
}
|
||||
|
||||
func (u *UserDatabase) Update(ctx context.Context, users []*table.UserModel) (err error) {
|
||||
func (u *UserDatabase) Update(ctx context.Context, users []*relation2.UserModel) (err error) {
|
||||
return u.sqlDB.Update(ctx, users)
|
||||
}
|
||||
func (u *UserDatabase) UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error) {
|
||||
return u.sqlDB.UpdateByMap(ctx, userID, args)
|
||||
}
|
||||
func (u *UserDatabase) GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*table.UserModel, count int64, err error) {
|
||||
func (u *UserDatabase) GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error) {
|
||||
return u.sqlDB.GetByName(ctx, userName, showNumber, pageNumber)
|
||||
}
|
||||
func (u *UserDatabase) GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*table.UserModel, count int64, err error) {
|
||||
func (u *UserDatabase) GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error) {
|
||||
return u.sqlDB.GetByNameAndID(ctx, content, showNumber, pageNumber)
|
||||
}
|
||||
|
||||
// 获取,如果没找到,不返回错误
|
||||
func (u *UserDatabase) Get(ctx context.Context, showNumber, pageNumber int32) (users []*table.UserModel, count int64, err error) {
|
||||
func (u *UserDatabase) Get(ctx context.Context, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error) {
|
||||
return u.sqlDB.Get(ctx, showNumber, pageNumber)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/table"
|
||||
"Open_IM/pkg/common/db/table/relation"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@@ -18,35 +18,35 @@ func NewBlackGorm(db *gorm.DB) *BlackGorm {
|
||||
return &black
|
||||
}
|
||||
|
||||
func (b *BlackGorm) Create(ctx context.Context, blacks []*table.BlackModel) (err error) {
|
||||
func (b *BlackGorm) Create(ctx context.Context, blacks []*relation.BlackModel) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "blacks", blacks)
|
||||
}()
|
||||
return utils.Wrap(b.DB.Model(&table.BlackModel{}).Create(&blacks).Error, "")
|
||||
return utils.Wrap(b.DB.Model(&relation.BlackModel{}).Create(&blacks).Error, "")
|
||||
}
|
||||
|
||||
func (b *BlackGorm) Delete(ctx context.Context, blacks []*table.BlackModel) (err error) {
|
||||
func (b *BlackGorm) Delete(ctx context.Context, blacks []*relation.BlackModel) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "blacks", blacks)
|
||||
}()
|
||||
return utils.Wrap(b.DB.Model(&table.BlackModel{}).Delete(blacks).Error, "")
|
||||
return utils.Wrap(b.DB.Model(&relation.BlackModel{}).Delete(blacks).Error, "")
|
||||
}
|
||||
|
||||
func (b *BlackGorm) UpdateByMap(ctx context.Context, ownerUserID, blockUserID string, args map[string]interface{}) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "blockUserID", blockUserID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(b.DB.Model(&table.BlackModel{}).Where("block_user_id = ? and block_user_id = ?", ownerUserID, blockUserID).Updates(args).Error, "")
|
||||
return utils.Wrap(b.DB.Model(&relation.BlackModel{}).Where("block_user_id = ? and block_user_id = ?", ownerUserID, blockUserID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (b *BlackGorm) Update(ctx context.Context, blacks []*table.BlackModel) (err error) {
|
||||
func (b *BlackGorm) Update(ctx context.Context, blacks []*relation.BlackModel) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "blacks", blacks)
|
||||
}()
|
||||
return utils.Wrap(b.DB.Model(&table.BlackModel{}).Updates(&blacks).Error, "")
|
||||
return utils.Wrap(b.DB.Model(&relation.BlackModel{}).Updates(&blacks).Error, "")
|
||||
}
|
||||
|
||||
func (b *BlackGorm) Find(ctx context.Context, blacks []*table.BlackModel) (blackList []*table.BlackModel, err error) {
|
||||
func (b *BlackGorm) Find(ctx context.Context, blacks []*relation.BlackModel) (blackList []*relation.BlackModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "blacks", blacks, "blackList", blackList)
|
||||
}()
|
||||
@@ -54,25 +54,25 @@ func (b *BlackGorm) Find(ctx context.Context, blacks []*table.BlackModel) (black
|
||||
for _, black := range blacks {
|
||||
where = append(where, []interface{}{black.OwnerUserID, black.BlockUserID})
|
||||
}
|
||||
return blackList, utils.Wrap(b.DB.Model(&table.BlackModel{}).Where("(owner_user_id, block_user_id) in ?", where).Find(&blackList).Error, "")
|
||||
return blackList, utils.Wrap(b.DB.Model(&relation.BlackModel{}).Where("(owner_user_id, block_user_id) in ?", where).Find(&blackList).Error, "")
|
||||
}
|
||||
|
||||
func (b *BlackGorm) Take(ctx context.Context, ownerUserID, blockUserID string) (black *table.BlackModel, err error) {
|
||||
black = &table.BlackModel{}
|
||||
func (b *BlackGorm) Take(ctx context.Context, ownerUserID, blockUserID string) (black *relation.BlackModel, err error) {
|
||||
black = &relation.BlackModel{}
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "blockUserID", blockUserID, "black", *black)
|
||||
}()
|
||||
return black, utils.Wrap(b.DB.Model(&table.BlackModel{}).Where("owner_user_id = ? and block_user_id = ?", ownerUserID, blockUserID).Take(black).Error, "")
|
||||
return black, utils.Wrap(b.DB.Model(&relation.BlackModel{}).Where("owner_user_id = ? and block_user_id = ?", ownerUserID, blockUserID).Take(black).Error, "")
|
||||
}
|
||||
|
||||
func (b *BlackGorm) FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*table.BlackModel, total int64, err error) {
|
||||
func (b *BlackGorm) FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*relation.BlackModel, total int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "blacks", blacks)
|
||||
}()
|
||||
err = b.DB.Model(&table.BlackModel{}).Model(b).Count(&total).Error
|
||||
err = b.DB.Model(&relation.BlackModel{}).Model(b).Count(&total).Error
|
||||
if err != nil {
|
||||
return nil, 0, utils.Wrap(err, "")
|
||||
}
|
||||
err = utils.Wrap(b.DB.Model(&table.BlackModel{}).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&blacks).Error, "")
|
||||
err = utils.Wrap(b.DB.Model(&relation.BlackModel{}).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&blacks).Error, "")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package relation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/table"
|
||||
"Open_IM/pkg/common/db/table/relation"
|
||||
pbMsg "Open_IM/pkg/proto/msg"
|
||||
server_api_params "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
@@ -22,7 +22,7 @@ func NewChatLog(db *gorm.DB) *ChatLogGorm {
|
||||
}
|
||||
|
||||
func (c *ChatLogGorm) Create(msg pbMsg.MsgDataToMQ) error {
|
||||
chatLog := new(table.ChatLogModel)
|
||||
chatLog := new(relation.ChatLogModel)
|
||||
copier.Copy(chatLog, msg.MsgData)
|
||||
switch msg.MsgData.SessionType {
|
||||
case constant.GroupChatType, constant.SuperGroupChatType:
|
||||
@@ -47,7 +47,7 @@ func (c *ChatLogGorm) Create(msg pbMsg.MsgDataToMQ) error {
|
||||
return c.DB.Create(chatLog).Error
|
||||
}
|
||||
|
||||
func (c *ChatLogGorm) GetChatLog(chatLog *table.ChatLogModel, pageNumber, showNumber int32, contentTypeList []int32) (int64, []ChatLogModel, error) {
|
||||
func (c *ChatLogGorm) GetChatLog(chatLog *relation.ChatLogModel, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relation.ChatLogModel, error) {
|
||||
mdb := c.DB.Model(chatLog)
|
||||
if chatLog.SendTime.Unix() > 0 {
|
||||
mdb = mdb.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
|
||||
@@ -76,7 +76,7 @@ func (c *ChatLogGorm) GetChatLog(chatLog *table.ChatLogModel, pageNumber, showNu
|
||||
if err := mdb.Count(&count).Error; err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
var chatLogs []table.ChatLogModel
|
||||
var chatLogs []relation.ChatLogModel
|
||||
mdb = mdb.Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1)))
|
||||
if err := mdb.Find(&chatLogs).Error; err != nil {
|
||||
return 0, nil, err
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/table"
|
||||
"Open_IM/pkg/common/db/table/relation"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@@ -9,12 +9,12 @@ import (
|
||||
)
|
||||
|
||||
type FriendDB interface {
|
||||
Create(ctx context.Context, friends []*table.FriendModel) (err error)
|
||||
Create(ctx context.Context, friends []*relation.FriendModel) (err error)
|
||||
Delete(ctx context.Context, ownerUserID string, friendUserIDs string) (err error)
|
||||
UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error)
|
||||
Update(ctx context.Context, friends []*table.FriendModel) (err error)
|
||||
Update(ctx context.Context, friends []*relation.FriendModel) (err error)
|
||||
UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error)
|
||||
FindOwnerUserID(ctx context.Context, ownerUserID string) (friends []*table.FriendModel, err error)
|
||||
FindOwnerUserID(ctx context.Context, ownerUserID string) (friends []*relation.FriendModel, err error)
|
||||
}
|
||||
|
||||
type FriendGorm struct {
|
||||
@@ -30,18 +30,18 @@ type FriendUser struct {
|
||||
Nickname string `gorm:"column:name;size:255"`
|
||||
}
|
||||
|
||||
func (f *FriendGorm) Create(ctx context.Context, friends []*table.FriendModel, tx ...*gorm.DB) (err error) {
|
||||
func (f *FriendGorm) Create(ctx context.Context, friends []*relation.FriendModel, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(f.DB, tx).Model(&table.FriendModel{}).Create(&friends).Error, "")
|
||||
return utils.Wrap(getDBConn(f.DB, tx).Model(&relation.FriendModel{}).Create(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendGorm) Delete(ctx context.Context, ownerUserID string, friendUserIDs string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserIDs", friendUserIDs)
|
||||
}()
|
||||
err = utils.Wrap(f.DB.Model(&table.FriendModel{}).Where("owner_user_id = ? and friend_user_id = ?", ownerUserID, friendUserIDs).Delete(&table.FriendModel{}).Error, "")
|
||||
err = utils.Wrap(f.DB.Model(&relation.FriendModel{}).Where("owner_user_id = ? and friend_user_id = ?", ownerUserID, friendUserIDs).Delete(&relation.FriendModel{}).Error, "")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -49,52 +49,52 @@ func (f *FriendGorm) UpdateByMap(ctx context.Context, ownerUserID string, args m
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(f.DB.Model(&table.FriendModel{}).Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
|
||||
return utils.Wrap(f.DB.Model(&relation.FriendModel{}).Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendGorm) Update(ctx context.Context, friends []*table.FriendModel, tx ...*gorm.DB) (err error) {
|
||||
func (f *FriendGorm) Update(ctx context.Context, friends []*relation.FriendModel, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
}()
|
||||
return utils.Wrap(f.DB.Model(&table.FriendModel{}).Updates(&friends).Error, "")
|
||||
return utils.Wrap(f.DB.Model(&relation.FriendModel{}).Updates(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendGorm) UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserID", friendUserID, "remark", remark)
|
||||
}()
|
||||
return utils.Wrap(f.DB.Model(&table.FriendModel{}).Where("owner_user_id = ? and friend_user_id = ?", ownerUserID, friendUserID).Update("remark", remark).Error, "")
|
||||
return utils.Wrap(f.DB.Model(&relation.FriendModel{}).Where("owner_user_id = ? and friend_user_id = ?", ownerUserID, friendUserID).Update("remark", remark).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendGorm) FindOwnerUserID(ctx context.Context, ownerUserID string) (friends []*table.FriendModel, err error) {
|
||||
func (f *FriendGorm) FindOwnerUserID(ctx context.Context, ownerUserID string) (friends []*relation.FriendModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friends", friends)
|
||||
}()
|
||||
return friends, utils.Wrap(f.DB.Model(&table.FriendModel{}).Where("owner_user_id = ?", ownerUserID).Find(&friends).Error, "")
|
||||
return friends, utils.Wrap(f.DB.Model(&relation.FriendModel{}).Where("owner_user_id = ?", ownerUserID).Find(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendGorm) FindFriendUserID(ctx context.Context, friendUserID string) (friends []*table.FriendModel, err error) {
|
||||
func (f *FriendGorm) FindFriendUserID(ctx context.Context, friendUserID string) (friends []*relation.FriendModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friendUserID", friendUserID, "friends", friends)
|
||||
}()
|
||||
return friends, utils.Wrap(f.DB.Model(&table.FriendModel{}).Where("friend_user_id = ?", friendUserID).Find(&friends).Error, "")
|
||||
return friends, utils.Wrap(f.DB.Model(&relation.FriendModel{}).Where("friend_user_id = ?", friendUserID).Find(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendGorm) Take(ctx context.Context, ownerUserID, friendUserID string) (friend *table.FriendModel, err error) {
|
||||
friend = &table.FriendModel{}
|
||||
func (f *FriendGorm) Take(ctx context.Context, ownerUserID, friendUserID string) (friend *relation.FriendModel, err error) {
|
||||
friend = &relation.FriendModel{}
|
||||
defer tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserID", friendUserID, "friend", friend)
|
||||
return friend, utils.Wrap(f.DB.Model(&table.FriendModel{}).Where("owner_user_id = ? and friend_user_id", ownerUserID, friendUserID).Take(friend).Error, "")
|
||||
return friend, utils.Wrap(f.DB.Model(&relation.FriendModel{}).Where("owner_user_id = ? and friend_user_id", ownerUserID, friendUserID).Take(friend).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendGorm) FindUserState(ctx context.Context, userID1, userID2 string) (friends []*table.FriendModel, err error) {
|
||||
func (f *FriendGorm) FindUserState(ctx context.Context, userID1, userID2 string) (friends []*relation.FriendModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "userID1", userID1, "userID2", userID2)
|
||||
}()
|
||||
return friends, utils.Wrap(f.DB.Model(&table.FriendModel{}).Where("(owner_user_id = ? and friend_user_id = ?) or (owner_user_id = ? and friend_user_id = ?)", userID1, userID2, userID2, userID1).Find(&friends).Error, "")
|
||||
return friends, utils.Wrap(f.DB.Model(&relation.FriendModel{}).Where("(owner_user_id = ? and friend_user_id = ?) or (owner_user_id = ? and friend_user_id = ?)", userID1, userID2, userID2, userID1).Find(&friends).Error, "")
|
||||
}
|
||||
|
||||
// 获取 owner的好友列表
|
||||
func (f *FriendGorm) FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string, tx ...*gorm.DB) (friends []*table.FriendModel, err error) {
|
||||
func (f *FriendGorm) FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string, tx ...*gorm.DB) (friends []*relation.FriendModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friendUserIDs", friendUserIDs, "friends", friends)
|
||||
}()
|
||||
@@ -102,7 +102,7 @@ func (f *FriendGorm) FindFriends(ctx context.Context, ownerUserID string, friend
|
||||
}
|
||||
|
||||
// 获取哪些人添加了friendUserID
|
||||
func (f *FriendGorm) FindReversalFriends(ctx context.Context, friendUserID string, ownerUserIDs []string, tx ...*gorm.DB) (friends []*table.FriendModel, err error) {
|
||||
func (f *FriendGorm) FindReversalFriends(ctx context.Context, friendUserID string, ownerUserIDs []string, tx ...*gorm.DB) (friends []*relation.FriendModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friendUserID", friendUserID, "friends", friends)
|
||||
}()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/table"
|
||||
"Open_IM/pkg/common/db/table/relation"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@@ -20,57 +20,57 @@ type FriendRequestGorm struct {
|
||||
DB *gorm.DB `gorm:"-"`
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) Create(ctx context.Context, friends []*table.FriendRequestModel) (err error) {
|
||||
func (f *FriendRequestGorm) Create(ctx context.Context, friends []*relation.FriendRequestModel) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
}()
|
||||
return utils.Wrap(f.DB.Model(&table.FriendRequestModel{}).Create(&friends).Error, "")
|
||||
return utils.Wrap(f.DB.Model(&relation.FriendRequestModel{}).Create(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) Delete(ctx context.Context, fromUserID, toUserID string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "fromUserID", fromUserID, "toUserID", toUserID)
|
||||
}()
|
||||
return utils.Wrap(f.DB.Model(&table.FriendRequestModel{}).Where("from_user_id = ? and to_user_id = ?", fromUserID, toUserID).Delete(&table.FriendRequestModel{}).Error, "")
|
||||
return utils.Wrap(f.DB.Model(&relation.FriendRequestModel{}).Where("from_user_id = ? and to_user_id = ?", fromUserID, toUserID).Delete(&relation.FriendRequestModel{}).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(f.DB.Model(&table.FriendRequestModel{}).Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
|
||||
return utils.Wrap(f.DB.Model(&relation.FriendRequestModel{}).Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) Update(ctx context.Context, friends []*table.FriendRequestModel) (err error) {
|
||||
func (f *FriendRequestGorm) Update(ctx context.Context, friends []*relation.FriendRequestModel) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
}()
|
||||
return utils.Wrap(f.DB.Model(&table.FriendRequestModel{}).Updates(&friends).Error, "")
|
||||
return utils.Wrap(f.DB.Model(&relation.FriendRequestModel{}).Updates(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) Find(ctx context.Context, ownerUserID string) (friends []*table.FriendRequestModel, err error) {
|
||||
func (f *FriendRequestGorm) Find(ctx context.Context, ownerUserID string) (friends []*relation.FriendRequestModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friends", friends)
|
||||
}()
|
||||
return friends, utils.Wrap(f.DB.Model(&table.FriendRequestModel{}).Where("owner_user_id = ?", ownerUserID).Find(&friends).Error, "")
|
||||
return friends, utils.Wrap(f.DB.Model(&relation.FriendRequestModel{}).Where("owner_user_id = ?", ownerUserID).Find(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) Take(ctx context.Context, fromUserID, toUserID string) (friend *table.FriendRequestModel, err error) {
|
||||
friend = &table.FriendRequestModel{}
|
||||
func (f *FriendRequestGorm) Take(ctx context.Context, fromUserID, toUserID string) (friend *relation.FriendRequestModel, err error) {
|
||||
friend = &relation.FriendRequestModel{}
|
||||
defer tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "fromUserID", fromUserID, "toUserID", toUserID, "friend", friend)
|
||||
return friend, utils.Wrap(f.DB.Model(&table.FriendRequestModel{}).Where("from_user_id = ? and to_user_id", fromUserID, toUserID).Take(friend).Error, "")
|
||||
return friend, utils.Wrap(f.DB.Model(&relation.FriendRequestModel{}).Where("from_user_id = ? and to_user_id", fromUserID, toUserID).Take(friend).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) FindToUserID(ctx context.Context, toUserID string) (friends []*table.FriendRequestModel, err error) {
|
||||
func (f *FriendRequestGorm) FindToUserID(ctx context.Context, toUserID string) (friends []*relation.FriendRequestModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "toUserID", toUserID, "friends", friends)
|
||||
}()
|
||||
return friends, utils.Wrap(f.DB.Model(&table.FriendRequestModel{}).Where("to_user_id = ?", toUserID).Find(&friends).Error, "")
|
||||
return friends, utils.Wrap(f.DB.Model(&relation.FriendRequestModel{}).Where("to_user_id = ?", toUserID).Find(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) FindFromUserID(ctx context.Context, fromUserID string) (friends []*table.FriendRequestModel, err error) {
|
||||
func (f *FriendRequestGorm) FindFromUserID(ctx context.Context, fromUserID string) (friends []*relation.FriendRequestModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "fromUserID", fromUserID, "friends", friends)
|
||||
}()
|
||||
return friends, utils.Wrap(f.DB.Model(&table.FriendRequestModel{}).Where("from_user_id = ?", fromUserID).Find(&friends).Error, "")
|
||||
return friends, utils.Wrap(f.DB.Model(&relation.FriendRequestModel{}).Where("from_user_id = ?", fromUserID).Find(&friends).Error, "")
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package relation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/table"
|
||||
"Open_IM/pkg/common/db/table/relation"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@@ -17,14 +17,14 @@ func NewGroupMemberDB(db *gorm.DB) *GroupMemberGorm {
|
||||
return &GroupMemberGorm{DB: db}
|
||||
}
|
||||
|
||||
func (g *GroupMemberGorm) Create(ctx context.Context, groupMemberList []*table.GroupMemberModel, tx ...*gorm.DB) (err error) {
|
||||
func (g *GroupMemberGorm) Create(ctx context.Context, groupMemberList []*relation.GroupMemberModel, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupMemberList", groupMemberList)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Create(&groupMemberList).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMemberGorm) Delete(ctx context.Context, groupMembers []*table.GroupMemberModel, tx ...*gorm.DB) (err error) {
|
||||
func (g *GroupMemberGorm) Delete(ctx context.Context, groupMembers []*relation.GroupMemberModel, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupMembers", groupMembers)
|
||||
}()
|
||||
@@ -35,15 +35,15 @@ func (g *GroupMemberGorm) UpdateByMap(ctx context.Context, groupID string, userI
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Model(&table.GroupMemberModel{}).Where("group_id = ? and user_id = ?", groupID, userID).Updates(args).Error, "")
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Model(&relation.GroupMemberModel{}).Where("group_id = ? and user_id = ?", groupID, userID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMemberGorm) Update(ctx context.Context, groupMembers []*table.GroupMemberModel, tx ...*gorm.DB) (err error) {
|
||||
func (g *GroupMemberGorm) Update(ctx context.Context, groupMembers []*relation.GroupMemberModel, tx ...*gorm.DB) (err error) {
|
||||
defer func() { tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupMembers", groupMembers) }()
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Updates(&groupMembers).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMemberGorm) Find(ctx context.Context, groupMembers []*table.GroupMemberModel, tx ...*gorm.DB) (groupList []*table.GroupMemberModel, err error) {
|
||||
func (g *GroupMemberGorm) Find(ctx context.Context, groupMembers []*relation.GroupMemberModel, tx ...*gorm.DB) (groupList []*relation.GroupMemberModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupMembers", groupMembers, "groupList", groupList)
|
||||
}()
|
||||
@@ -54,19 +54,19 @@ func (g *GroupMemberGorm) Find(ctx context.Context, groupMembers []*table.GroupM
|
||||
return groupList, utils.Wrap(getDBConn(g.DB, tx).Where("(group_id, user_id) in ?", where).Find(&groupList).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMemberGorm) Take(ctx context.Context, groupID string, userID string, tx ...*gorm.DB) (groupMember *table.GroupMemberModel, err 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)
|
||||
}()
|
||||
groupMember = &table.GroupMemberModel{}
|
||||
groupMember = &relation.GroupMemberModel{}
|
||||
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 *table.GroupMemberModel, err error) {
|
||||
func (g *GroupMemberGorm) TakeOwnerInfo(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)
|
||||
}()
|
||||
groupMember = &table.GroupMemberModel{}
|
||||
groupMember = &relation.GroupMemberModel{}
|
||||
return groupMember, utils.Wrap(getDBConn(g.DB, tx).Where("group_id = ? and role_level = ?", groupID, constant.GroupOwner).Take(groupMember).Error, "")
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/table"
|
||||
"Open_IM/pkg/common/db/table/relation"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@@ -16,7 +16,7 @@ func NewGroupDB(db *gorm.DB) *GroupGorm {
|
||||
return &GroupGorm{DB: db}
|
||||
}
|
||||
|
||||
func (g *GroupGorm) Create(ctx context.Context, groups []*table.GroupModel, tx ...*gorm.DB) (err error) {
|
||||
func (g *GroupGorm) Create(ctx context.Context, groups []*relation.GroupModel, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groups", groups)
|
||||
}()
|
||||
@@ -27,7 +27,7 @@ func (g *GroupGorm) Delete(ctx context.Context, groupIDs []string, tx ...*gorm.D
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupIDs", groupIDs)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Where("group_id in (?)", groupIDs).Delete(&table.GroupModel{}).Error, "")
|
||||
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) {
|
||||
@@ -37,22 +37,22 @@ func (g *GroupGorm) UpdateByMap(ctx context.Context, groupID string, args map[st
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Where("group_id = ?", groupID).Model(g).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupGorm) Update(ctx context.Context, groups []*table.GroupModel, tx ...*gorm.DB) (err 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 []*table.GroupModel, err 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)
|
||||
}()
|
||||
return groups, utils.Wrap(getDBConn(g.DB, tx).Where("group_id in (?)", groupIDs).Find(&groups).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupGorm) Take(ctx context.Context, groupID string, tx ...*gorm.DB) (group *table.GroupModel, err error) {
|
||||
group = &table.GroupModel{}
|
||||
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)
|
||||
}()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/table"
|
||||
"Open_IM/pkg/common/db/table/relation"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@@ -18,14 +18,14 @@ func NewGroupRequest(db *gorm.DB) *GroupRequestGorm {
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GroupRequestGorm) Create(ctx context.Context, groupRequests []*table.GroupRequestModel, tx ...*gorm.DB) (err error) {
|
||||
func (g *GroupRequestGorm) Create(ctx context.Context, groupRequests []*relation.GroupRequestModel, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupRequests", groupRequests)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Create(&groupRequests).Error, utils.GetSelfFuncName())
|
||||
}
|
||||
|
||||
func (g *GroupRequestGorm) Delete(ctx context.Context, groupRequests []*table.GroupRequestModel, tx ...*gorm.DB) (err error) {
|
||||
func (g *GroupRequestGorm) Delete(ctx context.Context, groupRequests []*relation.GroupRequestModel, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupRequests", groupRequests)
|
||||
}()
|
||||
@@ -39,14 +39,14 @@ func (g *GroupRequestGorm) UpdateByMap(ctx context.Context, groupID string, user
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Where("group_id = ? and user_id = ? ", groupID, userID).Updates(args).Error, utils.GetSelfFuncName())
|
||||
}
|
||||
|
||||
func (g *GroupRequestGorm) Update(ctx context.Context, groupRequests []*table.GroupRequestModel, tx ...*gorm.DB) (err error) {
|
||||
func (g *GroupRequestGorm) Update(ctx context.Context, groupRequests []*relation.GroupRequestModel, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupRequests", groupRequests)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Updates(&groupRequests).Error, utils.GetSelfFuncName())
|
||||
}
|
||||
|
||||
func (g *GroupRequestGorm) Find(ctx context.Context, groupRequests []*table.GroupRequestModel, tx ...*gorm.DB) (resultGroupRequests []*table.GroupRequestModel, err error) {
|
||||
func (g *GroupRequestGorm) Find(ctx context.Context, groupRequests []*relation.GroupRequestModel, tx ...*gorm.DB) (resultGroupRequests []*relation.GroupRequestModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupRequests", groupRequests, "resultGroupRequests", resultGroupRequests)
|
||||
}()
|
||||
@@ -57,8 +57,8 @@ func (g *GroupRequestGorm) Find(ctx context.Context, groupRequests []*table.Grou
|
||||
return resultGroupRequests, utils.Wrap(getDBConn(g.DB, tx).Where("(group_id, user_id) in ?", where).Find(&resultGroupRequests).Error, utils.GetSelfFuncName())
|
||||
}
|
||||
|
||||
func (g *GroupRequestGorm) Take(ctx context.Context, groupID string, userID string, tx ...*gorm.DB) (groupRequest *table.GroupRequestModel, err error) {
|
||||
groupRequest = &table.GroupRequestModel{}
|
||||
func (g *GroupRequestGorm) Take(ctx context.Context, groupID string, userID string, tx ...*gorm.DB) (groupRequest *relation.GroupRequestModel, err error) {
|
||||
groupRequest = &relation.GroupRequestModel{}
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID, "groupRequest", *groupRequest)
|
||||
}()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/table"
|
||||
"Open_IM/pkg/common/db/table/relation"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@@ -19,75 +19,75 @@ func NewUserGorm(db *gorm.DB) *UserGorm {
|
||||
return &user
|
||||
}
|
||||
|
||||
func (u *UserGorm) Create(ctx context.Context, users []*table.UserModel, tx ...*gorm.DB) (err error) {
|
||||
func (u *UserGorm) Create(ctx context.Context, users []*relation.UserModel, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "users", users)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(u.DB, tx).Model(&table.UserModel{}).Create(&users).Error, "")
|
||||
return utils.Wrap(getDBConn(u.DB, tx).Model(&relation.UserModel{}).Create(&users).Error, "")
|
||||
}
|
||||
|
||||
func (u *UserGorm) UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(u.DB.Model(&table.UserModel{}).Where("user_id = ?", userID).Updates(args).Error, "")
|
||||
return utils.Wrap(u.DB.Model(&relation.UserModel{}).Where("user_id = ?", userID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (u *UserGorm) Update(ctx context.Context, users []*table.UserModel) (err error) {
|
||||
func (u *UserGorm) Update(ctx context.Context, users []*relation.UserModel) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "users", users)
|
||||
}()
|
||||
return utils.Wrap(u.DB.Model(&table.UserModel{}).Updates(&users).Error, "")
|
||||
return utils.Wrap(u.DB.Model(&relation.UserModel{}).Updates(&users).Error, "")
|
||||
}
|
||||
|
||||
func (u *UserGorm) Find(ctx context.Context, userIDs []string) (users []*table.UserModel, err error) {
|
||||
func (u *UserGorm) Find(ctx context.Context, userIDs []string) (users []*relation.UserModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userIDs", userIDs, "users", users)
|
||||
}()
|
||||
err = utils.Wrap(u.DB.Model(&table.UserModel{}).Where("user_id in (?)", userIDs).Find(&users).Error, "")
|
||||
err = utils.Wrap(u.DB.Model(&relation.UserModel{}).Where("user_id in (?)", userIDs).Find(&users).Error, "")
|
||||
return users, err
|
||||
}
|
||||
|
||||
func (u *UserGorm) Take(ctx context.Context, userID string) (user *table.UserModel, err error) {
|
||||
user = &table.UserModel{}
|
||||
func (u *UserGorm) Take(ctx context.Context, userID string) (user *relation.UserModel, err error) {
|
||||
user = &relation.UserModel{}
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "user", *user)
|
||||
}()
|
||||
err = utils.Wrap(u.DB.Model(&table.UserModel{}).Where("user_id = ?", userID).Take(&user).Error, "")
|
||||
err = utils.Wrap(u.DB.Model(&relation.UserModel{}).Where("user_id = ?", userID).Take(&user).Error, "")
|
||||
return user, err
|
||||
}
|
||||
|
||||
func (u *UserGorm) GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*table.UserModel, count int64, err error) {
|
||||
func (u *UserGorm) GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation.UserModel, count int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userName", userName, "showNumber", showNumber, "pageNumber", pageNumber, "users", users, "count", count)
|
||||
}()
|
||||
err = u.DB.Model(&table.UserModel{}).Where(" name like ?", fmt.Sprintf("%%%s%%", userName)).Limit(int(showNumber)).Offset(int(showNumber * pageNumber)).Find(&users).Error
|
||||
err = u.DB.Model(&relation.UserModel{}).Where(" name like ?", fmt.Sprintf("%%%s%%", userName)).Limit(int(showNumber)).Offset(int(showNumber * pageNumber)).Find(&users).Error
|
||||
if err != nil {
|
||||
return nil, 0, utils.Wrap(err, "")
|
||||
}
|
||||
return users, count, utils.Wrap(u.DB.Model(&table.UserModel{}).Where(" name like ? ", fmt.Sprintf("%%%s%%", userName)).Count(&count).Error, "")
|
||||
return users, count, utils.Wrap(u.DB.Model(&relation.UserModel{}).Where(" name like ? ", fmt.Sprintf("%%%s%%", userName)).Count(&count).Error, "")
|
||||
}
|
||||
|
||||
func (u *UserGorm) GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*table.UserModel, count int64, err error) {
|
||||
func (u *UserGorm) GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*relation.UserModel, count int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "content", content, "showNumber", showNumber, "pageNumber", pageNumber, "users", users)
|
||||
}()
|
||||
db := u.DB.Model(&table.UserModel{}).Where(" name like ? or user_id = ? ", fmt.Sprintf("%%%s%%", content), content)
|
||||
if err := db.Model(&table.UserModel{}).Count(&count).Error; err != nil {
|
||||
db := u.DB.Model(&relation.UserModel{}).Where(" name like ? or user_id = ? ", fmt.Sprintf("%%%s%%", content), content)
|
||||
if err := db.Model(&relation.UserModel{}).Count(&count).Error; err != nil {
|
||||
return nil, 0, utils.Wrap(err, "")
|
||||
}
|
||||
err = utils.Wrap(db.Limit(int(showNumber)).Offset(int(showNumber*pageNumber)).Find(&users).Error, "")
|
||||
return
|
||||
}
|
||||
|
||||
func (u *UserGorm) Get(ctx context.Context, showNumber, pageNumber int32) (users []*table.UserModel, count int64, err error) {
|
||||
func (u *UserGorm) Get(ctx context.Context, showNumber, pageNumber int32) (users []*relation.UserModel, count int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "showNumber", showNumber, "pageNumber", pageNumber, "users", users, "count", count)
|
||||
}()
|
||||
err = u.DB.Model(&table.UserModel{}).Model(u).Count(&count).Error
|
||||
err = u.DB.Model(&relation.UserModel{}).Model(u).Count(&count).Error
|
||||
if err != nil {
|
||||
return nil, 0, utils.Wrap(err, "")
|
||||
}
|
||||
err = utils.Wrap(u.DB.Model(&table.UserModel{}).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&users).Error, "")
|
||||
err = utils.Wrap(u.DB.Model(&relation.UserModel{}).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&users).Error, "")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,165 +0,0 @@
|
||||
package table
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
FriendModelTableName = ""
|
||||
ConversationModelTableName = ""
|
||||
)
|
||||
|
||||
type FriendModel struct {
|
||||
OwnerUserID string `gorm:"column:owner_user_id;primary_key;size:64"`
|
||||
FriendUserID string `gorm:"column:friend_user_id;primary_key;size:64"`
|
||||
Remark string `gorm:"column:remark;size:255"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
AddSource int32 `gorm:"column:add_source"`
|
||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
}
|
||||
|
||||
type ConversationModel struct {
|
||||
OwnerUserID string `gorm:"column:owner_user_id;primary_key;type:char(128)" json:"OwnerUserID"`
|
||||
ConversationID string `gorm:"column:conversation_id;primary_key;type:char(128)" json:"conversationID"`
|
||||
ConversationType int32 `gorm:"column:conversation_type" json:"conversationType"`
|
||||
UserID string `gorm:"column:user_id;type:char(64)" json:"userID"`
|
||||
GroupID string `gorm:"column:group_id;type:char(128)" json:"groupID"`
|
||||
RecvMsgOpt int32 `gorm:"column:recv_msg_opt" json:"recvMsgOpt"`
|
||||
UnreadCount int32 `gorm:"column:unread_count" json:"unreadCount"`
|
||||
DraftTextTime int64 `gorm:"column:draft_text_time" json:"draftTextTime"`
|
||||
IsPinned bool `gorm:"column:is_pinned" json:"isPinned"`
|
||||
IsPrivateChat bool `gorm:"column:is_private_chat" json:"isPrivateChat"`
|
||||
BurnDuration int32 `gorm:"column:burn_duration;default:30" json:"burnDuration"`
|
||||
GroupAtType int32 `gorm:"column:group_at_type" json:"groupAtType"`
|
||||
IsNotInGroup bool `gorm:"column:is_not_in_group" json:"isNotInGroup"`
|
||||
UpdateUnreadCountTime int64 `gorm:"column:update_unread_count_time" json:"updateUnreadCountTime"`
|
||||
AttachedInfo string `gorm:"column:attached_info;type:varchar(1024)" json:"attachedInfo"`
|
||||
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
|
||||
}
|
||||
|
||||
type GroupModel struct {
|
||||
GroupID string `gorm:"column:group_id;primary_key;size:64" json:"groupID" binding:"required"`
|
||||
GroupName string `gorm:"column:name;size:255" json:"groupName"`
|
||||
Notification string `gorm:"column:notification;size:255" json:"notification"`
|
||||
Introduction string `gorm:"column:introduction;size:255" json:"introduction"`
|
||||
FaceURL string `gorm:"column:face_url;size:255" json:"faceURL"`
|
||||
CreateTime time.Time `gorm:"column:create_time;index:create_time"`
|
||||
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"`
|
||||
GroupType int32 `gorm:"column:group_type"`
|
||||
NeedVerification int32 `gorm:"column:need_verification"`
|
||||
LookMemberInfo int32 `gorm:"column:look_member_info" json:"lookMemberInfo"`
|
||||
ApplyMemberFriend int32 `gorm:"column:apply_member_friend" json:"applyMemberFriend"`
|
||||
NotificationUpdateTime time.Time `gorm:"column:notification_update_time"`
|
||||
NotificationUserID string `gorm:"column:notification_user_id;size:64"`
|
||||
}
|
||||
|
||||
func (f *GroupModel) EqID(i interface{}) bool {
|
||||
switch v := i.(type) {
|
||||
case GroupModel:
|
||||
return f.GroupID == v.GroupID
|
||||
case *GroupModel:
|
||||
return f.GroupID == v.GroupID
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func DuplicateRemoval[T any](arr []T, fn func(t T) string) {
|
||||
|
||||
}
|
||||
|
||||
func aaa() {
|
||||
DuplicateRemoval([]GroupModel{}, func(t GroupModel) string {
|
||||
return t.GroupID
|
||||
})
|
||||
|
||||
DuplicateRemoval([]*GroupModel{}, func(t *GroupModel) string {
|
||||
return t.GroupID
|
||||
})
|
||||
}
|
||||
|
||||
type FriendRequestModel struct {
|
||||
FromUserID string `gorm:"column:from_user_id;primary_key;size:64"`
|
||||
ToUserID string `gorm:"column:to_user_id;primary_key;size:64"`
|
||||
HandleResult int32 `gorm:"column:handle_result"`
|
||||
ReqMsg string `gorm:"column:req_msg;size:255"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
HandlerUserID string `gorm:"column:handler_user_id;size:64"`
|
||||
HandleMsg string `gorm:"column:handle_msg;size:255"`
|
||||
HandleTime time.Time `gorm:"column:handle_time"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
}
|
||||
|
||||
type GroupMemberModel struct {
|
||||
GroupID string `gorm:"column:group_id;primary_key;size:64"`
|
||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
Nickname string `gorm:"column:nickname;size:255"`
|
||||
FaceURL string `gorm:"column:user_group_face_url;size:255"`
|
||||
RoleLevel int32 `gorm:"column:role_level"`
|
||||
JoinTime time.Time `gorm:"column:join_time"`
|
||||
JoinSource int32 `gorm:"column:join_source"`
|
||||
InviterUserID string `gorm:"column:inviter_user_id;size:64"`
|
||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||
MuteEndTime time.Time `gorm:"column:mute_end_time"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
}
|
||||
|
||||
type GroupRequestModel struct {
|
||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
GroupID string `gorm:"column:group_id;primary_key;size:64"`
|
||||
HandleResult int32 `gorm:"column:handle_result"`
|
||||
ReqMsg string `gorm:"column:req_msg;size:1024"`
|
||||
HandledMsg string `gorm:"column:handle_msg;size:1024"`
|
||||
ReqTime time.Time `gorm:"column:req_time"`
|
||||
HandleUserID string `gorm:"column:handle_user_id;size:64"`
|
||||
HandledTime time.Time `gorm:"column:handle_time"`
|
||||
JoinSource int32 `gorm:"column:join_source"`
|
||||
InviterUserID string `gorm:"column:inviter_user_id;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
}
|
||||
|
||||
type UserModel struct {
|
||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
Nickname string `gorm:"column:name;size:255"`
|
||||
FaceURL string `gorm:"column:face_url;size:255"`
|
||||
Gender int32 `gorm:"column:gender"`
|
||||
PhoneNumber string `gorm:"column:phone_number;size:32"`
|
||||
Birth time.Time `gorm:"column:birth"`
|
||||
Email string `gorm:"column:email;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
CreateTime time.Time `gorm:"column:create_time;index:create_time"`
|
||||
AppMangerLevel int32 `gorm:"column:app_manger_level"`
|
||||
GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt"`
|
||||
}
|
||||
|
||||
type BlackModel struct {
|
||||
OwnerUserID string `gorm:"column:owner_user_id;primary_key;size:64"`
|
||||
BlockUserID string `gorm:"column:block_user_id;primary_key;size:64"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
AddSource int32 `gorm:"column:add_source"`
|
||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
}
|
||||
|
||||
type ChatLogModel struct {
|
||||
ServerMsgID string `gorm:"column:server_msg_id;primary_key;type:char(64)" json:"serverMsgID"`
|
||||
ClientMsgID string `gorm:"column:client_msg_id;type:char(64)" json:"clientMsgID"`
|
||||
SendID string `gorm:"column:send_id;type:char(64);index:send_id,priority:2" json:"sendID"`
|
||||
RecvID string `gorm:"column:recv_id;type:char(64);index:recv_id,priority:2" json:"recvID"`
|
||||
SenderPlatformID int32 `gorm:"column:sender_platform_id" json:"senderPlatformID"`
|
||||
SenderNickname string `gorm:"column:sender_nick_name;type:varchar(255)" json:"senderNickname"`
|
||||
SenderFaceURL string `gorm:"column:sender_face_url;type:varchar(255);" json:"senderFaceURL"`
|
||||
SessionType int32 `gorm:"column:session_type;index:session_type,priority:2;index:session_type_alone" json:"sessionType"`
|
||||
MsgFrom int32 `gorm:"column:msg_from" json:"msgFrom"`
|
||||
ContentType int32 `gorm:"column:content_type;index:content_type,priority:2;index:content_type_alone" json:"contentType"`
|
||||
Content string `gorm:"column:content;type:varchar(3000)" json:"content"`
|
||||
Status int32 `gorm:"column:status" json:"status"`
|
||||
SendTime time.Time `gorm:"column:send_time;index:sendTime;index:content_type,priority:1;index:session_type,priority:1;index:recv_id,priority:1;index:send_id,priority:1" json:"sendTime"`
|
||||
CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
|
||||
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
|
||||
DB *gorm.DB
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
BlackModelTableName = "blacks"
|
||||
)
|
||||
|
||||
type BlackModel struct {
|
||||
OwnerUserID string `gorm:"column:owner_user_id;primary_key;size:64"`
|
||||
BlockUserID string `gorm:"column:block_user_id;primary_key;size:64"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
AddSource int32 `gorm:"column:add_source"`
|
||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
}
|
||||
|
||||
func (BlackModel) TableName() string {
|
||||
return BlackModelTableName
|
||||
}
|
||||
|
||||
type BlackModelInterface interface {
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
|
||||
pbMsg "Open_IM/pkg/proto/msg"
|
||||
)
|
||||
|
||||
const (
|
||||
ChatLogModelTableName = "chat_logs"
|
||||
)
|
||||
|
||||
type ChatLogModel struct {
|
||||
ServerMsgID string `gorm:"column:server_msg_id;primary_key;type:char(64)" json:"serverMsgID"`
|
||||
ClientMsgID string `gorm:"column:client_msg_id;type:char(64)" json:"clientMsgID"`
|
||||
SendID string `gorm:"column:send_id;type:char(64);index:send_id,priority:2" json:"sendID"`
|
||||
RecvID string `gorm:"column:recv_id;type:char(64);index:recv_id,priority:2" json:"recvID"`
|
||||
SenderPlatformID int32 `gorm:"column:sender_platform_id" json:"senderPlatformID"`
|
||||
SenderNickname string `gorm:"column:sender_nick_name;type:varchar(255)" json:"senderNickname"`
|
||||
SenderFaceURL string `gorm:"column:sender_face_url;type:varchar(255);" json:"senderFaceURL"`
|
||||
SessionType int32 `gorm:"column:session_type;index:session_type,priority:2;index:session_type_alone" json:"sessionType"`
|
||||
MsgFrom int32 `gorm:"column:msg_from" json:"msgFrom"`
|
||||
ContentType int32 `gorm:"column:content_type;index:content_type,priority:2;index:content_type_alone" json:"contentType"`
|
||||
Content string `gorm:"column:content;type:varchar(3000)" json:"content"`
|
||||
Status int32 `gorm:"column:status" json:"status"`
|
||||
SendTime time.Time `gorm:"column:send_time;index:sendTime;index:content_type,priority:1;index:session_type,priority:1;index:recv_id,priority:1;index:send_id,priority:1" json:"sendTime"`
|
||||
CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
|
||||
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func (ChatLogModel) TableName() string {
|
||||
return ChatLogModelTableName
|
||||
}
|
||||
|
||||
type ChatLogModelInterface interface {
|
||||
Create(msg pbMsg.MsgDataToMQ) error
|
||||
GetChatLog(chatLog *ChatLogModel, pageNumber, showNumber int32, contentTypeList []int32) (int64, []ChatLogModel, error)
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package relation
|
||||
|
||||
const (
|
||||
conversationModelTableName = "conversations"
|
||||
)
|
||||
|
||||
type ConversationModel struct {
|
||||
OwnerUserID string `gorm:"column:owner_user_id;primary_key;type:char(128)" json:"OwnerUserID"`
|
||||
ConversationID string `gorm:"column:conversation_id;primary_key;type:char(128)" json:"conversationID"`
|
||||
ConversationType int32 `gorm:"column:conversation_type" json:"conversationType"`
|
||||
UserID string `gorm:"column:user_id;type:char(64)" json:"userID"`
|
||||
GroupID string `gorm:"column:group_id;type:char(128)" json:"groupID"`
|
||||
RecvMsgOpt int32 `gorm:"column:recv_msg_opt" json:"recvMsgOpt"`
|
||||
UnreadCount int32 `gorm:"column:unread_count" json:"unreadCount"`
|
||||
DraftTextTime int64 `gorm:"column:draft_text_time" json:"draftTextTime"`
|
||||
IsPinned bool `gorm:"column:is_pinned" json:"isPinned"`
|
||||
IsPrivateChat bool `gorm:"column:is_private_chat" json:"isPrivateChat"`
|
||||
BurnDuration int32 `gorm:"column:burn_duration;default:30" json:"burnDuration"`
|
||||
GroupAtType int32 `gorm:"column:group_at_type" json:"groupAtType"`
|
||||
IsNotInGroup bool `gorm:"column:is_not_in_group" json:"isNotInGroup"`
|
||||
UpdateUnreadCountTime int64 `gorm:"column:update_unread_count_time" json:"updateUnreadCountTime"`
|
||||
AttachedInfo string `gorm:"column:attached_info;type:varchar(1024)" json:"attachedInfo"`
|
||||
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
|
||||
}
|
||||
|
||||
func (ConversationModel) TableName() string {
|
||||
return conversationModelTableName
|
||||
}
|
||||
|
||||
type ConversationModelInterface interface {
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package relation
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
FriendModelTableName = "friends"
|
||||
)
|
||||
|
||||
type FriendModel struct {
|
||||
OwnerUserID string `gorm:"column:owner_user_id;primary_key;size:64"`
|
||||
FriendUserID string `gorm:"column:friend_user_id;primary_key;size:64"`
|
||||
Remark string `gorm:"column:remark;size:255"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
AddSource int32 `gorm:"column:add_source"`
|
||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
}
|
||||
|
||||
func (FriendModel) TableName() string {
|
||||
return FriendModelTableName
|
||||
}
|
||||
|
||||
type FriendModelInterface interface {
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package relation
|
||||
|
||||
import "time"
|
||||
|
||||
const FriendRequestModelTableName = "friend_requests"
|
||||
|
||||
type FriendRequestModel struct {
|
||||
FromUserID string `gorm:"column:from_user_id;primary_key;size:64"`
|
||||
ToUserID string `gorm:"column:to_user_id;primary_key;size:64"`
|
||||
HandleResult int32 `gorm:"column:handle_result"`
|
||||
ReqMsg string `gorm:"column:req_msg;size:255"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
HandlerUserID string `gorm:"column:handler_user_id;size:64"`
|
||||
HandleMsg string `gorm:"column:handle_msg;size:255"`
|
||||
HandleTime time.Time `gorm:"column:handle_time"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
}
|
||||
|
||||
func (FriendRequestModel) TableName() string {
|
||||
return FriendRequestModelTableName
|
||||
}
|
||||
|
||||
type FriendRequestModelInterface interface {
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package relation
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
GroupModelTableName = "groups"
|
||||
)
|
||||
|
||||
type GroupModel struct {
|
||||
GroupID string `gorm:"column:group_id;primary_key;size:64" json:"groupID" binding:"required"`
|
||||
GroupName string `gorm:"column:name;size:255" json:"groupName"`
|
||||
Notification string `gorm:"column:notification;size:255" json:"notification"`
|
||||
Introduction string `gorm:"column:introduction;size:255" json:"introduction"`
|
||||
FaceURL string `gorm:"column:face_url;size:255" json:"faceURL"`
|
||||
CreateTime time.Time `gorm:"column:create_time;index:create_time"`
|
||||
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"`
|
||||
GroupType int32 `gorm:"column:group_type"`
|
||||
NeedVerification int32 `gorm:"column:need_verification"`
|
||||
LookMemberInfo int32 `gorm:"column:look_member_info" json:"lookMemberInfo"`
|
||||
ApplyMemberFriend int32 `gorm:"column:apply_member_friend" json:"applyMemberFriend"`
|
||||
NotificationUpdateTime time.Time `gorm:"column:notification_update_time"`
|
||||
NotificationUserID string `gorm:"column:notification_user_id;size:64"`
|
||||
}
|
||||
|
||||
func (GroupModel) TableName() string {
|
||||
return GroupModelTableName
|
||||
}
|
||||
|
||||
type GroupModelInterface interface {
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package relation
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
GroupMemberModelTableName = "group_members"
|
||||
)
|
||||
|
||||
type GroupMemberModel struct {
|
||||
GroupID string `gorm:"column:group_id;primary_key;size:64"`
|
||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
Nickname string `gorm:"column:nickname;size:255"`
|
||||
FaceURL string `gorm:"column:user_group_face_url;size:255"`
|
||||
RoleLevel int32 `gorm:"column:role_level"`
|
||||
JoinTime time.Time `gorm:"column:join_time"`
|
||||
JoinSource int32 `gorm:"column:join_source"`
|
||||
InviterUserID string `gorm:"column:inviter_user_id;size:64"`
|
||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||
MuteEndTime time.Time `gorm:"column:mute_end_time"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
}
|
||||
|
||||
func (GroupMemberModel) TableName() string {
|
||||
return GroupMemberModelTableName
|
||||
}
|
||||
|
||||
type GroupMemberModelInterface interface {
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package relation
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
GroupRequestModelTableName = "group_requests"
|
||||
)
|
||||
|
||||
type GroupRequestModel struct {
|
||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
GroupID string `gorm:"column:group_id;primary_key;size:64"`
|
||||
HandleResult int32 `gorm:"column:handle_result"`
|
||||
ReqMsg string `gorm:"column:req_msg;size:1024"`
|
||||
HandledMsg string `gorm:"column:handle_msg;size:1024"`
|
||||
ReqTime time.Time `gorm:"column:req_time"`
|
||||
HandleUserID string `gorm:"column:handle_user_id;size:64"`
|
||||
HandledTime time.Time `gorm:"column:handle_time"`
|
||||
JoinSource int32 `gorm:"column:join_source"`
|
||||
InviterUserID string `gorm:"column:inviter_user_id;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
}
|
||||
|
||||
func (GroupRequestModel) TableName() string {
|
||||
return GroupRequestModelTableName
|
||||
}
|
||||
|
||||
type GroupRequestModelInterface interface {
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package relation
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
UserModelTableName = "users"
|
||||
)
|
||||
|
||||
type UserModel struct {
|
||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
Nickname string `gorm:"column:name;size:255"`
|
||||
FaceURL string `gorm:"column:face_url;size:255"`
|
||||
Gender int32 `gorm:"column:gender"`
|
||||
PhoneNumber string `gorm:"column:phone_number;size:32"`
|
||||
Birth time.Time `gorm:"column:birth"`
|
||||
Email string `gorm:"column:email;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
CreateTime time.Time `gorm:"column:create_time;index:create_time"`
|
||||
AppMangerLevel int32 `gorm:"column:app_manger_level"`
|
||||
GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt"`
|
||||
}
|
||||
|
||||
func (UserModel) TableName() string {
|
||||
return GroupRequestModelTableName
|
||||
}
|
||||
|
||||
type UserModelInterface interface {
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
package table
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
CSuperGroup = "super_group"
|
||||
CUserToSuperGroup = "user_to_super_group"
|
||||
CTag = "tag"
|
||||
CSendLog = "send_log"
|
||||
CWorkMoment = "work_moment"
|
||||
CExtendMsgSet = "extend_msgs"
|
||||
|
||||
ExtendMsgMaxNum = 100
|
||||
)
|
||||
|
||||
type SuperGroupModel struct {
|
||||
GroupID string `bson:"group_id" json:"groupID"`
|
||||
MemberIDList []string `bson:"member_id_list" json:"memberIDList"`
|
||||
}
|
||||
|
||||
func (SuperGroupModel) TableName() string {
|
||||
return CSuperGroup
|
||||
}
|
||||
|
||||
type UserToSuperGroupModel struct {
|
||||
UserID string `bson:"user_id" json:"userID"`
|
||||
GroupIDList []string `bson:"group_id_list" json:"groupIDList"`
|
||||
}
|
||||
|
||||
func (UserToSuperGroupModel) TableName() string {
|
||||
return CUserToSuperGroup
|
||||
}
|
||||
|
||||
type TagModel struct {
|
||||
UserID string `bson:"user_id"`
|
||||
TagID string `bson:"tag_id"`
|
||||
TagName string `bson:"tag_name"`
|
||||
UserList []string `bson:"user_list"`
|
||||
}
|
||||
|
||||
func (TagModel) TableName() string {
|
||||
return CTag
|
||||
}
|
||||
|
||||
type CommonUserModel struct {
|
||||
UserID string `bson:"user_id"`
|
||||
UserName string `bson:"user_name"`
|
||||
}
|
||||
|
||||
type TagSendLogModel struct {
|
||||
UserList []CommonUserModel `bson:"tag_list"`
|
||||
SendID string `bson:"send_id"`
|
||||
SenderPlatformID int32 `bson:"sender_platform_id"`
|
||||
Content string `bson:"content"`
|
||||
SendTime int64 `bson:"send_time"`
|
||||
}
|
||||
|
||||
func (TagSendLogModel) TableName() string {
|
||||
return CSendLog
|
||||
}
|
||||
|
||||
type WorkMoment struct {
|
||||
WorkMomentID string `bson:"work_moment_id"`
|
||||
UserID string `bson:"user_id"`
|
||||
UserName string `bson:"user_name"`
|
||||
FaceURL string `bson:"face_url"`
|
||||
Content string `bson:"content"`
|
||||
LikeUserList []*CommonUserModel `bson:"like_user_list"`
|
||||
AtUserList []*CommonUserModel `bson:"at_user_list"`
|
||||
PermissionUserList []*CommonUserModel `bson:"permission_user_list"`
|
||||
Comments []*CommonUserModel `bson:"comments"`
|
||||
PermissionUserIDList []string `bson:"permission_user_id_list"`
|
||||
Permission int32 `bson:"permission"`
|
||||
CreateTime int32 `bson:"create_time"`
|
||||
}
|
||||
|
||||
func (WorkMoment) TableName() string {
|
||||
return CWorkMoment
|
||||
}
|
||||
|
||||
type Comment struct {
|
||||
UserID string `bson:"user_id" json:"user_id"`
|
||||
UserName string `bson:"user_name" json:"user_name"`
|
||||
ReplyUserID string `bson:"reply_user_id" json:"reply_user_id"`
|
||||
ReplyUserName string `bson:"reply_user_name" json:"reply_user_name"`
|
||||
ContentID string `bson:"content_id" json:"content_id"`
|
||||
Content string `bson:"content" json:"content"`
|
||||
CreateTime int32 `bson:"create_time" json:"create_time"`
|
||||
}
|
||||
|
||||
type ExtendMsgSet struct {
|
||||
SourceID string `bson:"source_id" json:"sourceID"`
|
||||
SessionType int32 `bson:"session_type" json:"sessionType"`
|
||||
ExtendMsgs map[string]ExtendMsg `bson:"extend_msgs" json:"extendMsgs"`
|
||||
ExtendMsgNum int32 `bson:"extend_msg_num" json:"extendMsgNum"`
|
||||
CreateTime int64 `bson:"create_time" json:"createTime"` // this block's create time
|
||||
MaxMsgUpdateTime int64 `bson:"max_msg_update_time" json:"maxMsgUpdateTime"` // index find msg
|
||||
}
|
||||
|
||||
type KeyValue struct {
|
||||
TypeKey string `bson:"type_key" json:"typeKey"`
|
||||
Value string `bson:"value" json:"value"`
|
||||
LatestUpdateTime int64 `bson:"latest_update_time" json:"latestUpdateTime"`
|
||||
}
|
||||
|
||||
type ExtendMsg struct {
|
||||
ReactionExtensionList map[string]KeyValue `bson:"reaction_extension_list" json:"reactionExtensionList"`
|
||||
ClientMsgID string `bson:"client_msg_id" json:"clientMsgID"`
|
||||
MsgFirstModifyTime int64 `bson:"msg_first_modify_time" json:"msgFirstModifyTime"` // this extendMsg create time
|
||||
AttachedInfo string `bson:"attached_info" json:"attachedInfo"`
|
||||
Ex string `bson:"ex" json:"ex"`
|
||||
}
|
||||
|
||||
func (ExtendMsgSet) TableName() string {
|
||||
return CExtendMsgSet
|
||||
}
|
||||
|
||||
func (ExtendMsgSet) GetExtendMsgMaxNum() int32 {
|
||||
return ExtendMsgMaxNum
|
||||
}
|
||||
|
||||
func (ExtendMsgSet) GetSourceID(ID string, index int32) string {
|
||||
return ID + ":" + strconv.Itoa(int(index))
|
||||
}
|
||||
|
||||
func (e *ExtendMsgSet) SplitSourceIDAndGetIndex() int32 {
|
||||
l := strings.Split(e.SourceID, ":")
|
||||
index, _ := strconv.Atoi(l[len(l)-1])
|
||||
return int32(index)
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package unrelation
|
||||
|
||||
type CommonUserModel struct {
|
||||
UserID string `bson:"user_id"`
|
||||
UserName string `bson:"user_name"`
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package unrelation
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
CExtendMsgSet = "extend_msgs"
|
||||
|
||||
ExtendMsgMaxNum = 100
|
||||
)
|
||||
|
||||
type ExtendMsgSet struct {
|
||||
SourceID string `bson:"source_id" json:"sourceID"`
|
||||
SessionType int32 `bson:"session_type" json:"sessionType"`
|
||||
ExtendMsgs map[string]ExtendMsg `bson:"extend_msgs" json:"extendMsgs"`
|
||||
ExtendMsgNum int32 `bson:"extend_msg_num" json:"extendMsgNum"`
|
||||
CreateTime int64 `bson:"create_time" json:"createTime"` // this block's create time
|
||||
MaxMsgUpdateTime int64 `bson:"max_msg_update_time" json:"maxMsgUpdateTime"` // index find msg
|
||||
}
|
||||
|
||||
type KeyValue struct {
|
||||
TypeKey string `bson:"type_key" json:"typeKey"`
|
||||
Value string `bson:"value" json:"value"`
|
||||
LatestUpdateTime int64 `bson:"latest_update_time" json:"latestUpdateTime"`
|
||||
}
|
||||
|
||||
type ExtendMsg struct {
|
||||
ReactionExtensionList map[string]KeyValue `bson:"reaction_extension_list" json:"reactionExtensionList"`
|
||||
ClientMsgID string `bson:"client_msg_id" json:"clientMsgID"`
|
||||
MsgFirstModifyTime int64 `bson:"msg_first_modify_time" json:"msgFirstModifyTime"` // this extendMsg create time
|
||||
AttachedInfo string `bson:"attached_info" json:"attachedInfo"`
|
||||
Ex string `bson:"ex" json:"ex"`
|
||||
}
|
||||
|
||||
func (ExtendMsgSet) TableName() string {
|
||||
return CExtendMsgSet
|
||||
}
|
||||
|
||||
func (ExtendMsgSet) GetExtendMsgMaxNum() int32 {
|
||||
return ExtendMsgMaxNum
|
||||
}
|
||||
|
||||
func (ExtendMsgSet) GetSourceID(ID string, index int32) string {
|
||||
return ID + ":" + strconv.Itoa(int(index))
|
||||
}
|
||||
|
||||
func (e *ExtendMsgSet) SplitSourceIDAndGetIndex() int32 {
|
||||
l := strings.Split(e.SourceID, ":")
|
||||
index, _ := strconv.Atoi(l[len(l)-1])
|
||||
return int32(index)
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package unrelation
|
||||
|
||||
const (
|
||||
CSuperGroup = "super_group"
|
||||
CUserToSuperGroup = "user_to_super_group"
|
||||
)
|
||||
|
||||
type SuperGroupModel struct {
|
||||
GroupID string `bson:"group_id" json:"groupID"`
|
||||
MemberIDs []string `bson:"member_id_list" json:"memberIDList"`
|
||||
}
|
||||
|
||||
func (SuperGroupModel) TableName() string {
|
||||
return CSuperGroup
|
||||
}
|
||||
|
||||
type UserToSuperGroupModel struct {
|
||||
UserID string `bson:"user_id" json:"userID"`
|
||||
GroupIDs []string `bson:"group_id_list" json:"groupIDList"`
|
||||
}
|
||||
|
||||
func (UserToSuperGroupModel) TableName() string {
|
||||
return CUserToSuperGroup
|
||||
}
|
||||
|
||||
type SuperGroupModelInterface interface {
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package unrelation
|
||||
|
||||
const (
|
||||
CTag = "tag"
|
||||
CSendLog = "send_log"
|
||||
)
|
||||
|
||||
type TagModel struct {
|
||||
UserID string `bson:"user_id"`
|
||||
TagID string `bson:"tag_id"`
|
||||
TagName string `bson:"tag_name"`
|
||||
UserList []string `bson:"user_list"`
|
||||
}
|
||||
|
||||
func (TagModel) TableName() string {
|
||||
return CTag
|
||||
}
|
||||
|
||||
type TagSendLogModel struct {
|
||||
UserList []CommonUserModel `bson:"tag_list"`
|
||||
SendID string `bson:"send_id"`
|
||||
SenderPlatformID int32 `bson:"sender_platform_id"`
|
||||
Content string `bson:"content"`
|
||||
SendTime int64 `bson:"send_time"`
|
||||
}
|
||||
|
||||
func (TagSendLogModel) TableName() string {
|
||||
return CSendLog
|
||||
}
|
||||
|
||||
type TagModelInterface interface {
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package unrelation
|
||||
|
||||
const (
|
||||
CWorkMoment = "work_moment"
|
||||
)
|
||||
|
||||
type WorkMoment struct {
|
||||
WorkMomentID string `bson:"work_moment_id"`
|
||||
UserID string `bson:"user_id"`
|
||||
UserName string `bson:"user_name"`
|
||||
FaceURL string `bson:"face_url"`
|
||||
Content string `bson:"content"`
|
||||
LikeUserList []*CommonUserModel `bson:"like_user_list"`
|
||||
AtUserList []*CommonUserModel `bson:"at_user_list"`
|
||||
PermissionUserList []*CommonUserModel `bson:"permission_user_list"`
|
||||
Comments []*CommonUserModel `bson:"comments"`
|
||||
PermissionUserIDList []string `bson:"permission_user_id_list"`
|
||||
Permission int32 `bson:"permission"`
|
||||
CreateTime int32 `bson:"create_time"`
|
||||
}
|
||||
|
||||
type Comment struct {
|
||||
UserID string `bson:"user_id" json:"user_id"`
|
||||
UserName string `bson:"user_name" json:"user_name"`
|
||||
ReplyUserID string `bson:"reply_user_id" json:"reply_user_id"`
|
||||
ReplyUserName string `bson:"reply_user_name" json:"reply_user_name"`
|
||||
ContentID string `bson:"content_id" json:"content_id"`
|
||||
Content string `bson:"content" json:"content"`
|
||||
CreateTime int32 `bson:"create_time" json:"create_time"`
|
||||
}
|
||||
|
||||
func (WorkMoment) TableName() string {
|
||||
return CWorkMoment
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package unrelation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/table"
|
||||
"Open_IM/pkg/common/db/table/unrelation"
|
||||
server_api_params "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@@ -19,10 +19,10 @@ type ExtendMsgSetMongoDriver struct {
|
||||
}
|
||||
|
||||
func NewExtendMsgSetMongoDriver(mgoDB *mongo.Database) *ExtendMsgSetMongoDriver {
|
||||
return &ExtendMsgSetMongoDriver{mgoDB: mgoDB, ExtendMsgSetCollection: mgoDB.Collection(table.CExtendMsgSet)}
|
||||
return &ExtendMsgSetMongoDriver{mgoDB: mgoDB, ExtendMsgSetCollection: mgoDB.Collection(unrelation.CExtendMsgSet)}
|
||||
}
|
||||
|
||||
func (e *ExtendMsgSetMongoDriver) CreateExtendMsgSet(ctx context.Context, set *table.ExtendMsgSet) error {
|
||||
func (e *ExtendMsgSetMongoDriver) CreateExtendMsgSet(ctx context.Context, set *unrelation.ExtendMsgSet) error {
|
||||
_, err := e.ExtendMsgSetCollection.InsertOne(ctx, set)
|
||||
return err
|
||||
}
|
||||
@@ -31,7 +31,7 @@ type GetAllExtendMsgSetOpts struct {
|
||||
ExcludeExtendMsgs bool
|
||||
}
|
||||
|
||||
func (e *ExtendMsgSetMongoDriver) GetAllExtendMsgSet(ctx context.Context, ID string, opts *GetAllExtendMsgSetOpts) (sets []*table.ExtendMsgSet, err error) {
|
||||
func (e *ExtendMsgSetMongoDriver) GetAllExtendMsgSet(ctx context.Context, ID string, opts *GetAllExtendMsgSetOpts) (sets []*unrelation.ExtendMsgSet, err error) {
|
||||
regex := fmt.Sprintf("^%s", ID)
|
||||
var findOpts *options.FindOptions
|
||||
if opts != nil {
|
||||
@@ -51,7 +51,7 @@ func (e *ExtendMsgSetMongoDriver) GetAllExtendMsgSet(ctx context.Context, ID str
|
||||
return sets, nil
|
||||
}
|
||||
|
||||
func (e *ExtendMsgSetMongoDriver) GetExtendMsgSet(ctx context.Context, sourceID string, sessionType int32, maxMsgUpdateTime int64) (*table.ExtendMsgSet, error) {
|
||||
func (e *ExtendMsgSetMongoDriver) GetExtendMsgSet(ctx context.Context, sourceID string, sessionType int32, maxMsgUpdateTime int64) (*unrelation.ExtendMsgSet, error) {
|
||||
var err error
|
||||
findOpts := options.Find().SetLimit(1).SetSkip(0).SetSort(bson.M{"source_id": -1}).SetProjection(bson.M{"extend_msgs": 0})
|
||||
// update newest
|
||||
@@ -63,7 +63,7 @@ func (e *ExtendMsgSetMongoDriver) GetExtendMsgSet(ctx context.Context, sourceID
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
var setList []table.ExtendMsgSet
|
||||
var setList []unrelation.ExtendMsgSet
|
||||
if err := result.All(ctx, &setList); err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
@@ -74,7 +74,7 @@ func (e *ExtendMsgSetMongoDriver) GetExtendMsgSet(ctx context.Context, sourceID
|
||||
}
|
||||
|
||||
// first modify msg
|
||||
func (e *ExtendMsgSetMongoDriver) InsertExtendMsg(ctx context.Context, sourceID string, sessionType int32, msg *table.ExtendMsg) error {
|
||||
func (e *ExtendMsgSetMongoDriver) InsertExtendMsg(ctx context.Context, sourceID string, sessionType int32, msg *unrelation.ExtendMsg) error {
|
||||
set, err := e.GetExtendMsgSet(ctx, sourceID, sessionType, 0)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "")
|
||||
@@ -84,10 +84,10 @@ func (e *ExtendMsgSetMongoDriver) InsertExtendMsg(ctx context.Context, sourceID
|
||||
if set != nil {
|
||||
index = set.SplitSourceIDAndGetIndex()
|
||||
}
|
||||
err = e.CreateExtendMsgSet(ctx, &table.ExtendMsgSet{
|
||||
err = e.CreateExtendMsgSet(ctx, &unrelation.ExtendMsgSet{
|
||||
SourceID: set.GetSourceID(sourceID, index),
|
||||
SessionType: sessionType,
|
||||
ExtendMsgs: map[string]table.ExtendMsg{msg.ClientMsgID: *msg},
|
||||
ExtendMsgs: map[string]unrelation.ExtendMsg{msg.ClientMsgID: *msg},
|
||||
ExtendMsgNum: 1,
|
||||
CreateTime: msg.MsgFirstModifyTime,
|
||||
MaxMsgUpdateTime: msg.MsgFirstModifyTime,
|
||||
@@ -136,14 +136,14 @@ func (e *ExtendMsgSetMongoDriver) DeleteReactionExtendMsgSet(ctx context.Context
|
||||
return err
|
||||
}
|
||||
|
||||
func (e *ExtendMsgSetMongoDriver) GetExtendMsg(ctx context.Context, sourceID string, sessionType int32, clientMsgID string, maxMsgUpdateTime int64) (extendMsg *table.ExtendMsg, err error) {
|
||||
func (e *ExtendMsgSetMongoDriver) GetExtendMsg(ctx context.Context, sourceID string, sessionType int32, clientMsgID string, maxMsgUpdateTime int64) (extendMsg *unrelation.ExtendMsg, err error) {
|
||||
findOpts := options.Find().SetLimit(1).SetSkip(0).SetSort(bson.M{"source_id": -1}).SetProjection(bson.M{fmt.Sprintf("extend_msgs.%s", clientMsgID): 1})
|
||||
regex := fmt.Sprintf("^%s", sourceID)
|
||||
result, err := e.ExtendMsgSetCollection.Find(ctx, bson.M{"source_id": primitive.Regex{Pattern: regex}, "session_type": sessionType, "max_msg_update_time": bson.M{"$lte": maxMsgUpdateTime}}, findOpts)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
var setList []table.ExtendMsgSet
|
||||
var setList []unrelation.ExtendMsgSet
|
||||
if err := result.All(ctx, &setList); err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package unrelation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/db/table"
|
||||
"Open_IM/pkg/common/db/table/unrelation"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"fmt"
|
||||
@@ -62,14 +62,14 @@ func (m *Mongo) GetClient() *mongo.Client {
|
||||
}
|
||||
|
||||
func (m *Mongo) CreateTagIndex() {
|
||||
if err := m.createMongoIndex(table.CSendLog, false, "send_id", "-send_time"); err != nil {
|
||||
panic(err.Error() + " index create failed " + table.CSendLog + " send_id, -send_time")
|
||||
if err := m.createMongoIndex(unrelation.CSendLog, false, "send_id", "-send_time"); err != nil {
|
||||
panic(err.Error() + " index create failed " + unrelation.CSendLog + " send_id, -send_time")
|
||||
}
|
||||
if err := m.createMongoIndex(table.CTag, false, "user_id", "-create_time"); err != nil {
|
||||
panic(err.Error() + "index create failed " + table.CTag + " user_id, -create_time")
|
||||
if err := m.createMongoIndex(unrelation.CTag, false, "user_id", "-create_time"); err != nil {
|
||||
panic(err.Error() + "index create failed " + unrelation.CTag + " user_id, -create_time")
|
||||
}
|
||||
if err := m.createMongoIndex(table.CTag, true, "tag_id"); err != nil {
|
||||
panic(err.Error() + "index create failed " + table.CTag + " tag_id")
|
||||
if err := m.createMongoIndex(unrelation.CTag, true, "tag_id"); err != nil {
|
||||
panic(err.Error() + "index create failed " + unrelation.CTag + " tag_id")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,29 +80,29 @@ func (m *Mongo) CreateMsgIndex() {
|
||||
}
|
||||
|
||||
func (m *Mongo) CreateSuperGroupIndex() {
|
||||
if err := m.createMongoIndex(table.CSuperGroup, true, "group_id"); err != nil {
|
||||
panic(err.Error() + "index create failed " + table.CTag + " group_id")
|
||||
if err := m.createMongoIndex(unrelation.CSuperGroup, true, "group_id"); err != nil {
|
||||
panic(err.Error() + "index create failed " + unrelation.CTag + " group_id")
|
||||
}
|
||||
if err := m.createMongoIndex(table.CUserToSuperGroup, true, "user_id"); err != nil {
|
||||
panic(err.Error() + "index create failed " + table.CTag + "user_id")
|
||||
if err := m.createMongoIndex(unrelation.CUserToSuperGroup, true, "user_id"); err != nil {
|
||||
panic(err.Error() + "index create failed " + unrelation.CTag + "user_id")
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Mongo) CreateWorkMomentIndex() {
|
||||
if err := m.createMongoIndex(table.CWorkMoment, true, "-create_time", "work_moment_id"); err != nil {
|
||||
panic(err.Error() + "index create failed " + table.CWorkMoment + " -create_time, work_moment_id")
|
||||
if err := m.createMongoIndex(unrelation.CWorkMoment, true, "-create_time", "work_moment_id"); err != nil {
|
||||
panic(err.Error() + "index create failed " + unrelation.CWorkMoment + " -create_time, work_moment_id")
|
||||
}
|
||||
if err := m.createMongoIndex(table.CWorkMoment, true, "work_moment_id"); err != nil {
|
||||
panic(err.Error() + "index create failed " + table.CWorkMoment + " work_moment_id ")
|
||||
if err := m.createMongoIndex(unrelation.CWorkMoment, true, "work_moment_id"); err != nil {
|
||||
panic(err.Error() + "index create failed " + unrelation.CWorkMoment + " work_moment_id ")
|
||||
}
|
||||
if err := m.createMongoIndex(table.CWorkMoment, false, "user_id", "-create_time"); err != nil {
|
||||
panic(err.Error() + "index create failed " + table.CWorkMoment + "user_id, -create_time")
|
||||
if err := m.createMongoIndex(unrelation.CWorkMoment, false, "user_id", "-create_time"); err != nil {
|
||||
panic(err.Error() + "index create failed " + unrelation.CWorkMoment + "user_id, -create_time")
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Mongo) CreateExtendMsgSetIndex() {
|
||||
if err := m.createMongoIndex(table.CExtendMsgSet, true, "-create_time", "work_moment_id"); err != nil {
|
||||
panic(err.Error() + "index create failed " + table.CWorkMoment + " -create_time, work_moment_id")
|
||||
if err := m.createMongoIndex(unrelation.CExtendMsgSet, true, "-create_time", "work_moment_id"); err != nil {
|
||||
panic(err.Error() + "index create failed " + unrelation.CWorkMoment + " -create_time, work_moment_id")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package unrelation
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/table"
|
||||
"Open_IM/pkg/common/db/table/unrelation"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
@@ -20,11 +20,11 @@ type OfficeMongoDriver struct {
|
||||
}
|
||||
|
||||
func NewOfficeMongoDriver(mgoDB *mongo.Database) *OfficeMongoDriver {
|
||||
return &OfficeMongoDriver{mgoDB: mgoDB, TagCollection: mgoDB.Collection(table.CTag), TagSendLogCollection: mgoDB.Collection(table.CSendLog), WorkMomentCollection: mgoDB.Collection(table.CSendLog)}
|
||||
return &OfficeMongoDriver{mgoDB: mgoDB, TagCollection: mgoDB.Collection(unrelation.CTag), TagSendLogCollection: mgoDB.Collection(unrelation.CSendLog), WorkMomentCollection: mgoDB.Collection(unrelation.CSendLog)}
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) GetUserTags(ctx context.Context, userID string) ([]table.TagModel, error) {
|
||||
var tags []table.TagModel
|
||||
func (db *OfficeMongoDriver) GetUserTags(ctx context.Context, userID string) ([]unrelation.TagModel, error) {
|
||||
var tags []unrelation.TagModel
|
||||
cursor, err := db.TagCollection.Find(ctx, bson.M{"user_id": userID})
|
||||
if err != nil {
|
||||
return tags, err
|
||||
@@ -37,7 +37,7 @@ func (db *OfficeMongoDriver) GetUserTags(ctx context.Context, userID string) ([]
|
||||
|
||||
func (db *OfficeMongoDriver) CreateTag(ctx context.Context, userID, tagName string, userList []string) error {
|
||||
tagID := generateTagID(tagName, userID)
|
||||
tag := table.TagModel{
|
||||
tag := unrelation.TagModel{
|
||||
UserID: userID,
|
||||
TagID: tagID,
|
||||
TagName: tagName,
|
||||
@@ -47,8 +47,8 @@ func (db *OfficeMongoDriver) CreateTag(ctx context.Context, userID, tagName stri
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) GetTagByID(ctx context.Context, userID, tagID string) (table.TagModel, error) {
|
||||
var tag table.TagModel
|
||||
func (db *OfficeMongoDriver) GetTagByID(ctx context.Context, userID, tagID string) (unrelation.TagModel, error) {
|
||||
var tag unrelation.TagModel
|
||||
err := db.TagCollection.FindOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}).Decode(&tag)
|
||||
return tag, err
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func (db *OfficeMongoDriver) DeleteTag(ctx context.Context, userID, tagID string
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) SetTag(ctx context.Context, userID, tagID, newName string, increaseUserIDList []string, reduceUserIDList []string) error {
|
||||
var tag table.TagModel
|
||||
var tag unrelation.TagModel
|
||||
if err := db.TagCollection.FindOne(ctx, bson.M{"tag_id": tagID, "user_id": userID}).Decode(&tag); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -92,18 +92,18 @@ func (db *OfficeMongoDriver) SetTag(ctx context.Context, userID, tagID, newName
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) GetUserIDListByTagID(ctx context.Context, userID, tagID string) ([]string, error) {
|
||||
var tag table.TagModel
|
||||
var tag unrelation.TagModel
|
||||
err := db.TagCollection.FindOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}).Decode(&tag)
|
||||
return tag.UserList, err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) SaveTagSendLog(ctx context.Context, tagSendLog *table.TagSendLogModel) error {
|
||||
func (db *OfficeMongoDriver) SaveTagSendLog(ctx context.Context, tagSendLog *unrelation.TagSendLogModel) error {
|
||||
_, err := db.TagSendLogCollection.InsertOne(ctx, tagSendLog)
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) GetTagSendLogs(ctx context.Context, userID string, showNumber, pageNumber int32) ([]table.TagSendLogModel, error) {
|
||||
var tagSendLogs []table.TagSendLogModel
|
||||
func (db *OfficeMongoDriver) GetTagSendLogs(ctx context.Context, userID string, showNumber, pageNumber int32) ([]unrelation.TagSendLogModel, error) {
|
||||
var tagSendLogs []unrelation.TagSendLogModel
|
||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"send_time": -1})
|
||||
cursor, err := db.TagSendLogCollection.Find(ctx, bson.M{"send_id": userID}, findOpts)
|
||||
if err != nil {
|
||||
@@ -113,7 +113,7 @@ func (db *OfficeMongoDriver) GetTagSendLogs(ctx context.Context, userID string,
|
||||
return tagSendLogs, err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) CreateOneWorkMoment(ctx context.Context, workMoment *table.WorkMoment) error {
|
||||
func (db *OfficeMongoDriver) CreateOneWorkMoment(ctx context.Context, workMoment *unrelation.WorkMoment) error {
|
||||
workMomentID := generateWorkMomentID(workMoment.UserID)
|
||||
workMoment.WorkMomentID = workMomentID
|
||||
workMoment.CreateTime = int32(time.Now().Unix())
|
||||
@@ -136,13 +136,13 @@ func (db *OfficeMongoDriver) DeleteComment(ctx context.Context, workMomentID, co
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) GetWorkMomentByID(ctx context.Context, workMomentID string) (*table.WorkMoment, error) {
|
||||
workMoment := &table.WorkMoment{}
|
||||
func (db *OfficeMongoDriver) GetWorkMomentByID(ctx context.Context, workMomentID string) (*unrelation.WorkMoment, error) {
|
||||
workMoment := &unrelation.WorkMoment{}
|
||||
err := db.WorkMomentCollection.FindOne(ctx, bson.M{"work_moment_id": workMomentID}).Decode(workMoment)
|
||||
return workMoment, err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) LikeOneWorkMoment(ctx context.Context, likeUserID, userName, workMomentID string) (*table.WorkMoment, bool, error) {
|
||||
func (db *OfficeMongoDriver) LikeOneWorkMoment(ctx context.Context, likeUserID, userName, workMomentID string) (*unrelation.WorkMoment, bool, error) {
|
||||
workMoment, err := db.GetWorkMomentByID(ctx, workMomentID)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
@@ -155,7 +155,7 @@ func (db *OfficeMongoDriver) LikeOneWorkMoment(ctx context.Context, likeUserID,
|
||||
}
|
||||
}
|
||||
if !isAlreadyLike {
|
||||
workMoment.LikeUserList = append(workMoment.LikeUserList, &table.CommonUserModel{UserID: likeUserID, UserName: userName})
|
||||
workMoment.LikeUserList = append(workMoment.LikeUserList, &unrelation.CommonUserModel{UserID: likeUserID, UserName: userName})
|
||||
}
|
||||
_, err = db.WorkMomentCollection.UpdateOne(ctx, bson.M{"work_moment_id": workMomentID}, bson.M{"$set": bson.M{"like_user_list": workMoment.LikeUserList}})
|
||||
return workMoment, !isAlreadyLike, err
|
||||
@@ -165,15 +165,15 @@ func (db *OfficeMongoDriver) SetUserWorkMomentsLevel(ctx context.Context, userID
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) CommentOneWorkMoment(ctx context.Context, comment *table.Comment, workMomentID string) (table.WorkMoment, error) {
|
||||
func (db *OfficeMongoDriver) CommentOneWorkMoment(ctx context.Context, comment *unrelation.Comment, workMomentID string) (unrelation.WorkMoment, error) {
|
||||
comment.ContentID = generateWorkMomentCommentID(workMomentID)
|
||||
var workMoment table.WorkMoment
|
||||
var workMoment unrelation.WorkMoment
|
||||
err := db.WorkMomentCollection.FindOneAndUpdate(ctx, bson.M{"work_moment_id": workMomentID}, bson.M{"$push": bson.M{"comments": comment}}).Decode(&workMoment)
|
||||
return workMoment, err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) GetUserSelfWorkMoments(ctx context.Context, userID string, showNumber, pageNumber int32) ([]table.WorkMoment, error) {
|
||||
var workMomentList []table.WorkMoment
|
||||
func (db *OfficeMongoDriver) GetUserSelfWorkMoments(ctx context.Context, userID string, showNumber, pageNumber int32) ([]unrelation.WorkMoment, error) {
|
||||
var workMomentList []unrelation.WorkMoment
|
||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
||||
result, err := db.WorkMomentCollection.Find(ctx, bson.M{"user_id": userID}, findOpts)
|
||||
if err != nil {
|
||||
@@ -183,8 +183,8 @@ func (db *OfficeMongoDriver) GetUserSelfWorkMoments(ctx context.Context, userID
|
||||
return workMomentList, err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) GetUserWorkMoments(ctx context.Context, opUserID, userID string, showNumber, pageNumber int32, friendIDList []string) ([]table.WorkMoment, error) {
|
||||
var workMomentList []table.WorkMoment
|
||||
func (db *OfficeMongoDriver) GetUserWorkMoments(ctx context.Context, opUserID, userID string, showNumber, pageNumber int32, friendIDList []string) ([]unrelation.WorkMoment, error) {
|
||||
var workMomentList []unrelation.WorkMoment
|
||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
||||
result, err := db.WorkMomentCollection.Find(ctx, bson.D{ // 等价条件: select * from
|
||||
{"user_id", userID},
|
||||
@@ -201,8 +201,8 @@ func (db *OfficeMongoDriver) GetUserWorkMoments(ctx context.Context, opUserID, u
|
||||
return workMomentList, err
|
||||
}
|
||||
|
||||
func (db *OfficeMongoDriver) GetUserFriendWorkMoments(ctx context.Context, showNumber, pageNumber int32, userID string, friendIDList []string) ([]table.WorkMoment, error) {
|
||||
var workMomentList []table.WorkMoment
|
||||
func (db *OfficeMongoDriver) GetUserFriendWorkMoments(ctx context.Context, showNumber, pageNumber int32, userID string, friendIDList []string) ([]unrelation.WorkMoment, error) {
|
||||
var workMomentList []unrelation.WorkMoment
|
||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
||||
var filter bson.D
|
||||
permissionFilter := bson.D{
|
||||
|
||||
@@ -2,7 +2,7 @@ package unrelation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/db/table"
|
||||
"Open_IM/pkg/common/db/table/unrelation"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
@@ -20,13 +20,13 @@ type SuperGroupMongoDriver struct {
|
||||
|
||||
func NewSuperGroupMongoDriver(mgoClient *mongo.Client) *SuperGroupMongoDriver {
|
||||
mgoDB := mgoClient.Database(config.Config.Mongo.DBDatabase)
|
||||
return &SuperGroupMongoDriver{MgoDB: mgoDB, MgoClient: mgoClient, superGroupCollection: mgoDB.Collection(table.CSuperGroup), userToSuperGroupCollection: mgoDB.Collection(table.CUserToSuperGroup)}
|
||||
return &SuperGroupMongoDriver{MgoDB: mgoDB, MgoClient: mgoClient, superGroupCollection: mgoDB.Collection(unrelation.CSuperGroup), userToSuperGroupCollection: mgoDB.Collection(unrelation.CUserToSuperGroup)}
|
||||
}
|
||||
|
||||
func (db *SuperGroupMongoDriver) CreateSuperGroup(sCtx mongo.SessionContext, groupID string, initMemberIDList []string) error {
|
||||
superGroup := table.SuperGroupModel{
|
||||
GroupID: groupID,
|
||||
MemberIDList: initMemberIDList,
|
||||
func (db *SuperGroupMongoDriver) CreateSuperGroup(sCtx mongo.SessionContext, groupID string, initMemberIDs []string) error {
|
||||
superGroup := unrelation.SuperGroupModel{
|
||||
GroupID: groupID,
|
||||
MemberIDs: initMemberIDs,
|
||||
}
|
||||
_, err := db.superGroupCollection.InsertOne(sCtx, superGroup)
|
||||
if err != nil {
|
||||
@@ -36,7 +36,7 @@ func (db *SuperGroupMongoDriver) CreateSuperGroup(sCtx mongo.SessionContext, gro
|
||||
opts := &options.UpdateOptions{
|
||||
Upsert: &upsert,
|
||||
}
|
||||
for _, userID := range initMemberIDList {
|
||||
for _, userID := range initMemberIDs {
|
||||
_, err = db.userToSuperGroupCollection.UpdateOne(sCtx, bson.M{"user_id": userID}, bson.M{"$addToSet": bson.M{"group_id_list": groupID}}, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -46,16 +46,16 @@ func (db *SuperGroupMongoDriver) CreateSuperGroup(sCtx mongo.SessionContext, gro
|
||||
|
||||
}
|
||||
|
||||
func (db *SuperGroupMongoDriver) GetSuperGroup(ctx context.Context, groupID string) (*table.SuperGroupModel, error) {
|
||||
superGroup := table.SuperGroupModel{}
|
||||
func (db *SuperGroupMongoDriver) GetSuperGroup(ctx context.Context, groupID string) (*unrelation.SuperGroupModel, error) {
|
||||
superGroup := unrelation.SuperGroupModel{}
|
||||
err := db.superGroupCollection.FindOne(ctx, bson.M{"group_id": groupID}).Decode(&superGroup)
|
||||
return &superGroup, err
|
||||
}
|
||||
|
||||
func (db *SuperGroupMongoDriver) AddUserToSuperGroup(ctx context.Context, groupID string, userIDList []string) error {
|
||||
func (db *SuperGroupMongoDriver) AddUserToSuperGroup(ctx context.Context, groupID string, userIDs []string) error {
|
||||
opts := options.Session().SetDefaultReadConcern(readconcern.Majority())
|
||||
return db.MgoDB.Client().UseSessionWithOptions(ctx, opts, func(sCtx mongo.SessionContext) error {
|
||||
_, err := db.superGroupCollection.UpdateOne(sCtx, bson.M{"group_id": groupID}, bson.M{"$addToSet": bson.M{"member_id_list": bson.M{"$each": userIDList}}})
|
||||
_, err := db.superGroupCollection.UpdateOne(sCtx, bson.M{"group_id": groupID}, bson.M{"$addToSet": bson.M{"member_id_list": bson.M{"$each": userIDs}}})
|
||||
if err != nil {
|
||||
_ = sCtx.AbortTransaction(ctx)
|
||||
return err
|
||||
@@ -64,7 +64,7 @@ func (db *SuperGroupMongoDriver) AddUserToSuperGroup(ctx context.Context, groupI
|
||||
opts := &options.UpdateOptions{
|
||||
Upsert: &upsert,
|
||||
}
|
||||
for _, userID := range userIDList {
|
||||
for _, userID := range userIDs {
|
||||
_, err = db.userToSuperGroupCollection.UpdateOne(sCtx, bson.M{"user_id": userID}, bson.M{"$addToSet": bson.M{"group_id_list": groupID}}, opts)
|
||||
if err != nil {
|
||||
_ = sCtx.AbortTransaction(ctx)
|
||||
@@ -75,15 +75,15 @@ func (db *SuperGroupMongoDriver) AddUserToSuperGroup(ctx context.Context, groupI
|
||||
})
|
||||
}
|
||||
|
||||
func (db *SuperGroupMongoDriver) RemoverUserFromSuperGroup(ctx context.Context, groupID string, userIDList []string) error {
|
||||
func (db *SuperGroupMongoDriver) RemoverUserFromSuperGroup(ctx context.Context, groupID string, userIDs []string) error {
|
||||
opts := options.Session().SetDefaultReadConcern(readconcern.Majority())
|
||||
return db.MgoDB.Client().UseSessionWithOptions(ctx, opts, func(sCtx mongo.SessionContext) error {
|
||||
_, err := db.superGroupCollection.UpdateOne(sCtx, bson.M{"group_id": groupID}, bson.M{"$pull": bson.M{"member_id_list": bson.M{"$in": userIDList}}})
|
||||
_, err := db.superGroupCollection.UpdateOne(sCtx, bson.M{"group_id": groupID}, bson.M{"$pull": bson.M{"member_id_list": bson.M{"$in": userIDs}}})
|
||||
if err != nil {
|
||||
_ = sCtx.AbortTransaction(ctx)
|
||||
return err
|
||||
}
|
||||
err = db.RemoveGroupFromUser(sCtx, groupID, userIDList)
|
||||
err = db.RemoveGroupFromUser(sCtx, groupID, userIDs)
|
||||
if err != nil {
|
||||
_ = sCtx.AbortTransaction(ctx)
|
||||
return err
|
||||
@@ -92,8 +92,8 @@ func (db *SuperGroupMongoDriver) RemoverUserFromSuperGroup(ctx context.Context,
|
||||
})
|
||||
}
|
||||
|
||||
func (db *SuperGroupMongoDriver) GetSuperGroupByUserID(ctx context.Context, userID string) (*table.UserToSuperGroupModel, error) {
|
||||
var user table.UserToSuperGroupModel
|
||||
func (db *SuperGroupMongoDriver) GetSuperGroupByUserID(ctx context.Context, userID string) (*unrelation.UserToSuperGroupModel, error) {
|
||||
var user unrelation.UserToSuperGroupModel
|
||||
err := db.userToSuperGroupCollection.FindOne(ctx, bson.M{"user_id": userID}).Decode(&user)
|
||||
return &user, utils.Wrap(err, "")
|
||||
}
|
||||
@@ -101,13 +101,13 @@ func (db *SuperGroupMongoDriver) GetSuperGroupByUserID(ctx context.Context, user
|
||||
func (db *SuperGroupMongoDriver) DeleteSuperGroup(ctx context.Context, groupID string) error {
|
||||
opts := options.Session().SetDefaultReadConcern(readconcern.Majority())
|
||||
return db.MgoDB.Client().UseSessionWithOptions(ctx, opts, func(sCtx mongo.SessionContext) error {
|
||||
superGroup := &table.SuperGroupModel{}
|
||||
superGroup := &unrelation.SuperGroupModel{}
|
||||
_, err := db.superGroupCollection.DeleteOne(sCtx, bson.M{"group_id": groupID})
|
||||
if err != nil {
|
||||
_ = sCtx.AbortTransaction(ctx)
|
||||
return err
|
||||
}
|
||||
if err = db.RemoveGroupFromUser(sCtx, groupID, superGroup.MemberIDList); err != nil {
|
||||
if err = db.RemoveGroupFromUser(sCtx, groupID, superGroup.MemberIDs); err != nil {
|
||||
_ = sCtx.AbortTransaction(ctx)
|
||||
return err
|
||||
}
|
||||
@@ -115,7 +115,7 @@ func (db *SuperGroupMongoDriver) DeleteSuperGroup(ctx context.Context, groupID s
|
||||
})
|
||||
}
|
||||
|
||||
func (db *SuperGroupMongoDriver) RemoveGroupFromUser(sCtx context.Context, groupID string, userIDList []string) error {
|
||||
_, err := db.userToSuperGroupCollection.UpdateOne(sCtx, bson.M{"user_id": bson.M{"$in": userIDList}}, bson.M{"$pull": bson.M{"group_id_list": groupID}})
|
||||
func (db *SuperGroupMongoDriver) RemoveGroupFromUser(sCtx context.Context, groupID string, userIDs []string) error {
|
||||
_, err := db.userToSuperGroupCollection.UpdateOne(sCtx, bson.M{"user_id": bson.M{"$in": userIDs}}, bson.M{"$pull": bson.M{"group_id_list": groupID}})
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user