mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-16 23:09:01 +08:00
Merge branch 'errcode' of github.com:OpenIMSDK/Open-IM-Server into errcode
Conflicts: pkg/common/db/cache/conversation.go
This commit is contained in:
Vendored
+15
-11
@@ -13,18 +13,22 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
conversationKey = "CONVERSATION:"
|
||||
conversationIDsKey = "CONVERSATION_IDS:"
|
||||
recvMsgOptKey = "RECV_MSG_OPT:"
|
||||
superGroupRecvMsgNotNotifyUserIDsKey = "SUPER_GROUP_RECV_MSG_NOT_NOTIFY_USER_IDS:"
|
||||
conversationExpireTime = time.Second * 60 * 60 * 12
|
||||
)
|
||||
type DBFun func() (string, error)
|
||||
|
||||
type ConversationCache struct {
|
||||
conversationDB *relation.ConversationGorm
|
||||
expireTime time.Duration
|
||||
rcClient *rockscache.Client
|
||||
type ConversationCache interface {
|
||||
GetUserConversationIDListFromCache(userID string, fn DBFun) ([]string, error)
|
||||
DelUserConversationIDListFromCache(userID string) error
|
||||
GetConversationFromCache(ownerUserID, conversationID string, fn DBFun) (*table.ConversationModel, error)
|
||||
GetConversationsFromCache(ownerUserID string, conversationIDList []string, fn DBFun) ([]*table.ConversationModel, error)
|
||||
GetUserAllConversationList(ownerUserID string, fn DBFun) ([]*table.ConversationModel, error)
|
||||
DelConversationFromCache(ownerUserID, conversationID string) error
|
||||
}
|
||||
type ConversationRedis struct {
|
||||
rcClient *rockscache.Client
|
||||
}
|
||||
|
||||
func NewConversationRedis(rcClient *rockscache.Client) *ConversationRedis {
|
||||
return &ConversationRedis{rcClient: rcClient}
|
||||
}
|
||||
|
||||
func NewConversationCache(rdb redis.UniversalClient, conversationDB *relation.ConversationGorm, options rockscache.Options) *ConversationCache {
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/cache"
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"Open_IM/pkg/common/db/table"
|
||||
"context"
|
||||
)
|
||||
|
||||
type ConversationInterface interface {
|
||||
//GetUserIDExistConversation 获取拥有该会话的的用户ID列表
|
||||
GetUserIDExistConversation(ctx context.Context, userIDList []string, conversationID string) ([]string, error)
|
||||
//UpdateUserConversationFiled 更新用户该会话的属性信息
|
||||
UpdateUsersConversationFiled(ctx context.Context, UserIDList []string, conversationID string, args map[string]interface{}) error
|
||||
//CreateConversation 创建一批新的会话
|
||||
CreateConversation(ctx context.Context, conversations []*table.ConversationModel) error
|
||||
//SyncPeerUserPrivateConversation 同步对端私聊会话内部保证事务操作
|
||||
SyncPeerUserPrivateConversationTx(ctx context.Context, conversation *table.ConversationModel) error
|
||||
//FindConversations 根据会话ID获取某个用户的多个会话
|
||||
FindConversations(ctx context.Context, ownerUserID string, conversationID []string) ([]*table.ConversationModel, error)
|
||||
//GetUserAllConversation 获取一个用户在服务器上所有的会话
|
||||
GetUserAllConversation(ctx context.Context, ownerUserID string) ([]*table.ConversationModel, error)
|
||||
//SetUserConversations 设置用户多个会话属性,如果会话不存在则创建,否则更新,内部保证原子性
|
||||
SetUserConversations(ctx context.Context, ownerUserID string, conversations []*table.ConversationModel) error
|
||||
}
|
||||
type ConversationController struct {
|
||||
database ConversationDataBaseInterface
|
||||
}
|
||||
|
||||
func NewConversationController(database ConversationDataBaseInterface) *ConversationController {
|
||||
return &ConversationController{database: database}
|
||||
}
|
||||
|
||||
func (c *ConversationController) GetUserIDExistConversation(ctx context.Context, userIDList []string, conversationID string) ([]string, error) {
|
||||
return c.database.GetUserIDExistConversation(ctx, userIDList, conversationID)
|
||||
}
|
||||
|
||||
func (c ConversationController) UpdateUsersConversationFiled(ctx context.Context, UserIDList []string, conversationID string, args map[string]interface{}) error {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (c ConversationController) CreateConversation(ctx context.Context, conversations []*table.ConversationModel) error {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (c ConversationController) SyncPeerUserPrivateConversationTx(ctx context.Context, conversation *table.ConversationModel) error {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (c ConversationController) FindConversations(ctx context.Context, ownerUserID string, conversationID []string) ([]*table.ConversationModel, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (c ConversationController) GetUserAllConversation(ctx context.Context, ownerUserID string) ([]*table.ConversationModel, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
func (c ConversationController) SetUserConversations(ctx context.Context, ownerUserID string, conversations []*table.ConversationModel) error {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
var _ ConversationInterface = (*ConversationController)(nil)
|
||||
|
||||
type ConversationDataBaseInterface interface {
|
||||
//GetUserIDExistConversation 获取拥有该会话的的用户ID列表
|
||||
GetUserIDExistConversation(ctx context.Context, userIDList []string, conversationID string) ([]string, error)
|
||||
//UpdateUserConversationFiled 更新用户该会话的属性信息
|
||||
UpdateUsersConversationFiled(ctx context.Context, UserIDList []string, conversationID string, args map[string]interface{}) error
|
||||
//CreateConversation 创建一批新的会话
|
||||
CreateConversation(ctx context.Context, conversations []*table.ConversationModel) error
|
||||
//SyncPeerUserPrivateConversation 同步对端私聊会话内部保证事务操作
|
||||
SyncPeerUserPrivateConversationTx(ctx context.Context, conversation *table.ConversationModel) error
|
||||
//FindConversations 根据会话ID获取某个用户的多个会话
|
||||
FindConversations(ctx context.Context, ownerUserID string, conversationID []string) ([]*table.ConversationModel, error)
|
||||
//GetUserAllConversation 获取一个用户在服务器上所有的会话
|
||||
GetUserAllConversation(ctx context.Context, ownerUserID string) ([]*table.ConversationModel, error)
|
||||
//SetUserConversations 设置用户多个会话属性,如果会话不存在则创建,否则更新,内部保证原子性
|
||||
SetUserConversations(ctx context.Context, ownerUserID string, conversations []*table.ConversationModel) error
|
||||
}
|
||||
type ConversationDataBase struct {
|
||||
db relation.Conversation
|
||||
cache cache.ConversationCache
|
||||
}
|
||||
|
||||
func (c ConversationDataBase) GetUserIDExistConversation(ctx context.Context, userIDList []string, conversationID string) ([]string, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (c ConversationDataBase) UpdateUsersConversationFiled(ctx context.Context, UserIDList []string, conversationID string, args map[string]interface{}) error {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (c ConversationDataBase) CreateConversation(ctx context.Context, conversations []*table.ConversationModel) error {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (c ConversationDataBase) SyncPeerUserPrivateConversationTx(ctx context.Context, conversation *table.ConversationModel) error {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (c ConversationDataBase) FindConversations(ctx context.Context, ownerUserID string, conversationID []string) ([]*table.ConversationModel, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (c ConversationDataBase) GetUserAllConversation(ctx context.Context, ownerUserID string) ([]*table.ConversationModel, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (c ConversationDataBase) SetUserConversations(ctx context.Context, ownerUserID string, conversations []*table.ConversationModel) error {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func NewConversationDataBase(db relation.Conversation, cache cache.ConversationCache) *ConversationDataBase {
|
||||
return &ConversationDataBase{db: db, cache: cache}
|
||||
}
|
||||
|
||||
//func NewConversationController(db *gorm.DB, rdb redis.UniversalClient) ConversationInterface {
|
||||
// groupController := &ConversationController{database: newGroupDatabase(db, rdb, mgoClient)}
|
||||
// return groupController
|
||||
//}
|
||||
@@ -2,8 +2,8 @@ package controller
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"Open_IM/pkg/common/db/table"
|
||||
relation1 "Open_IM/pkg/common/db/relation"
|
||||
"Open_IM/pkg/common/db/table/relation"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
@@ -15,25 +15,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 []*relation.FriendModel, revFriends []*relation.FriendModel) (err error)
|
||||
// RefuseFriendRequest 拒绝好友申请
|
||||
RefuseFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error)
|
||||
RefuseFriendRequest(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error)
|
||||
// AgreeFriendRequest 同意好友申请
|
||||
AgreeFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error)
|
||||
AgreeFriendRequest(ctx context.Context, friendRequest *relation.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 []*relation.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 []*relation.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 []*relation.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 []*relation.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 []*relation.FriendModel, err error)
|
||||
}
|
||||
|
||||
type FriendController struct {
|
||||
@@ -55,17 +55,17 @@ func (f *FriendController) AddFriendRequest(ctx context.Context, fromUserID, toU
|
||||
}
|
||||
|
||||
// BecomeFriend 先判断是否在好友表,如果在则不插入
|
||||
func (f *FriendController) BecomeFriend(ctx context.Context, ownerUserID string, friends []*table.FriendModel) (err error) {
|
||||
func (f *FriendController) BecomeFriend(ctx context.Context, ownerUserID string, friends []*relation.FriendModel) (err error) {
|
||||
return f.database.BecomeFriend(ctx, ownerUserID, friends)
|
||||
}
|
||||
|
||||
// RefuseFriendRequest 拒绝好友申请
|
||||
func (f *FriendController) RefuseFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error) {
|
||||
func (f *FriendController) RefuseFriendRequest(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error) {
|
||||
return f.database.RefuseFriendRequest(ctx, friendRequest)
|
||||
}
|
||||
|
||||
// AgreeFriendRequest 同意好友申请
|
||||
func (f *FriendController) AgreeFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error) {
|
||||
func (f *FriendController) AgreeFriendRequest(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error) {
|
||||
return f.database.AgreeFriendRequest(ctx, friendRequest)
|
||||
}
|
||||
|
||||
@@ -80,27 +80,27 @@ 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, total int64, err error) {
|
||||
func (f *FriendController) FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*relation.FriendModel, total int64, err error) {
|
||||
return f.database.FindOwnerFriends(ctx, ownerUserID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// FindInWhoseFriends friendUserID在哪些人的好友列表中
|
||||
func (f *FriendController) FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*table.FriendModel, total int64, err error) {
|
||||
func (f *FriendController) FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*relation.FriendModel, total int64, err error) {
|
||||
return f.database.FindInWhoseFriends(ctx, friendUserID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// FindFriendRequestFromMe 获取我发出去的好友申请
|
||||
func (f *FriendController) FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*table.FriendRequestModel, total int64, err error) {
|
||||
func (f *FriendController) FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequestModel, total int64, err error) {
|
||||
return f.database.FindFriendRequestFromMe(ctx, userID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// FindFriendRequestToMe 获取我收到的的好友申请
|
||||
func (f *FriendController) FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*table.FriendRequestModel, total int64, err error) {
|
||||
func (f *FriendController) FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequestModel, total int64, err error) {
|
||||
return f.database.FindFriendRequestToMe(ctx, userID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// 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 []*relation.FriendModel, err error) {
|
||||
return f.database.FindFriends(ctx, ownerUserID, friendUserIDs)
|
||||
|
||||
}
|
||||
@@ -111,34 +111,34 @@ type FriendDatabaseInterface interface {
|
||||
// AddFriendRequest 增加或者更新好友申请
|
||||
AddFriendRequest(ctx context.Context, fromUserID, toUserID string, reqMsg string, ex string) (err error)
|
||||
// BecomeFriend 先判断是否在好友表,如果在则不插入
|
||||
BecomeFriend(ctx context.Context, ownerUserID string, friends []*table.FriendModel) (err error)
|
||||
BecomeFriend(ctx context.Context, ownerUserID string, friends []*relation.FriendModel) (err error)
|
||||
// RefuseFriendRequest 拒绝好友申请
|
||||
RefuseFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error)
|
||||
RefuseFriendRequest(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error)
|
||||
// AgreeFriendRequest 同意好友申请
|
||||
AgreeFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error)
|
||||
AgreeFriendRequest(ctx context.Context, friendRequest *relation.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 []*relation.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 []*relation.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 []*relation.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 []*relation.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 []*relation.FriendModel, err error)
|
||||
}
|
||||
|
||||
type FriendDatabase struct {
|
||||
friend *relation.FriendGorm
|
||||
friendRequest *relation.FriendRequestGorm
|
||||
friend *relation1.FriendGorm
|
||||
friendRequest *relation1.FriendRequestGorm
|
||||
}
|
||||
|
||||
func NewFriendDatabase(db *gorm.DB) *FriendDatabase {
|
||||
return &FriendDatabase{friend: relation.NewFriendGorm(db), friendRequest: relation.NewFriendRequestGorm(db)}
|
||||
return &FriendDatabase{friend: relation1.NewFriendGorm(db), friendRequest: relation1.NewFriendRequestGorm(db)}
|
||||
}
|
||||
|
||||
// CheckIn 检查user2是否在user1的好友列表中(inUser1Friends==true) 检查user1是否在user2的好友列表中(inUser2Friends==true)
|
||||
@@ -157,11 +157,31 @@ func (f *FriendDatabase) CheckIn(ctx context.Context, userID1, userID2 string) (
|
||||
|
||||
// AddFriendRequest 增加或者更新好友申请
|
||||
func (f *FriendDatabase) AddFriendRequest(ctx context.Context, fromUserID, toUserID string, reqMsg string, ex string) (err error) {
|
||||
|
||||
return f.friendRequest.DB.Transaction(func(tx *gorm.DB) error {
|
||||
fq, err := f.friendRequest.Find(ctx, fromUserID, toUserID, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if fq != nil { //
|
||||
m := make(map[string]interface{}, 1)
|
||||
m["handle_result"] = 0
|
||||
m["handle_msg"] = ""
|
||||
m["req_msg"] = reqMsg
|
||||
m["ex"] = ex
|
||||
if err := f.friendRequest.UpdateByMap(ctx, fromUserID, toUserID, m, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := f.friendRequest.Create(ctx, []*relation.FriendRequestModel{&relation.FriendRequestModel{FromUserID: fromUserID, ToUserID: toUserID, ReqMsg: reqMsg, Ex: ex}}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// 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 []*relation.FriendModel) (err error) {
|
||||
return f.friend.DB.Transaction(func(tx *gorm.DB) error {
|
||||
//先find 找出重复的 去掉重复的
|
||||
friendUserIDs := make([]string, 0, len(friends))
|
||||
@@ -173,7 +193,7 @@ func (f *FriendDatabase) BecomeFriend(ctx context.Context, ownerUserID string, f
|
||||
return err
|
||||
}
|
||||
fs1 = append(fs1, friends...)
|
||||
fs11 := utils.DistinctAny(fs1, func(e *table.FriendModel) string {
|
||||
fs11 := utils.DistinctAny(fs1, func(e *relation.FriendModel) string {
|
||||
return utils.UniqueJoin(e.OwnerUserID, e.FriendUserID)
|
||||
})
|
||||
err = f.friend.Create(ctx, fs11, tx)
|
||||
@@ -185,9 +205,9 @@ func (f *FriendDatabase) BecomeFriend(ctx context.Context, ownerUserID string, f
|
||||
return err
|
||||
}
|
||||
for _, v := range friends {
|
||||
fs2 = append(fs2, &table.FriendModel{OwnerUserID: v.FriendUserID, FriendUserID: ownerUserID})
|
||||
fs2 = append(fs2, &relation.FriendModel{OwnerUserID: v.FriendUserID, FriendUserID: ownerUserID})
|
||||
}
|
||||
fs22 := utils.DistinctAny(fs2, func(e *table.FriendModel) string {
|
||||
fs22 := utils.DistinctAny(fs2, func(e *relation.FriendModel) string {
|
||||
return utils.UniqueJoin(e.OwnerUserID, e.FriendUserID)
|
||||
})
|
||||
err = f.friend.Create(ctx, fs22, tx)
|
||||
@@ -199,9 +219,9 @@ 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 *relation.FriendRequestModel) (err error) {
|
||||
friendRequest.HandleResult = constant.FriendResponseRefuse
|
||||
err = f.friendRequest.Update(ctx, []*table.FriendRequestModel{friendRequest})
|
||||
err = f.friendRequest.Update(ctx, []*relation.FriendRequestModel{friendRequest})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -209,7 +229,7 @@ func (f *FriendDatabase) RefuseFriendRequest(ctx context.Context, friendRequest
|
||||
}
|
||||
|
||||
// AgreeFriendRequest 同意好友申请
|
||||
func (f *FriendDatabase) AgreeFriendRequest(ctx context.Context, friendRequest *table.FriendRequestModel) (err error) {
|
||||
func (f *FriendDatabase) AgreeFriendRequest(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error) {
|
||||
return f.friend.DB.Transaction(func(tx *gorm.DB) error {
|
||||
//先find 找出重复的 去掉重复的
|
||||
fs1, err := f.friend.FindFriends(ctx, friendRequest.FromUserID, []string{friendRequest.ToUserID}, tx)
|
||||
@@ -217,8 +237,8 @@ func (f *FriendDatabase) AgreeFriendRequest(ctx context.Context, friendRequest *
|
||||
return err
|
||||
}
|
||||
if len(fs1) == 0 {
|
||||
err = f.friend.Create(ctx, []*table.FriendModel{
|
||||
&table.FriendModel{
|
||||
err = f.friend.Create(ctx, []*relation.FriendModel{
|
||||
&relation.FriendModel{
|
||||
OwnerUserID: friendRequest.FromUserID,
|
||||
FriendUserID: friendRequest.ToUserID,
|
||||
OperatorUserID: friendRequest.ToUserID,
|
||||
@@ -230,8 +250,8 @@ func (f *FriendDatabase) AgreeFriendRequest(ctx context.Context, friendRequest *
|
||||
}
|
||||
fs2, err := f.friend.FindReversalFriends(ctx, friendRequest.ToUserID, []string{friendRequest.FromUserID}, tx)
|
||||
if len(fs2) == 0 {
|
||||
err = f.friend.Create(ctx, []*table.FriendModel{
|
||||
&table.FriendModel{
|
||||
err = f.friend.Create(ctx, []*relation.FriendModel{
|
||||
&relation.FriendModel{
|
||||
OwnerUserID: friendRequest.ToUserID,
|
||||
FriendUserID: friendRequest.FromUserID,
|
||||
OperatorUserID: friendRequest.ToUserID,
|
||||
@@ -242,7 +262,7 @@ func (f *FriendDatabase) AgreeFriendRequest(ctx context.Context, friendRequest *
|
||||
}
|
||||
}
|
||||
friendRequest.HandleResult = constant.FriendResponseAgree
|
||||
err = f.friendRequest.Update(ctx, []*table.FriendRequestModel{friendRequest}, tx)
|
||||
err = f.friendRequest.Update(ctx, []*relation.FriendRequestModel{friendRequest}, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -261,27 +281,27 @@ 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, total int64, err error) {
|
||||
func (f *FriendDatabase) FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*relation.FriendModel, total int64, err error) {
|
||||
return f.friend.FindOwnerFriends(ctx, ownerUserID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// FindInWhoseFriends friendUserID在哪些人的好友列表中
|
||||
func (f *FriendDatabase) FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*table.FriendModel, total int64, err error) {
|
||||
func (f *FriendDatabase) FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*relation.FriendModel, total int64, err error) {
|
||||
return f.friend.FindInWhoseFriends(ctx, friendUserID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// FindFriendRequestFromMe 获取我发出去的好友申请
|
||||
func (f *FriendDatabase) FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*table.FriendRequestModel, total int64, err error) {
|
||||
func (f *FriendDatabase) FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequestModel, total int64, err error) {
|
||||
return f.friendRequest.FindFromUserID(ctx, userID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// FindFriendRequestToMe 获取我收到的的好友申请
|
||||
func (f *FriendDatabase) FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*table.FriendRequestModel, total int64, err error) {
|
||||
func (f *FriendDatabase) FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequestModel, total int64, err error) {
|
||||
return f.friendRequest.FindToUserID(ctx, userID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// 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 []*relation.FriendModel, err error) {
|
||||
friends, err = f.friend.FindFriends(ctx, ownerUserID, friendUserIDs)
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
+422
-138
@@ -1,10 +1,13 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/cache"
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
relation2 "Open_IM/pkg/common/db/table/relation"
|
||||
unrelation2 "Open_IM/pkg/common/db/table/unrelation"
|
||||
"Open_IM/pkg/common/db/unrelation"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/dtm-labs/rockscache"
|
||||
_ "github.com/dtm-labs/rockscache"
|
||||
@@ -14,29 +17,43 @@ import (
|
||||
)
|
||||
|
||||
type GroupInterface interface {
|
||||
FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error)
|
||||
// group
|
||||
FindGroup(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error)
|
||||
SearchGroup(ctx context.Context, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error)
|
||||
TakeGroup(ctx context.Context, groupID string) (group *relation2.GroupModel, err error)
|
||||
FindJoinedGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error)
|
||||
UpdateGroup(ctx context.Context, groupID string, data map[string]any) error
|
||||
DismissGroup(ctx context.Context, groupID string) error // 解散群,并删除群成员
|
||||
// groupMember
|
||||
CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMember []*relation2.GroupMemberModel) error
|
||||
DeleteGroupByIDs(ctx context.Context, groupIDs []string) error
|
||||
TakeGroupByID(ctx context.Context, groupID string) (group *relation2.GroupModel, err error)
|
||||
TakeGroupMemberByID(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupModel, err error)
|
||||
GetJoinedGroupList(ctx context.Context, userID string) ([]*relation2.GroupModel, error)
|
||||
GetGroupMemberList(ctx context.Context, groupID string) ([]*relation2.GroupMemberModel, error)
|
||||
GetGroupMemberListByUserID(ctx context.Context, groupID string, userIDs []string) ([]*relation2.GroupMemberModel, error)
|
||||
GetGroupMemberFilterList(ctx context.Context, groupID string, filter int32, begin int32, maxNumber int32) ([]*relation2.GroupModel, error) // relation.GetGroupMemberByGroupID(req.GroupID, req.Filter, req.NextSeq, 30)
|
||||
FindGroupMembersByID(ctx context.Context, groupID string, userIDs []string) (groups []*relation2.GroupMemberModel, err error)
|
||||
DelGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
||||
GetGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error)
|
||||
GetGroupOwnerUserID(ctx context.Context, groupIDs []string) (map[string]string, error)
|
||||
GetGroupRecvApplicationList(ctx context.Context, userID string) ([]*relation2.GroupRequestModel, error)
|
||||
|
||||
TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupMemberModel, err error)
|
||||
FindGroupMember(ctx context.Context, groupID string, userIDs []string) ([]*relation2.GroupMemberModel, error)
|
||||
FindGroupMemberAll(ctx context.Context, groupID string) ([]*relation2.GroupMemberModel, error)
|
||||
FindGroupMemberFilterList(ctx context.Context, groupID string, filter int32, begin int32, maxNumber int32) ([]*relation2.GroupMemberModel, error) // relation.GetGroupMemberByGroupID(req.GroupID, req.Filter, req.NextSeq, 30)
|
||||
SearchGroupMember(ctx context.Context, groupID, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error)
|
||||
TakeGroupOwner(ctx context.Context, groupID string) (*relation2.GroupMemberModel, error)
|
||||
FindGroupOwnerUser(ctx context.Context, groupID []string) ([]*relation2.GroupMemberModel, error)
|
||||
CreateGroupMember(ctx context.Context, groupMember []*relation2.GroupMemberModel) error
|
||||
CreateGroupRequest(ctx context.Context, requests []*relation2.GroupRequestModel) error
|
||||
HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relation2.GroupMemberModel) error
|
||||
DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
||||
MapGroupHash(ctx context.Context, groupIDs []string) (map[string]uint64, error)
|
||||
MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error)
|
||||
MapGroupOwnerUserID(ctx context.Context, groupIDs []string) (map[string]string, error)
|
||||
TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string) error // 转让群
|
||||
UpdateGroupMember(ctx context.Context, groupID, userID string, data map[string]any) error
|
||||
|
||||
//mongo
|
||||
CreateGroupRequest(ctx context.Context, requests []*relation2.GroupRequestModel) error
|
||||
GetGroupRecvApplicationList(ctx context.Context, userID string) ([]*relation2.GroupRequestModel, error) // ?
|
||||
TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relation2.GroupRequestModel, error)
|
||||
FindUserGroupRequest(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupRequestModel, error)
|
||||
// superGroup
|
||||
TakeSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation2.SuperGroupModel, err error)
|
||||
CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error
|
||||
DelSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
||||
DeleteSuperGroup(ctx context.Context, groupID string) error
|
||||
DeleteSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
||||
AddUserToSuperGroup(ctx context.Context, groupID string, userIDs []string) error
|
||||
GetSuperGroupByID(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error)
|
||||
FindJoinSuperGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (total int32, groupIDs []string, err error)
|
||||
MapSuperGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error)
|
||||
}
|
||||
|
||||
var _ GroupInterface = (*GroupController)(nil)
|
||||
@@ -45,82 +62,112 @@ type GroupController struct {
|
||||
database GroupDataBaseInterface
|
||||
}
|
||||
|
||||
func (g *GroupController) TakeGroupMemberByID(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupModel, err error) {
|
||||
func (g *GroupController) FindGroup(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) FindGroupMembersByID(ctx context.Context, groupID string, userIDs []string) (groups []*relation2.GroupModel, err error) {
|
||||
func (g *GroupController) SearchGroup(ctx context.Context, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) DelGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
||||
func (g *GroupController) TakeGroup(ctx context.Context, groupID string) (group *relation2.GroupModel, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) GetGroupRecvApplicationList(ctx context.Context, userID string) ([]*relation2.GroupRequestModel, error) {
|
||||
/*
|
||||
var groupRequestList []db.GroupRequest
|
||||
memberList, err := GetGroupMemberListByUserID(userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range memberList {
|
||||
if v.RoleLevel > constant.GroupOrdinaryUsers {
|
||||
list, err := GetGroupRequestByGroupID(v.GroupID)
|
||||
if err != nil {
|
||||
// fmt.Println("111 GetGroupRequestByGroupID failed ", err.Error())
|
||||
continue
|
||||
}
|
||||
// fmt.Println("222 GetGroupRequestByGroupID ok ", list)
|
||||
groupRequestList = append(groupRequestList, list...)
|
||||
// fmt.Println("333 GetGroupRequestByGroupID ok ", groupRequestList)
|
||||
}
|
||||
}
|
||||
return groupRequestList, nil
|
||||
*/
|
||||
func (g *GroupController) FindJoinedGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) DelSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
||||
func (g *GroupController) UpdateGroup(ctx context.Context, groupID string, data map[string]any) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) GetJoinedGroupList(ctx context.Context, userID string) ([]*relation2.GroupModel, error) {
|
||||
func (g *GroupController) DismissGroup(ctx context.Context, groupID string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) GetGroupMemberList(ctx context.Context, groupID string) ([]*relation2.GroupModel, error) {
|
||||
func (g *GroupController) CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMember []*relation2.GroupMemberModel) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) GetGroupMemberListByUserID(ctx context.Context, groupID string, userIDs []string) ([]*relation2.GroupModel, error) {
|
||||
func (g *GroupController) TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupMemberModel, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) GetGroupMemberFilterList(ctx context.Context, groupID string, filter int32, begin int32, maxNumber int32) ([]*relation2.GroupModel, error) {
|
||||
func (g *GroupController) FindGroupMember(ctx context.Context, groupID string, userIDs []string) ([]*relation2.GroupMemberModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) GetGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error) {
|
||||
func (g *GroupController) FindGroupMemberAll(ctx context.Context, groupID string) ([]*relation2.GroupMemberModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) GetGroupOwnerUserID(ctx context.Context, groupIDs []string) (map[string]string, error) {
|
||||
func (g *GroupController) FindGroupMemberFilterList(ctx context.Context, groupID string, filter int32, begin int32, maxNumber int32) ([]*relation2.GroupMemberModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) CreateGroupMember(ctx context.Context, groupMember []*relation2.GroupModel) error {
|
||||
func (g *GroupController) SearchGroupMember(ctx context.Context, groupID, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) TakeGroupOwner(ctx context.Context, groupID string) (*relation2.GroupMemberModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) FindGroupOwnerUser(ctx context.Context, groupID []string) ([]*relation2.GroupMemberModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) CreateGroupMember(ctx context.Context, groupMember []*relation2.GroupMemberModel) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relation2.GroupMemberModel) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) MapGroupHash(ctx context.Context, groupIDs []string) (map[string]uint64, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) MapGroupOwnerUserID(ctx context.Context, groupIDs []string) (map[string]string, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) UpdateGroupMember(ctx context.Context, groupID, userID string, data map[string]any) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
@@ -130,49 +177,98 @@ func (g *GroupController) CreateGroupRequest(ctx context.Context, requests []*re
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) GetGroupRecvApplicationList(ctx context.Context, userID string) ([]*relation2.GroupRequestModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relation2.GroupRequestModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) FindUserGroupRequest(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupRequestModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) TakeSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation2.SuperGroupModel, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) DeleteSuperGroup(ctx context.Context, groupID string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) DeleteSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) AddUserToSuperGroup(ctx context.Context, groupID string, userIDs []string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func NewGroupController(db *gorm.DB, rdb redis.UniversalClient, mgoClient *mongo.Client) GroupInterface {
|
||||
groupController := &GroupController{database: newGroupDatabase(db, rdb, mgoClient)}
|
||||
return groupController
|
||||
func (g *GroupController) FindJoinSuperGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (total int32, groupIDs []string, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupController) FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error) {
|
||||
return g.database.FindGroupsByID(ctx, groupIDs)
|
||||
}
|
||||
|
||||
func (g *GroupController) CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMember []*relation2.GroupModel) error {
|
||||
return g.database.CreateGroup(ctx, groups, groupMember)
|
||||
}
|
||||
|
||||
func (g *GroupController) DeleteGroupByIDs(ctx context.Context, groupIDs []string) error {
|
||||
return g.database.DeleteGroupByIDs(ctx, groupIDs)
|
||||
}
|
||||
|
||||
func (g *GroupController) TakeGroupByID(ctx context.Context, groupID string) (group *relation2.GroupModel, err error) {
|
||||
return g.database.TakeGroupByID(ctx, groupID)
|
||||
}
|
||||
|
||||
func (g *GroupController) GetSuperGroupByID(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error) {
|
||||
return g.database.GetSuperGroupByID(ctx, groupID)
|
||||
}
|
||||
|
||||
func (g *GroupController) CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error {
|
||||
return g.database.CreateSuperGroup(ctx, groupID, initMemberIDList)
|
||||
func (g *GroupController) MapSuperGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
type GroupDataBaseInterface interface {
|
||||
FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error)
|
||||
CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMember []*relation2.GroupModel) error
|
||||
DeleteGroupByIDs(ctx context.Context, groupIDs []string) error
|
||||
TakeGroupByID(ctx context.Context, groupID string) (group *relation2.GroupModel, err error)
|
||||
GetSuperGroupByID(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error)
|
||||
// group
|
||||
FindGroup(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error)
|
||||
SearchGroup(ctx context.Context, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error)
|
||||
TakeGroup(ctx context.Context, groupID string) (group *relation2.GroupModel, err error)
|
||||
FindJoinedGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error)
|
||||
UpdateGroup(ctx context.Context, groupID string, data map[string]any) error
|
||||
DismissGroup(ctx context.Context, groupID string) error // 解散群,并删除群成员
|
||||
// groupMember
|
||||
CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMember []*relation2.GroupMemberModel) error
|
||||
TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupMemberModel, err error)
|
||||
FindGroupMember(ctx context.Context, groupID string, userIDs []string) ([]*relation2.GroupMemberModel, error)
|
||||
FindGroupMemberAll(ctx context.Context, groupID string) ([]*relation2.GroupMemberModel, error)
|
||||
FindGroupMemberFilterList(ctx context.Context, groupID string, filter int32, begin int32, maxNumber int32) ([]*relation2.GroupMemberModel, error) // relation.GetGroupMemberByGroupID(req.GroupID, req.Filter, req.NextSeq, 30)
|
||||
SearchGroupMember(ctx context.Context, groupID, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error)
|
||||
TakeGroupOwner(ctx context.Context, groupID string) (*relation2.GroupMemberModel, error)
|
||||
FindGroupOwnerUser(ctx context.Context, groupID []string) ([]*relation2.GroupMemberModel, error)
|
||||
CreateGroupMember(ctx context.Context, groupMember []*relation2.GroupMemberModel) error
|
||||
HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relation2.GroupMemberModel) error
|
||||
DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
||||
MapGroupHash(ctx context.Context, groupIDs []string) (map[string]uint64, error)
|
||||
MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error)
|
||||
MapGroupOwnerUserID(ctx context.Context, groupIDs []string) (map[string]string, error)
|
||||
TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string) error // 转让群
|
||||
UpdateGroupMember(ctx context.Context, groupID, userID string, data map[string]any) error
|
||||
|
||||
CreateGroupRequest(ctx context.Context, requests []*relation2.GroupRequestModel) error
|
||||
GetGroupRecvApplicationList(ctx context.Context, userID string) ([]*relation2.GroupRequestModel, error) // ?
|
||||
TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relation2.GroupRequestModel, error)
|
||||
FindUserGroupRequest(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupRequestModel, error)
|
||||
// superGroup
|
||||
TakeSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation2.SuperGroupModel, err error)
|
||||
CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error
|
||||
DeleteSuperGroup(ctx context.Context, groupID string) error
|
||||
DeleteSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
||||
AddUserToSuperGroup(ctx context.Context, groupID string, userIDs []string) error
|
||||
FindJoinSuperGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (total int32, groupIDs []string, err error)
|
||||
MapSuperGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error)
|
||||
}
|
||||
|
||||
var _ *GroupDataBase = (GroupDataBaseInterface)(nil)
|
||||
|
||||
type GroupDataBase struct {
|
||||
groupDB *relation.GroupGorm
|
||||
groupMemberDB *relation.GroupMemberGorm
|
||||
@@ -205,82 +301,270 @@ func newGroupDatabase(db *gorm.DB, rdb redis.UniversalClient, mgoClient *mongo.C
|
||||
return database
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error) {
|
||||
return g.cache.GetGroupsInfo(ctx, groupIDs)
|
||||
//func (g *GroupDataBase) FindGroupsByID(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error) {
|
||||
// return g.cache.GetGroupsInfo(ctx, groupIDs)
|
||||
//}
|
||||
//
|
||||
//func (g *GroupDataBase) CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMembers []*relation2.GroupMemberModel) error {
|
||||
// return g.db.Transaction(func(tx *gorm.DB) error {
|
||||
// if len(groups) > 0 {
|
||||
// if err := g.groupDB.Create(ctx, groups, tx); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
// if len(groupMembers) > 0 {
|
||||
// if err := g.groupMemberDB.Create(ctx, groupMembers, tx); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
// return nil
|
||||
// })
|
||||
//}
|
||||
//
|
||||
//func (g *GroupDataBase) DeleteGroupByIDs(ctx context.Context, groupIDs []string) error {
|
||||
// return g.groupDB.DB.Transaction(func(tx *gorm.DB) error {
|
||||
// if err := g.groupDB.Delete(ctx, groupIDs, tx); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// if err := g.cache.DelGroupsInfo(ctx, groupIDs); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// return nil
|
||||
// })
|
||||
//}
|
||||
//
|
||||
//func (g *GroupDataBase) TakeGroupByID(ctx context.Context, groupID string) (group *relation2.GroupModel, err error) {
|
||||
// return g.cache.GetGroupInfo(ctx, groupID)
|
||||
//}
|
||||
//
|
||||
//func (g *GroupDataBase) Update(ctx context.Context, groups []*relation2.GroupModel) error {
|
||||
// return g.db.Transaction(func(tx *gorm.DB) error {
|
||||
// if err := g.groupDB.Update(ctx, groups, tx); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// var groupIDs []string
|
||||
// for _, group := range groups {
|
||||
// groupIDs = append(groupIDs, group.GroupID)
|
||||
// }
|
||||
// if err := g.cache.DelGroupsInfo(ctx, groupIDs); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// return nil
|
||||
// })
|
||||
//}
|
||||
//
|
||||
//func (g *GroupDataBase) GetJoinedGroupList(ctx context.Context, userID string) ([]*relation2.GroupModel, error) {
|
||||
//
|
||||
// return nil, nil
|
||||
//}
|
||||
//
|
||||
//func (g *GroupDataBase) CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error {
|
||||
// sess, err := g.mongoDB.MgoClient.StartSession()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// defer sess.EndSession(ctx)
|
||||
// sCtx := mongo.NewSessionContext(ctx, sess)
|
||||
// if err = g.mongoDB.CreateSuperGroup(sCtx, groupID, initMemberIDList); err != nil {
|
||||
// _ = sess.AbortTransaction(ctx)
|
||||
// return err
|
||||
// }
|
||||
//
|
||||
// if err = g.cache.BatchDelJoinedSuperGroupIDs(ctx, initMemberIDList); err != nil {
|
||||
// _ = sess.AbortTransaction(ctx)
|
||||
// return err
|
||||
// }
|
||||
// return sess.CommitTransaction(ctx)
|
||||
//}
|
||||
//
|
||||
//func (g *GroupDataBase) GetSuperGroupByID(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error) {
|
||||
// return g.mongoDB.GetSuperGroup(ctx, groupID)
|
||||
//}
|
||||
|
||||
func (g *GroupDataBase) FindGroup(ctx context.Context, groupIDs []string) (groups []*relation2.GroupModel, err error) {
|
||||
return g.groupDB.Find(ctx, groupIDs)
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) SearchGroup(ctx context.Context, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error) {
|
||||
return g.groupDB.Search(ctx, name, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) TakeGroup(ctx context.Context, groupID string) (group *relation2.GroupModel, err error) {
|
||||
return g.groupDB.Take(ctx, groupID)
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) FindJoinedGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupModel, error) {
|
||||
total, members, err := g.groupMemberDB.PageByUser(ctx, userID, pageNumber, showNumber)
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
if len(members) == 0 {
|
||||
return total, []*relation2.GroupModel{}, nil
|
||||
}
|
||||
groupIDs := utils.Slice(members, func(e *relation2.GroupMemberModel) string {
|
||||
return e.GroupID
|
||||
})
|
||||
groups, err := g.groupDB.Find(ctx, groupIDs)
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
utils.OrderPtr(groupIDs, &groups, func(e *relation2.GroupModel) string {
|
||||
return e.GroupID
|
||||
})
|
||||
return total, groups, nil
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) UpdateGroup(ctx context.Context, groupID string, data map[string]any) error {
|
||||
return g.groupDB.UpdateMap(ctx, groupID, data)
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) DismissGroup(ctx context.Context, groupID string) error {
|
||||
return utils.Wrap(g.db.Transaction(func(tx *gorm.DB) error {
|
||||
if err := g.groupDB.UpdateStatus(ctx, groupID, constant.GroupStatusDismissed, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return g.groupMemberDB.DeleteGroup(ctx, []string{groupID}, tx)
|
||||
}), "")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) CreateGroup(ctx context.Context, groups []*relation2.GroupModel, groupMembers []*relation2.GroupMemberModel) error {
|
||||
return g.db.Transaction(func(tx *gorm.DB) error {
|
||||
if len(groups) > 0 {
|
||||
if len(groups) > 0 && len(groupMembers) > 0 {
|
||||
return g.db.Transaction(func(tx *gorm.DB) error {
|
||||
if err := g.groupDB.Create(ctx, groups, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(groupMembers) > 0 {
|
||||
if err := g.groupMemberDB.Create(ctx, groupMembers, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return g.groupMemberDB.Create(ctx, groupMembers, tx)
|
||||
})
|
||||
}
|
||||
if len(groups) > 0 {
|
||||
return g.groupDB.Create(ctx, groups)
|
||||
}
|
||||
if len(groupMembers) > 0 {
|
||||
return g.groupMemberDB.Create(ctx, groupMembers)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) DeleteGroupByIDs(ctx context.Context, groupIDs []string) error {
|
||||
return g.groupDB.DB.Transaction(func(tx *gorm.DB) error {
|
||||
if err := g.groupDB.Delete(ctx, groupIDs, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := g.cache.DelGroupsInfo(ctx, groupIDs); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
func (g *GroupDataBase) TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relation2.GroupMemberModel, err error) {
|
||||
return g.groupMemberDB.Take(ctx, groupID, userID)
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) TakeGroupByID(ctx context.Context, groupID string) (group *relation2.GroupModel, err error) {
|
||||
return g.cache.GetGroupInfo(ctx, groupID)
|
||||
func (g *GroupDataBase) FindGroupMember(ctx context.Context, groupID string, userIDs []string) ([]*relation2.GroupMemberModel, error) {
|
||||
return g.groupMemberDB.FindGroupUser(ctx, []string{groupID}, userIDs, nil)
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) Update(ctx context.Context, groups []*relation2.GroupModel) error {
|
||||
return g.db.Transaction(func(tx *gorm.DB) error {
|
||||
if err := g.groupDB.Update(ctx, groups, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
var groupIDs []string
|
||||
for _, group := range groups {
|
||||
groupIDs = append(groupIDs, group.GroupID)
|
||||
}
|
||||
if err := g.cache.DelGroupsInfo(ctx, groupIDs); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
func (g *GroupDataBase) FindGroupMemberAll(ctx context.Context, groupID string) ([]*relation2.GroupMemberModel, error) {
|
||||
return g.groupMemberDB.FindGroupUser(ctx, []string{groupID}, nil, nil)
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) GetJoinedGroupList(ctx context.Context, userID string) ([]*relation2.GroupModel, error) {
|
||||
func (g *GroupDataBase) FindGroupMemberFilterList(ctx context.Context, groupID string, filter int32, begin int32, maxNumber int32) ([]*relation2.GroupMemberModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
func (g *GroupDataBase) SearchGroupMember(ctx context.Context, groupID string, name string, pageNumber, showNumber int32) (int32, []*relation2.GroupMemberModel, error) {
|
||||
return g.groupMemberDB.SearchMember(ctx, groupID, name, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) TakeGroupOwner(ctx context.Context, groupID string) (*relation2.GroupMemberModel, error) {
|
||||
return g.groupMemberDB.TakeOwner(ctx, groupID)
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) FindGroupOwnerUser(ctx context.Context, groupIDs []string) ([]*relation2.GroupMemberModel, error) {
|
||||
return g.groupMemberDB.FindGroupUser(ctx, groupIDs, nil, []int32{constant.GroupOwner})
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) CreateGroupMember(ctx context.Context, groupMember []*relation2.GroupMemberModel) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relation2.GroupMemberModel) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) MapGroupHash(ctx context.Context, groupIDs []string) (map[string]uint64, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]int, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) MapGroupOwnerUserID(ctx context.Context, groupIDs []string) (map[string]string, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) UpdateGroupMember(ctx context.Context, groupID, userID string, data map[string]any) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) CreateGroupRequest(ctx context.Context, requests []*relation2.GroupRequestModel) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) GetGroupRecvApplicationList(ctx context.Context, userID string) ([]*relation2.GroupRequestModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relation2.GroupRequestModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) FindUserGroupRequest(ctx context.Context, userID string, pageNumber, showNumber int32) (int32, []*relation2.GroupRequestModel, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) TakeSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation2.SuperGroupModel, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error {
|
||||
sess, err := g.mongoDB.MgoClient.StartSession()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer sess.EndSession(ctx)
|
||||
sCtx := mongo.NewSessionContext(ctx, sess)
|
||||
if err = g.mongoDB.CreateSuperGroup(sCtx, groupID, initMemberIDList); err != nil {
|
||||
_ = sess.AbortTransaction(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
if err = g.cache.BatchDelJoinedSuperGroupIDs(ctx, initMemberIDList); err != nil {
|
||||
_ = sess.AbortTransaction(ctx)
|
||||
return err
|
||||
}
|
||||
return sess.CommitTransaction(ctx)
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) GetSuperGroupByID(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error) {
|
||||
return g.mongoDB.GetSuperGroup(ctx, groupID)
|
||||
func (g *GroupDataBase) DeleteSuperGroup(ctx context.Context, groupID string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) DeleteSuperGroupMember(ctx context.Context, groupID string, userIDs []string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) AddUserToSuperGroup(ctx context.Context, groupID string, userIDs []string) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) FindJoinSuperGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (total int32, groupIDs []string, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) MapSuperGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
@@ -1,15 +1,35 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/table/relation"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ConversationGorm struct {
|
||||
DB *gorm.DB
|
||||
var ConversationDB *gorm.DB
|
||||
|
||||
//type Conversation 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 (Conversation) TableName() string {
|
||||
return "conversations"
|
||||
}
|
||||
|
||||
func SetConversation(conversation relation.ConversationModel) (bool, error) {
|
||||
func SetConversation(conversation Conversation) (bool, error) {
|
||||
var isUpdate bool
|
||||
newConversation := conversation
|
||||
if ConversationDB.Model(&Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
||||
@@ -73,7 +93,7 @@ func GetExistConversationUserIDList(ownerUserIDList []string, conversationID str
|
||||
return resultArr, nil
|
||||
}
|
||||
|
||||
func GetConversation(OwnerUserID, conversationID string) (relation.ConversationModel, error) {
|
||||
func GetConversation(OwnerUserID, conversationID string) (Conversation, error) {
|
||||
var conversation Conversation
|
||||
err := ConversationDB.Table("conversations").Where("owner_user_id=? and conversation_id=?", OwnerUserID, conversationID).Take(&conversation).Error
|
||||
return conversation, err
|
||||
@@ -96,7 +116,7 @@ func UpdateColumnsConversations(ownerUserIDList []string, conversationID string,
|
||||
|
||||
}
|
||||
|
||||
func GetConversationIDsByUserID(userID string) ([]string, error) {
|
||||
func GetConversationIDListByUserID(userID string) ([]string, error) {
|
||||
var IDList []string
|
||||
err := ConversationDB.Model(&Conversation{}).Where("owner_user_id=?", userID).Pluck("conversation_id", &IDList).Error
|
||||
return IDList, err
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/table"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Conversation interface {
|
||||
TableName() string
|
||||
Create(ctx context.Context, conversations []*table.ConversationModel) (err error)
|
||||
Delete(ctx context.Context, groupIDs []string) (err error)
|
||||
UpdateByMap(ctx context.Context, groupID string, args map[string]interface{}) (err error)
|
||||
Update(ctx context.Context, groups []*table.ConversationModel) (err error)
|
||||
Find(ctx context.Context, groupIDs []string) (groups []*table.ConversationModel, err error)
|
||||
Take(ctx context.Context, groupID string) (group *table.ConversationModel, err error)
|
||||
}
|
||||
type ConversationGorm struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func (c *ConversationGorm) TableName() string {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func NewConversationGorm(DB *gorm.DB) Conversation {
|
||||
return &ConversationGorm{DB: DB}
|
||||
}
|
||||
|
||||
func (c *ConversationGorm) Create(ctx context.Context, conversations []*table.ConversationModel) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "conversations", conversations)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Create(&conversations).Error, "")
|
||||
}
|
||||
|
||||
func (c *ConversationGorm) Delete(ctx context.Context, groupIDs []string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupIDs", groupIDs)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Where("group_id in (?)", groupIDs).Delete(&table.ConversationModel{}).Error, "")
|
||||
}
|
||||
|
||||
func (c *ConversationGorm) UpdateByMap(ctx context.Context, groupID string, args map[string]interface{}) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Where("group_id = ?", groupID).Model(g).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (c *ConversationGorm) Update(ctx context.Context, groups []*table.ConversationModel) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groups", groups)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Updates(&groups).Error, "")
|
||||
}
|
||||
|
||||
func (c *ConversationGorm) Find(ctx context.Context, groupIDs []string) (groups []*table.ConversationModel, 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 (c *ConversationGorm) Take(ctx context.Context, groupID string) (group *table.ConversationModel, err error) {
|
||||
group = &Group{}
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "group", *group)
|
||||
}()
|
||||
return group, utils.Wrap(getDBConn(g.DB, tx).Where("group_id = ?", groupID).Take(group).Error, "")
|
||||
}
|
||||
@@ -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,7 +30,7 @@ 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)
|
||||
}()
|
||||
@@ -52,7 +52,7 @@ func (f *FriendGorm) UpdateByMap(ctx context.Context, ownerUserID string, args m
|
||||
return utils.Wrap(f.DB.Model(&table.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)
|
||||
}()
|
||||
@@ -66,27 +66,27 @@ func (f *FriendGorm) UpdateRemark(ctx context.Context, ownerUserID, friendUserID
|
||||
return utils.Wrap(f.DB.Model(&table.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, "")
|
||||
}
|
||||
|
||||
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, "")
|
||||
}
|
||||
|
||||
func (f *FriendGorm) Take(ctx context.Context, ownerUserID, friendUserID string) (friend *table.FriendModel, err error) {
|
||||
func (f *FriendGorm) Take(ctx context.Context, ownerUserID, friendUserID string) (friend *relation.FriendModel, err error) {
|
||||
friend = &table.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, "")
|
||||
}
|
||||
|
||||
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)
|
||||
}()
|
||||
@@ -94,7 +94,7 @@ func (f *FriendGorm) FindUserState(ctx context.Context, userID1, userID2 string)
|
||||
}
|
||||
|
||||
// 获取 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,14 +102,14 @@ 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)
|
||||
}()
|
||||
return friends, utils.Wrap(getDBConn(f.DB, tx).Where("friend_user_id = ? AND owner_user_id in (?)", friendUserID, ownerUserIDs).Find(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendGorm) FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32, tx ...*gorm.DB) (friends []*table.FriendModel, total int64, err error) {
|
||||
func (f *FriendGorm) FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32, tx ...*gorm.DB) (friends []*relation.FriendModel, total int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "pageNumber", pageNumber, "showNumber", showNumber, "friends", friends, "total", total)
|
||||
}()
|
||||
@@ -121,7 +121,7 @@ func (f *FriendGorm) FindOwnerFriends(ctx context.Context, ownerUserID string, p
|
||||
return
|
||||
}
|
||||
|
||||
func (f *FriendGorm) FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32, tx ...*gorm.DB) (friends []*table.FriendModel, total int64, err error) {
|
||||
func (f *FriendGorm) FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32, tx ...*gorm.DB) (friends []*relation.FriendModel, total int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friendUserID", friendUserID, "pageNumber", pageNumber, "showNumber", showNumber, "friends", friends, "total", total)
|
||||
}()
|
||||
|
||||
@@ -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,69 +20,68 @@ 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, tx ...*gorm.DB) (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) {
|
||||
func (f *FriendRequestGorm) UpdateByMap(ctx context.Context, formUserID string, toUserID string, args map[string]interface{}, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "args", args)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "formUserID", formUserID, "toUserID", toUserID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(f.DB.Model(&table.FriendRequestModel{}).Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
|
||||
return utils.Wrap(getDBConn(f.DB, tx).Model(&relation.FriendRequestModel{}).Where("from_user_id = ? AND to_user_id ", formUserID, toUserID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) Update(ctx context.Context, friendRequests []*table.FriendRequestModel, tx ...*gorm.DB) (err error) {
|
||||
func (f *FriendRequestGorm) Update(ctx context.Context, friendRequests []*relation.FriendRequestModel, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friendRequests", friendRequests)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(f.DB, tx).Model(&table.FriendRequestModel{}).Updates(&friendRequests).Error, "")
|
||||
return utils.Wrap(getDBConn(f.DB, tx).Model(&relation.FriendRequestModel{}).Updates(&friendRequests).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) Find(ctx context.Context, ownerUserID string) (friends []*table.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, "")
|
||||
}
|
||||
|
||||
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, pageNumber, showNumber int32, tx ...*gorm.DB) (friends []*table.FriendRequestModel, total int64, err error) {
|
||||
func (f *FriendRequestGorm) Find(ctx context.Context, fromUserID, toUserID string, tx ...*gorm.DB) (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(getDBConn(f.DB, tx).Model(&relation.FriendRequestModel{}).Where("from_user_id = ? and to_user_id", fromUserID, toUserID).Find(friend).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) FindToUserID(ctx context.Context, toUserID string, pageNumber, showNumber int32, tx ...*gorm.DB) (friends []*relation.FriendRequestModel, total int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "toUserID", toUserID, "friends", friends)
|
||||
}()
|
||||
|
||||
err = getDBConn(f.DB, tx).Model(&table.FriendRequestModel{}).Where("to_user_id = ? ", toUserID).Count(&total).Error
|
||||
err = getDBConn(f.DB, tx).Model(&relation.FriendRequestModel{}).Where("to_user_id = ? ", toUserID).Count(&total).Error
|
||||
if err != nil {
|
||||
return nil, 0, utils.Wrap(err, "")
|
||||
}
|
||||
err = utils.Wrap(getDBConn(f.DB, tx).Model(&table.FriendRequestModel{}).Where("to_user_id = ? ", toUserID).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&friends).Error, "")
|
||||
err = utils.Wrap(getDBConn(f.DB, tx).Model(&relation.FriendRequestModel{}).Where("to_user_id = ? ", toUserID).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&friends).Error, "")
|
||||
return
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) FindFromUserID(ctx context.Context, fromUserID string, pageNumber, showNumber int32, tx ...*gorm.DB) (friends []*table.FriendRequestModel, total int64, err error) {
|
||||
func (f *FriendRequestGorm) FindFromUserID(ctx context.Context, fromUserID string, pageNumber, showNumber int32, tx ...*gorm.DB) (friends []*relation.FriendRequestModel, total int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "fromUserID", fromUserID, "friends", friends)
|
||||
}()
|
||||
|
||||
err = getDBConn(f.DB, tx).Model(&table.FriendRequestModel{}).Where("from_user_id = ? ", fromUserID).Count(&total).Error
|
||||
err = getDBConn(f.DB, tx).Model(&relation.FriendRequestModel{}).Where("from_user_id = ? ", fromUserID).Count(&total).Error
|
||||
if err != nil {
|
||||
return nil, 0, utils.Wrap(err, "")
|
||||
}
|
||||
err = utils.Wrap(getDBConn(f.DB, tx).Model(&table.FriendRequestModel{}).Where("from_user_id = ? ", fromUserID).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&friends).Error, "")
|
||||
err = utils.Wrap(getDBConn(f.DB, tx).Model(&relation.FriendRequestModel{}).Where("from_user_id = ? ", fromUserID).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&friends).Error, "")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ package relation
|
||||
//
|
||||
//}
|
||||
//
|
||||
//func GetGroupMemberListByUserID(userID string) ([]GroupMember, error) {
|
||||
//func FindGroupMember(userID string) ([]GroupMember, error) {
|
||||
// var groupMemberList []GroupMember
|
||||
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("user_id=?", userID).Find(&groupMemberList).Error
|
||||
// if err != nil {
|
||||
@@ -167,7 +167,7 @@ package relation
|
||||
//}
|
||||
//
|
||||
//func GetJoinedGroupIDListByUserID(userID string) ([]string, error) {
|
||||
// memberList, err := GetGroupMemberListByUserID(userID)
|
||||
// memberList, err := FindGroupMember(userID)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
@@ -31,6 +31,13 @@ func (g *GroupMemberGorm) Delete(ctx context.Context, groupMembers []*relation.G
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Delete(groupMembers).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMemberGorm) DeleteGroup(ctx context.Context, groupIDs []string, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupIDs", groupIDs)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Where("group_id in (?)", groupIDs).Delete(&relation.GroupMemberModel{}).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMemberGorm) UpdateByMap(ctx context.Context, groupID string, userID string, args map[string]interface{}, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID, "args", args)
|
||||
@@ -54,6 +61,23 @@ func (g *GroupMemberGorm) Find(ctx context.Context, groupMembers []*relation.Gro
|
||||
return groupList, utils.Wrap(getDBConn(g.DB, tx).Where("(group_id, user_id) in ?", where).Find(&groupList).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMemberGorm) FindGroupUser(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32, tx ...*gorm.DB) (groupList []*relation.GroupMemberModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupIDs", groupIDs, "userIDs", userIDs, "groupList", groupList)
|
||||
}()
|
||||
db := getDBConn(g.DB, tx)
|
||||
if len(groupList) > 0 {
|
||||
db = db.Where("group_id in (?)", groupIDs)
|
||||
}
|
||||
if len(userIDs) > 0 {
|
||||
db = db.Where("user_id in (?)", userIDs)
|
||||
}
|
||||
if len(roleLevels) > 0 {
|
||||
db = db.Where("role_level in (?)", roleLevels)
|
||||
}
|
||||
return groupList, utils.Wrap(db.Find(&groupList).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMemberGorm) Take(ctx context.Context, groupID string, userID string, tx ...*gorm.DB) (groupMember *relation.GroupMemberModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID, "groupMember", *groupMember)
|
||||
@@ -62,7 +86,7 @@ func (g *GroupMemberGorm) Take(ctx context.Context, groupID string, userID strin
|
||||
return groupMember, utils.Wrap(getDBConn(g.DB, tx).Where("group_id = ? and user_id = ?", groupID, userID).Take(groupMember).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupMemberGorm) TakeOwnerInfo(ctx context.Context, groupID string, tx ...*gorm.DB) (groupMember *relation.GroupMemberModel, err error) {
|
||||
func (g *GroupMemberGorm) TakeOwner(ctx context.Context, groupID string, tx ...*gorm.DB) (groupMember *relation.GroupMemberModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "groupMember", *groupMember)
|
||||
}()
|
||||
@@ -70,214 +94,16 @@ func (g *GroupMemberGorm) TakeOwnerInfo(ctx context.Context, groupID string, tx
|
||||
return groupMember, utils.Wrap(getDBConn(g.DB, tx).Where("group_id = ? and role_level = ?", groupID, constant.GroupOwner).Take(groupMember).Error, "")
|
||||
}
|
||||
|
||||
//func InsertIntoGroupMember(toInsertInfo GroupMemberModel) error {
|
||||
// toInsertInfo.JoinTime = time.Now()
|
||||
// if toInsertInfo.RoleLevel == 0 {
|
||||
// toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
|
||||
// }
|
||||
// toInsertInfo.MuteEndTime = time.Unix(int64(time.Now().Second()), 0)
|
||||
// err := GroupMemberDB.Table("group_members").Create(toInsertInfo).Error
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// return nil
|
||||
//}
|
||||
//
|
||||
//func BatchInsertIntoGroupMember(toInsertInfoList []*GroupMemberModel) error {
|
||||
// for _, toInsertInfo := range toInsertInfoList {
|
||||
// toInsertInfo.JoinTime = time.Now()
|
||||
// if toInsertInfo.RoleLevel == 0 {
|
||||
// toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
|
||||
// }
|
||||
// toInsertInfo.MuteEndTime = time.Unix(int64(time.Now().Second()), 0)
|
||||
// }
|
||||
// return GroupMemberDB.Create(toInsertInfoList).Error
|
||||
//
|
||||
//}
|
||||
//
|
||||
//func GetGroupMemberListByUserID(userID string) ([]GroupMemberModel, error) {
|
||||
// var groupMemberList []GroupMemberModel
|
||||
// err := GroupMemberDB.Table("group_members").Where("user_id=?", userID).Find(&groupMemberList).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return groupMemberList, nil
|
||||
//}
|
||||
//
|
||||
//func GetGroupMemberListByGroupID(groupID string) ([]GroupMemberModel, error) {
|
||||
// var groupMemberList []GroupMemberModel
|
||||
// err := GroupMemberDB.Table("group_members").Where("group_id=?", groupID).Find(&groupMemberList).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return groupMemberList, nil
|
||||
//}
|
||||
//
|
||||
//func GetGroupMemberIDListByGroupID(groupID string) ([]string, error) {
|
||||
// var groupMemberIDList []string
|
||||
// err := GroupMemberDB.Table("group_members").Where("group_id=?", groupID).Pluck("user_id", &groupMemberIDList).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return groupMemberIDList, nil
|
||||
//}
|
||||
//
|
||||
//func GetGroupMemberListByGroupIDAndRoleLevel(groupID string, roleLevel int32) ([]GroupMemberModel, error) {
|
||||
// var groupMemberList []GroupMemberModel
|
||||
// err := GroupMemberDB.Table("group_members").Where("group_id=? and role_level=?", groupID, roleLevel).Find(&groupMemberList).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return groupMemberList, nil
|
||||
//}
|
||||
//
|
||||
//func GetGroupMemberInfoByGroupIDAndUserID(groupID, userID string) (*GroupMemberModel, error) {
|
||||
// var groupMember GroupMemberModel
|
||||
// err := GroupMemberDB.Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Limit(1).Take(&groupMember).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return &groupMember, nil
|
||||
//}
|
||||
//
|
||||
//func DeleteGroupMemberByGroupIDAndUserID(groupID, userID string) error {
|
||||
// return GroupMemberDB.Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Delete(GroupMemberModel{}).Error
|
||||
//}
|
||||
//
|
||||
//func DeleteGroupMemberByGroupID(groupID string) error {
|
||||
// return GroupMemberDB.Table("group_members").Where("group_id=? ", groupID).Delete(GroupMemberModel{}).Error
|
||||
//}
|
||||
//
|
||||
//func UpdateGroupMemberInfo(groupMemberInfo GroupMemberModel) error {
|
||||
// return GroupMemberDB.Table("group_members").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Updates(&groupMemberInfo).Error
|
||||
//}
|
||||
//
|
||||
//func UpdateGroupMemberInfoByMap(groupMemberInfo GroupMemberModel, m map[string]interface{}) error {
|
||||
// return GroupMemberDB.Table("group_members").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Updates(m).Error
|
||||
//}
|
||||
//
|
||||
//func GetOwnerManagerByGroupID(groupID string) ([]GroupMemberModel, error) {
|
||||
// var groupMemberList []GroupMemberModel
|
||||
// err := GroupMemberDB.Table("group_members").Where("group_id=? and role_level>?", groupID, constant.GroupOrdinaryUsers).Find(&groupMemberList).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return groupMemberList, nil
|
||||
//}
|
||||
//
|
||||
//func GetGroupMemberNumByGroupID(groupID string) (int64, error) {
|
||||
// var number int64
|
||||
// err := GroupMemberDB.Table("group_members").Where("group_id=?", groupID).Count(&number).Error
|
||||
// if err != nil {
|
||||
// return 0, utils.Wrap(err, "")
|
||||
// }
|
||||
// return number, nil
|
||||
//}
|
||||
//
|
||||
//func GetGroupOwnerInfoByGroupID(groupID string) (*GroupMemberModel, error) {
|
||||
// omList, err := GetOwnerManagerByGroupID(groupID)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// for _, v := range omList {
|
||||
// if v.RoleLevel == constant.GroupOwner {
|
||||
// return &v, nil
|
||||
// }
|
||||
// }
|
||||
// return nil, utils.Wrap(constant.ErrGroupNoOwner, "")
|
||||
//}
|
||||
//
|
||||
//func IsExistGroupMember(groupID, userID string) bool {
|
||||
// var number int64
|
||||
// err := GroupMemberDB.Table("group_members").Where("group_id = ? and user_id = ?", groupID, userID).Count(&number).Error
|
||||
// if err != nil {
|
||||
// return false
|
||||
// }
|
||||
// if number != 1 {
|
||||
// return false
|
||||
// }
|
||||
// return true
|
||||
//}
|
||||
//
|
||||
//func CheckIsExistGroupMember(ctx context.Context, groupID, userID string) error {
|
||||
// var number int64
|
||||
// err := GroupMemberDB.Table("group_members").Where("group_id = ? and user_id = ?", groupID, userID).Count(&number).Error
|
||||
// if err != nil {
|
||||
// return constant.ErrDB.Wrap()
|
||||
// }
|
||||
// if number != 1 {
|
||||
// return constant.ErrData.Wrap()
|
||||
// }
|
||||
// return nil
|
||||
//}
|
||||
//
|
||||
//func GetGroupMemberByGroupID(groupID string, filter int32, begin int32, maxNumber int32) ([]GroupMember, error) {
|
||||
// var memberList []GroupMember
|
||||
// var err error
|
||||
// if filter >= 0 {
|
||||
// memberList, err = GetGroupMemberListByGroupIDAndRoleLevel(groupID, filter) //sorted by join time
|
||||
// } else {
|
||||
// memberList, err = GetGroupMemberListByGroupID(groupID)
|
||||
// }
|
||||
//
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// if begin >= int32(len(memberList)) {
|
||||
// return nil, nil
|
||||
// }
|
||||
//
|
||||
// var end int32
|
||||
// if begin+int32(maxNumber) < int32(len(memberList)) {
|
||||
// end = begin + maxNumber
|
||||
// } else {
|
||||
// end = int32(len(memberList))
|
||||
// }
|
||||
// return memberList[begin:end], nil
|
||||
//}
|
||||
//
|
||||
//func GetJoinedGroupIDListByUserID(userID string) ([]string, error) {
|
||||
// memberList, err := GetGroupMemberListByUserID(userID)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// var groupIDList []string
|
||||
// for _, v := range memberList {
|
||||
// groupIDList = append(groupIDList, v.GroupID)
|
||||
// }
|
||||
// return groupIDList, nil
|
||||
//}
|
||||
//
|
||||
//func IsGroupOwnerAdmin(groupID, UserID string) bool {
|
||||
// groupMemberList, err := GetOwnerManagerByGroupID(groupID)
|
||||
// if err != nil {
|
||||
// return false
|
||||
// }
|
||||
// for _, v := range groupMemberList {
|
||||
// if v.UserID == UserID && v.RoleLevel > constant.GroupOrdinaryUsers {
|
||||
// return true
|
||||
// }
|
||||
// }
|
||||
// return false
|
||||
//}
|
||||
//
|
||||
//func GetGroupMembersByGroupIdCMS(groupId string, userName string, showNumber, pageNumber int32) ([]GroupMember, error) {
|
||||
// var groupMembers []GroupMember
|
||||
// err := GroupMemberDB.Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groupMembers).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return groupMembers, nil
|
||||
//}
|
||||
//
|
||||
//func GetGroupMembersCount(groupID, userName string) (int64, error) {
|
||||
// var count int64
|
||||
// if err := GroupMemberDB.Table("group_members").Where("group_id=?", groupID).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Count(&count).Error; err != nil {
|
||||
// return count, err
|
||||
// }
|
||||
// return count, nil
|
||||
//}
|
||||
//
|
||||
//func UpdateGroupMemberInfoDefaultZero(groupMemberInfo GroupMember, args map[string]interface{}) error {
|
||||
// return GroupMemberDB.Model(groupMemberInfo).Updates(args).Error
|
||||
//}
|
||||
func (g *GroupMemberGorm) PageByUser(ctx context.Context, userID string, pageNumber, showNumber int32, tx ...*gorm.DB) (total int32, groupList []*relation.GroupMemberModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "total", total, "groupList", groupList)
|
||||
}()
|
||||
return gormPage[relation.GroupMemberModel](getDBConn(g.DB, tx).Where("user_id = ?", userID), pageNumber, showNumber)
|
||||
}
|
||||
|
||||
func (g *GroupMemberGorm) SearchMember(ctx context.Context, groupID string, name string, pageNumber, showNumber int32, tx ...*gorm.DB) (total int32, groupList []*relation.GroupMemberModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "name", name, "pageNumber", pageNumber, "showNumber", showNumber, "total", total, "groupList", groupList)
|
||||
}()
|
||||
return gormSearch[relation.GroupMemberModel](getDBConn(g.DB, tx).Where("group_id = ?", groupID), "nickname", name, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
@@ -30,20 +30,27 @@ func (g *GroupGorm) Delete(ctx context.Context, groupIDs []string, tx ...*gorm.D
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Where("group_id in (?)", groupIDs).Delete(&relation.GroupModel{}).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupGorm) UpdateByMap(ctx context.Context, groupID string, args map[string]interface{}, tx ...*gorm.DB) (err error) {
|
||||
func (g *GroupGorm) UpdateMap(ctx context.Context, groupID string, args map[string]interface{}, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Where("group_id = ?", groupID).Model(g).Updates(args).Error, "")
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Where("group_id = ?", groupID).Model(&relation.GroupModel{}).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupGorm) Update(ctx context.Context, groups []*relation.GroupModel, tx ...*gorm.DB) (err error) {
|
||||
func (g *GroupGorm) UpdateStatus(ctx context.Context, groupID string, status int32, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groups", groups)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "status", status)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Updates(&groups).Error, "")
|
||||
return utils.Wrap(getDBConn(g.DB, tx).Where("group_id = ?", groupID).Model(&relation.GroupModel{}).Updates(map[string]any{"status": status}).Error, "")
|
||||
}
|
||||
|
||||
//func (g *GroupGorm) Update(ctx context.Context, groups []*relation.GroupModel, tx ...*gorm.DB) (err error) {
|
||||
// defer func() {
|
||||
// tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groups", groups)
|
||||
// }()
|
||||
// return utils.Wrap(getDBConn(g.DB, tx).Updates(&groups).Error, "")
|
||||
//}
|
||||
|
||||
func (g *GroupGorm) Find(ctx context.Context, groupIDs []string, tx ...*gorm.DB) (groups []*relation.GroupModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupIDs", groupIDs, "groups", groups)
|
||||
@@ -54,7 +61,14 @@ func (g *GroupGorm) Find(ctx context.Context, groupIDs []string, tx ...*gorm.DB)
|
||||
func (g *GroupGorm) Take(ctx context.Context, groupID string, tx ...*gorm.DB) (group *relation.GroupModel, err error) {
|
||||
group = &relation.GroupModel{}
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "group", *group)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "group", group)
|
||||
}()
|
||||
return group, utils.Wrap(getDBConn(g.DB, tx).Where("group_id = ?", groupID).Take(group).Error, "")
|
||||
}
|
||||
|
||||
func (g *GroupGorm) Search(ctx context.Context, name string, pageNumber, showNumber int32, tx ...*gorm.DB) (total int32, groups []*relation.GroupModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "name", name, "pageNumber", pageNumber, "showNumber", showNumber, "total", total, "groups", groups)
|
||||
}()
|
||||
return gormSearch[relation.GroupModel](getDBConn(g.DB, tx), "name", name, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ package relation
|
||||
//received
|
||||
//func GetRecvGroupApplicationList(userID string) ([]GroupRequest, error) {
|
||||
// var groupRequestList []GroupRequest
|
||||
// memberList, err := GetGroupMemberListByUserID(userID)
|
||||
// memberList, err := FindGroupMember(userID)
|
||||
// if err != nil {
|
||||
// return nil, utils.Wrap(err, utils.GetSelfFuncName())
|
||||
// }
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/utils"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func gormPage[E any](db *gorm.DB, pageNumber, showNumber int32) (int32, []*E, error) {
|
||||
var count int64
|
||||
if err := db.Model(new(E)).Count(&count).Error; err != nil {
|
||||
return 0, nil, utils.Wrap(err, "")
|
||||
}
|
||||
var es []*E
|
||||
if err := db.Limit(int(showNumber)).Offset(int(pageNumber * showNumber)).Find(&es).Error; err != nil {
|
||||
return 0, nil, utils.Wrap(err, "")
|
||||
}
|
||||
return int32(count), es, nil
|
||||
}
|
||||
|
||||
func gormSearch[E any](db *gorm.DB, field string, value string, pageNumber, showNumber int32) (int32, []*E, error) {
|
||||
if field != "" && value != "" {
|
||||
db = db.Where(field+" like ?", "%"+value+"%")
|
||||
}
|
||||
return gormPage[E](db, pageNumber, showNumber)
|
||||
}
|
||||
@@ -12,7 +12,7 @@ type GroupModel struct {
|
||||
Notification string `gorm:"column:notification;size:255" json:"notification"`
|
||||
Introduction string `gorm:"column:introduction;size:255" json:"introduction"`
|
||||
FaceURL string `gorm:"column:face_url;size:255" json:"faceURL"`
|
||||
CreateTime time.Time `gorm:"column:create_time;index:create_time"`
|
||||
CreateTime time.Time `gorm:"column:create_time;index:create_time;autoCreateTime"`
|
||||
Ex string `gorm:"column:ex" json:"ex;size:1024" json:"ex"`
|
||||
Status int32 `gorm:"column:status"`
|
||||
CreatorUserID string `gorm:"column:creator_user_id;size:64"`
|
||||
|
||||
Reference in New Issue
Block a user