mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-02 08:05:58 +08:00
db
This commit is contained in:
@@ -3,6 +3,7 @@ package controller
|
||||
import (
|
||||
relation2 "Open_IM/pkg/common/db/relation"
|
||||
"Open_IM/pkg/common/db/table/relation"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
@@ -100,7 +101,7 @@ func (b *BlackDatabase) CheckIn(ctx context.Context, userID1, userID2 string) (i
|
||||
inUser2Blacks = true
|
||||
_, err = b.sqlDB.Take(ctx, userID2, userID1)
|
||||
if err != nil {
|
||||
if errors.Unwrap(err) != gorm.ErrRecordNotFound {
|
||||
if utils.Unwrap(err) != gorm.ErrRecordNotFound {
|
||||
return
|
||||
}
|
||||
inUser2Blacks = false
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
type ChatLogInterface interface {
|
||||
CreateChatLog(msg pbMsg.MsgDataToMQ) error
|
||||
GetChatLog(chatLog *relationTb.ChatLogModel, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relation.ChatLog, error)
|
||||
GetChatLog(chatLog *relationTb.ChatLogModel, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relationTb.ChatLogModel, error)
|
||||
}
|
||||
|
||||
func NewChatLogController(db *gorm.DB) ChatLogInterface {
|
||||
@@ -24,17 +24,17 @@ func (c *ChatLogController) CreateChatLog(msg pbMsg.MsgDataToMQ) error {
|
||||
return c.database.CreateChatLog(msg)
|
||||
}
|
||||
|
||||
func (c *ChatLogController) GetChatLog(chatLog *relationTb.ChatLogModel, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relation.ChatLog, error) {
|
||||
func (c *ChatLogController) GetChatLog(chatLog *relationTb.ChatLogModel, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relationTb.ChatLogModel, error) {
|
||||
return c.database.GetChatLog(chatLog, pageNumber, showNumber, contentTypeList)
|
||||
}
|
||||
|
||||
type ChatLogDataBaseInterface interface {
|
||||
CreateChatLog(msg pbMsg.MsgDataToMQ) error
|
||||
GetChatLog(chatLog *relationTb.ChatLogModel, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relation.ChatLog, error)
|
||||
GetChatLog(chatLog *relationTb.ChatLogModel, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relationTb.ChatLogModel, error)
|
||||
}
|
||||
|
||||
type ChatLogDataBase struct {
|
||||
chatLogDB *relationTb.ChatLogModelInterface
|
||||
chatLogDB relationTb.ChatLogModelInterface
|
||||
}
|
||||
|
||||
func NewChatLogDataBase(db *gorm.DB) ChatLogDataBaseInterface {
|
||||
@@ -45,6 +45,6 @@ func (c *ChatLogDataBase) CreateChatLog(msg pbMsg.MsgDataToMQ) error {
|
||||
return c.chatLogDB.Create(msg)
|
||||
}
|
||||
|
||||
func (c *ChatLogDataBase) GetChatLog(chatLog *relationTb.ChatLogModel, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relation.ChatLog, error) {
|
||||
func (c *ChatLogDataBase) GetChatLog(chatLog *relationTb.ChatLogModel, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relationTb.ChatLogModel, error) {
|
||||
return c.chatLogDB.GetChatLog(chatLog, pageNumber, showNumber, contentTypeList)
|
||||
}
|
||||
|
||||
@@ -88,12 +88,12 @@ func (e *ExtendMsgDatabase) InsertExtendMsg(ctx context.Context, sourceID string
|
||||
}
|
||||
|
||||
func (e *ExtendMsgDatabase) InsertOrUpdateReactionExtendMsgSet(ctx context.Context, sourceID string, sessionType int32, clientMsgID string, msgFirstModifyTime int64, reactionExtensionList map[string]*sdkws.KeyValue) error {
|
||||
return e.InsertOrUpdateReactionExtendMsgSet(ctx, sourceID, sessionType, clientMsgID, msgFirstModifyTime, reactionExtensionList)
|
||||
return e.model.InsertOrUpdateReactionExtendMsgSet(ctx, sourceID, sessionType, clientMsgID, msgFirstModifyTime, reactionExtensionList)
|
||||
}
|
||||
func (e *ExtendMsgDatabase) DeleteReactionExtendMsgSet(ctx context.Context, sourceID string, sessionType int32, clientMsgID string, msgFirstModifyTime int64, reactionExtensionList map[string]*sdkws.KeyValue) error {
|
||||
return e.DeleteReactionExtendMsgSet(ctx, sourceID, sessionType, clientMsgID, msgFirstModifyTime, reactionExtensionList)
|
||||
return e.model.DeleteReactionExtendMsgSet(ctx, sourceID, sessionType, clientMsgID, msgFirstModifyTime, reactionExtensionList)
|
||||
}
|
||||
|
||||
func (e *ExtendMsgDatabase) GetExtendMsg(ctx context.Context, sourceID string, sessionType int32, clientMsgID string, maxMsgUpdateTime int64) (extendMsg *unRelationTb.ExtendMsgModel, err error) {
|
||||
return e.GetExtendMsg(ctx, sourceID, sessionType, clientMsgID, maxMsgUpdateTime)
|
||||
return e.model.TakeExtendMsg(ctx, sourceID, sessionType, clientMsgID, maxMsgUpdateTime)
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ func (g *GroupController) DismissGroup(ctx context.Context, groupID string) erro
|
||||
}
|
||||
|
||||
func (g *GroupController) GetGroupIDsByGroupType(ctx context.Context, groupType int) (groupIDs []string, err error) {
|
||||
return g.database.
|
||||
return g.database.GetGroupIDsByGroupType(ctx, groupType)
|
||||
}
|
||||
|
||||
func (g *GroupController) TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relationTb.GroupMemberModel, err error) {
|
||||
@@ -213,8 +213,8 @@ type GroupRequest interface {
|
||||
}
|
||||
|
||||
type SuperGroup interface {
|
||||
FindSuperGroup(ctx context.Context, groupIDs []string) ([]*unrelationTb.SuperGroupModel, error)
|
||||
FindJoinSuperGroup(ctx context.Context, userID string) (*unrelationTb.UserToSuperGroupModel, error)
|
||||
FindSuperGroup(ctx context.Context, groupIDs []string) ([]*unRelationTb.SuperGroupModel, error)
|
||||
FindJoinSuperGroup(ctx context.Context, userID string) (*unRelationTb.UserToSuperGroupModel, 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
|
||||
@@ -299,6 +299,10 @@ type GroupDataBase struct {
|
||||
mongoDB *unrelation.SuperGroupMongoDriver
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) GetGroupIDsByGroupType(ctx context.Context, groupType int) (groupIDs []string, err error) {
|
||||
return g.groupDB.GetGroupIDsByGroupType(ctx, groupType)
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) delGroupMemberCache(ctx context.Context, groupID string, userIDs []string) error {
|
||||
for _, userID := range userIDs {
|
||||
if err := g.cache.DelJoinedGroupID(ctx, userID); err != nil {
|
||||
@@ -346,10 +350,10 @@ func (g *GroupDataBase) CreateGroup(ctx context.Context, groups []*relationTb.Gr
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) TakeGroup(ctx context.Context, groupID string) (group *relationTb.GroupModel, err error) {
|
||||
//return g.cache.GetGroupInfo(ctx, groupID)
|
||||
return cache.GetCache(ctx, g.rcClient, g.getGroupInfoKey(groupID), g.expireTime, func(ctx context.Context) (*relationTb.GroupModel, error) {
|
||||
return g.group.Take(ctx, groupID)
|
||||
})
|
||||
return g.cache.GetGroupInfo(ctx, groupID)
|
||||
//return cache.GetCache(ctx, g.rcClient, g.getGroupInfoKey(groupID), g.expireTime, func(ctx context.Context) (*relationTb.GroupModel, error) {
|
||||
// return g.group.Take(ctx, groupID)
|
||||
//})
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) FindGroup(ctx context.Context, groupIDs []string) (groups []*relationTb.GroupModel, err error) {
|
||||
@@ -509,11 +513,11 @@ func (g *GroupDataBase) PageGroupRequestUser(ctx context.Context, userID string,
|
||||
return g.groupRequestDB.Page(ctx, userID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) FindSuperGroup(ctx context.Context, groupIDs []string) ([]*table.SuperGroupModel, error) {
|
||||
func (g *GroupDataBase) FindSuperGroup(ctx context.Context, groupIDs []string) ([]*unRelationTb.SuperGroupModel, error) {
|
||||
return g.mongoDB.FindSuperGroup(ctx, groupIDs)
|
||||
}
|
||||
|
||||
func (g *GroupDataBase) FindJoinSuperGroup(ctx context.Context, userID string) (*table.UserToSuperGroupModel, error) {
|
||||
func (g *GroupDataBase) FindJoinSuperGroup(ctx context.Context, userID string) (*unRelationTb.UserToSuperGroupModel, error) {
|
||||
return g.mongoDB.GetSuperGroupByUserID(ctx, userID)
|
||||
}
|
||||
|
||||
|
||||
@@ -337,7 +337,7 @@ func (db *MsgDatabase) GetMsgAndIndexBySeqsInOneDoc(ctx context.Context, docID s
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
if utils.Contain(msgPb.Seq, seqs) {
|
||||
if utils.Contain(msgPb.Seq, seqs...) {
|
||||
indexes = append(indexes, i)
|
||||
seqMsgs = append(seqMsgs, msgPb)
|
||||
hasSeqList = append(hasSeqList, msgPb.Seq)
|
||||
@@ -348,7 +348,7 @@ func (db *MsgDatabase) GetMsgAndIndexBySeqsInOneDoc(ctx context.Context, docID s
|
||||
}
|
||||
}
|
||||
for _, i := range seqs {
|
||||
if utils.Contain(i, hasSeqList) {
|
||||
if utils.Contain(i, hasSeqList...) {
|
||||
continue
|
||||
}
|
||||
unExistSeqs = append(unExistSeqs, i)
|
||||
@@ -398,7 +398,7 @@ func (db *MsgDatabase) getMsgBySeqs(ctx context.Context, sourceID string, seqs [
|
||||
//log.NewError(operationID, "Unmarshal err", seqUid, value, uid, seqList, err.Error())
|
||||
return nil, err
|
||||
}
|
||||
if utils.Contain(msgPb.Seq, value) {
|
||||
if utils.Contain(msgPb.Seq, value...) {
|
||||
seqMsg = append(seqMsg, msgPb)
|
||||
hasSeqs = append(hasSeqs, msgPb.Seq)
|
||||
singleCount++
|
||||
|
||||
@@ -69,8 +69,8 @@ func (g *GroupGorm) Search(ctx context.Context, keyword string, pageNumber, show
|
||||
}
|
||||
|
||||
func (g *GroupGorm) GetGroupIDsByGroupType(ctx context.Context, groupType int) (groupIDs []string, err error) {
|
||||
if err := g.DB.Model(&relation.GroupModel{}).Where("group_type = ? ", groupType).Pluck("group_id", &groupIDs).Error; err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
return groupIDs, nil
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupType", groupType, "groupIDs", groupIDs)
|
||||
}()
|
||||
return groupIDs, utils.Wrap(g.DB.Model(&relation.GroupModel{}).Where("group_type = ? ", groupType).Pluck("group_id", &groupIDs).Error, "")
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ func (GroupModel) TableName() string {
|
||||
|
||||
type GroupModelInterface interface {
|
||||
Create(ctx context.Context, groups []*GroupModel, tx ...any) (err error)
|
||||
//Delete(ctx context.Context, groupIDs []string, tx ...any) (err error)
|
||||
UpdateMap(ctx context.Context, groupID string, args map[string]interface{}, tx ...any) (err error)
|
||||
UpdateStatus(ctx context.Context, groupID string, status int32, tx ...any) (err error)
|
||||
Find(ctx context.Context, groupIDs []string, tx ...any) (groups []*GroupModel, err error)
|
||||
Take(ctx context.Context, groupID string, tx ...any) (group *GroupModel, err error)
|
||||
Search(ctx context.Context, keyword string, pageNumber, showNumber int32, tx ...any) (total uint32, groups []*GroupModel, err error)
|
||||
GetGroupIDsByGroupType(ctx context.Context, groupType int) (groupIDs []string, err error)
|
||||
}
|
||||
|
||||
@@ -29,11 +29,7 @@ func (GroupRequestModel) TableName() string {
|
||||
|
||||
type GroupRequestModelInterface interface {
|
||||
Create(ctx context.Context, groupRequests []*GroupRequestModel, tx ...any) (err error)
|
||||
//Delete(ctx context.Context, groupRequests []*GroupRequestModel, tx ...any) (err error)
|
||||
//UpdateMap(ctx context.Context, groupID string, userID string, args map[string]interface{}, tx ...any) (err error)
|
||||
UpdateHandler(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, tx ...any) (err error)
|
||||
//Update(ctx context.Context, groupRequests []*GroupRequestModel, tx ...any) (err error)
|
||||
//Find(ctx context.Context, groupRequests []*GroupRequestModel, tx ...any) (resultGroupRequests []*GroupRequestModel, err error)
|
||||
Take(ctx context.Context, groupID string, userID string, tx ...any) (groupRequest *GroupRequestModel, err error)
|
||||
Page(ctx context.Context, userID string, pageNumber, showNumber int32, tx ...any) (total uint32, groups []*GroupRequestModel, err error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user