mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-03 08:35:59 +08:00
* feat: Add light mode and dark mode.(#89) Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: make file code len Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: fix scripts support win Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: make build issue Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: golint and format Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add scripts sudo limits of authority Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: docker images fix Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: docker images fix Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --------- Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
This commit is contained in:
@@ -26,9 +26,9 @@ import (
|
||||
)
|
||||
|
||||
type AuthDatabase interface {
|
||||
//结果为空 不返回错误
|
||||
// 结果为空 不返回错误
|
||||
GetTokensWithoutError(ctx context.Context, userID string, platformID int) (map[string]int, error)
|
||||
//创建token
|
||||
// 创建token
|
||||
CreateToken(ctx context.Context, userID string, platformID int) (string, error)
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ func NewAuthDatabase(cache cache.MsgModel, accessSecret string, accessExpire int
|
||||
return &authDatabase{cache: cache, accessSecret: accessSecret, accessExpire: accessExpire}
|
||||
}
|
||||
|
||||
// 结果为空 不返回错误
|
||||
// 结果为空 不返回错误.
|
||||
func (a *authDatabase) GetTokensWithoutError(
|
||||
ctx context.Context,
|
||||
userID string,
|
||||
@@ -52,7 +52,7 @@ func (a *authDatabase) GetTokensWithoutError(
|
||||
return a.cache.GetTokensWithoutError(ctx, userID, platformID)
|
||||
}
|
||||
|
||||
// 创建token
|
||||
// 创建token.
|
||||
func (a *authDatabase) CreateToken(ctx context.Context, userID string, platformID int) (string, error) {
|
||||
tokens, err := a.cache.GetTokensWithoutError(ctx, userID, platformID)
|
||||
if err != nil {
|
||||
|
||||
@@ -48,7 +48,7 @@ func NewBlackDatabase(black relation.BlackModelInterface, cache cache.BlackCache
|
||||
return &blackDatabase{black, cache}
|
||||
}
|
||||
|
||||
// Create 增加黑名单
|
||||
// Create 增加黑名单.
|
||||
func (b *blackDatabase) Create(ctx context.Context, blacks []*relation.BlackModel) (err error) {
|
||||
if err := b.black.Create(ctx, blacks); err != nil {
|
||||
return err
|
||||
@@ -56,7 +56,7 @@ func (b *blackDatabase) Create(ctx context.Context, blacks []*relation.BlackMode
|
||||
return b.deleteBlackIDsCache(ctx, blacks)
|
||||
}
|
||||
|
||||
// Delete 删除黑名单
|
||||
// Delete 删除黑名单.
|
||||
func (b *blackDatabase) Delete(ctx context.Context, blacks []*relation.BlackModel) (err error) {
|
||||
if err := b.black.Delete(ctx, blacks); err != nil {
|
||||
return err
|
||||
@@ -72,7 +72,7 @@ func (b *blackDatabase) deleteBlackIDsCache(ctx context.Context, blacks []*relat
|
||||
return cache.ExecDel(ctx)
|
||||
}
|
||||
|
||||
// FindOwnerBlacks 获取黑名单列表
|
||||
// FindOwnerBlacks 获取黑名单列表.
|
||||
func (b *blackDatabase) FindOwnerBlacks(
|
||||
ctx context.Context,
|
||||
ownerUserID string,
|
||||
@@ -81,7 +81,7 @@ func (b *blackDatabase) FindOwnerBlacks(
|
||||
return b.black.FindOwnerBlacks(ctx, ownerUserID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// CheckIn 检查user2是否在user1的黑名单列表中(inUser1Blacks==true) 检查user1是否在user2的黑名单列表中(inUser2Blacks==true)
|
||||
// CheckIn 检查user2是否在user1的黑名单列表中(inUser1Blacks==true) 检查user1是否在user2的黑名单列表中(inUser2Blacks==true).
|
||||
func (b *blackDatabase) CheckIn(
|
||||
ctx context.Context,
|
||||
userID1, userID2 string,
|
||||
|
||||
@@ -27,21 +27,21 @@ import (
|
||||
)
|
||||
|
||||
type ConversationDatabase interface {
|
||||
//UpdateUserConversationFiled 更新用户该会话的属性信息
|
||||
// UpdateUserConversationFiled 更新用户该会话的属性信息
|
||||
UpdateUsersConversationFiled(ctx context.Context, userIDs []string, conversationID string, args map[string]interface{}) error
|
||||
//CreateConversation 创建一批新的会话
|
||||
// CreateConversation 创建一批新的会话
|
||||
CreateConversation(ctx context.Context, conversations []*relationTb.ConversationModel) error
|
||||
//SyncPeerUserPrivateConversation 同步对端私聊会话内部保证事务操作
|
||||
// SyncPeerUserPrivateConversation 同步对端私聊会话内部保证事务操作
|
||||
SyncPeerUserPrivateConversationTx(ctx context.Context, conversation []*relationTb.ConversationModel) error
|
||||
//FindConversations 根据会话ID获取某个用户的多个会话
|
||||
// FindConversations 根据会话ID获取某个用户的多个会话
|
||||
FindConversations(ctx context.Context, ownerUserID string, conversationIDs []string) ([]*relationTb.ConversationModel, error)
|
||||
//FindRecvMsgNotNotifyUserIDs 获取超级大群开启免打扰的用户ID
|
||||
// FindRecvMsgNotNotifyUserIDs 获取超级大群开启免打扰的用户ID
|
||||
FindRecvMsgNotNotifyUserIDs(ctx context.Context, groupID string) ([]string, error)
|
||||
//GetUserAllConversation 获取一个用户在服务器上所有的会话
|
||||
// GetUserAllConversation 获取一个用户在服务器上所有的会话
|
||||
GetUserAllConversation(ctx context.Context, ownerUserID string) ([]*relationTb.ConversationModel, error)
|
||||
//SetUserConversations 设置用户多个会话属性,如果会话不存在则创建,否则更新,内部保证原子性
|
||||
// SetUserConversations 设置用户多个会话属性,如果会话不存在则创建,否则更新,内部保证原子性
|
||||
SetUserConversations(ctx context.Context, ownerUserID string, conversations []*relationTb.ConversationModel) error
|
||||
//SetUsersConversationFiledTx 设置多个用户会话关于某个字段的更新操作,如果会话不存在则创建,否则更新,内部保证事务操作
|
||||
// SetUsersConversationFiledTx 设置多个用户会话关于某个字段的更新操作,如果会话不存在则创建,否则更新,内部保证事务操作
|
||||
SetUsersConversationFiledTx(ctx context.Context, userIDs []string, conversation *relationTb.ConversationModel, filedMap map[string]interface{}) error
|
||||
CreateGroupChatConversation(ctx context.Context, groupID string, userIDs []string) error
|
||||
GetConversationIDs(ctx context.Context, userID string) ([]string, error)
|
||||
@@ -98,7 +98,6 @@ func (c *conversationDatabase) SetUsersConversationFiledTx(ctx context.Context,
|
||||
temp.OwnerUserID = v
|
||||
temp.CreateTime = now
|
||||
conversations = append(conversations, temp)
|
||||
|
||||
}
|
||||
if len(conversations) > 0 {
|
||||
err = conversationTx.Create(ctx, conversations)
|
||||
|
||||
@@ -93,7 +93,7 @@ func NewFriendDatabase(
|
||||
return &friendDatabase{friend: friend, friendRequest: friendRequest, cache: cache, tx: tx}
|
||||
}
|
||||
|
||||
// ok 检查user2是否在user1的好友列表中(inUser1Friends==true) 检查user1是否在user2的好友列表中(inUser2Friends==true)
|
||||
// ok 检查user2是否在user1的好友列表中(inUser1Friends==true) 检查user1是否在user2的好友列表中(inUser2Friends==true).
|
||||
func (f *friendDatabase) CheckIn(
|
||||
ctx context.Context,
|
||||
userID1, userID2 string,
|
||||
@@ -109,7 +109,7 @@ func (f *friendDatabase) CheckIn(
|
||||
return utils.IsContain(userID2, userID1FriendIDs), utils.IsContain(userID1, userID2FriendIDs), nil
|
||||
}
|
||||
|
||||
// 增加或者更新好友申请 如果之前有记录则更新,没有记录则新增
|
||||
// 增加或者更新好友申请 如果之前有记录则更新,没有记录则新增.
|
||||
func (f *friendDatabase) AddFriendRequest(
|
||||
ctx context.Context,
|
||||
fromUserID, toUserID string,
|
||||
@@ -118,11 +118,11 @@ func (f *friendDatabase) AddFriendRequest(
|
||||
) (err error) {
|
||||
return f.tx.Transaction(func(tx any) error {
|
||||
_, err := f.friendRequest.NewTx(tx).Take(ctx, fromUserID, toUserID)
|
||||
//有db错误
|
||||
// 有db错误
|
||||
if err != nil && errs.Unwrap(err) != gorm.ErrRecordNotFound {
|
||||
return err
|
||||
}
|
||||
//无错误 则更新
|
||||
// 无错误 则更新
|
||||
if err == nil {
|
||||
m := make(map[string]interface{}, 1)
|
||||
m["handle_result"] = 0
|
||||
@@ -135,7 +135,7 @@ func (f *friendDatabase) AddFriendRequest(
|
||||
}
|
||||
return nil
|
||||
}
|
||||
//gorm.ErrRecordNotFound 错误,则新增
|
||||
// gorm.ErrRecordNotFound 错误,则新增
|
||||
if err := f.friendRequest.NewTx(tx).Create(ctx, []*relation.FriendRequestModel{{FromUserID: fromUserID, ToUserID: toUserID, ReqMsg: reqMsg, Ex: ex, CreateTime: time.Now(), HandleTime: time.Unix(0, 0)}}); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -143,7 +143,7 @@ func (f *friendDatabase) AddFriendRequest(
|
||||
})
|
||||
}
|
||||
|
||||
// (1)先判断是否在好友表 (在不在都不返回错误) (2)对于不在好友列表的 插入即可
|
||||
// (1)先判断是否在好友表 (在不在都不返回错误) (2)对于不在好友列表的 插入即可.
|
||||
func (f *friendDatabase) BecomeFriends(
|
||||
ctx context.Context,
|
||||
ownerUserID string,
|
||||
@@ -152,7 +152,7 @@ func (f *friendDatabase) BecomeFriends(
|
||||
) (err error) {
|
||||
cache := f.cache.NewCache()
|
||||
if err := f.tx.Transaction(func(tx any) error {
|
||||
//先find 找出重复的 去掉重复的
|
||||
// 先find 找出重复的 去掉重复的
|
||||
fs1, err := f.friend.NewTx(tx).FindFriends(ctx, ownerUserID, friendUserIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -194,7 +194,7 @@ func (f *friendDatabase) BecomeFriends(
|
||||
return cache.ExecDel(ctx)
|
||||
}
|
||||
|
||||
// 拒绝好友申请 (1)检查是否有申请记录且为未处理状态 (没有记录返回错误) (2)修改申请记录 已拒绝
|
||||
// 拒绝好友申请 (1)检查是否有申请记录且为未处理状态 (没有记录返回错误) (2)修改申请记录 已拒绝.
|
||||
func (f *friendDatabase) RefuseFriendRequest(
|
||||
ctx context.Context,
|
||||
friendRequest *relation.FriendRequestModel,
|
||||
@@ -215,7 +215,7 @@ func (f *friendDatabase) RefuseFriendRequest(
|
||||
return nil
|
||||
}
|
||||
|
||||
// AgreeFriendRequest 同意好友申请 (1)检查是否有申请记录且为未处理状态 (没有记录返回错误) (2)检查是否好友(不返回错误) (3) 建立双向好友关系(存在的忽略)
|
||||
// AgreeFriendRequest 同意好友申请 (1)检查是否有申请记录且为未处理状态 (没有记录返回错误) (2)检查是否好友(不返回错误) (3) 建立双向好友关系(存在的忽略).
|
||||
func (f *friendDatabase) AgreeFriendRequest(
|
||||
ctx context.Context,
|
||||
friendRequest *relation.FriendRequestModel,
|
||||
@@ -289,7 +289,7 @@ func (f *friendDatabase) AgreeFriendRequest(
|
||||
})
|
||||
}
|
||||
|
||||
// 删除好友 外部判断是否好友关系
|
||||
// 删除好友 外部判断是否好友关系.
|
||||
func (f *friendDatabase) Delete(ctx context.Context, ownerUserID string, friendUserIDs []string) (err error) {
|
||||
if err := f.friend.Delete(ctx, ownerUserID, friendUserIDs); err != nil {
|
||||
return err
|
||||
@@ -297,7 +297,7 @@ func (f *friendDatabase) Delete(ctx context.Context, ownerUserID string, friendU
|
||||
return f.cache.DelFriendIDs(append(friendUserIDs, ownerUserID)...).ExecDel(ctx)
|
||||
}
|
||||
|
||||
// 更新好友备注 零值也支持
|
||||
// 更新好友备注 零值也支持.
|
||||
func (f *friendDatabase) UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error) {
|
||||
if err := f.friend.UpdateRemark(ctx, ownerUserID, friendUserID, remark); err != nil {
|
||||
return err
|
||||
@@ -305,7 +305,7 @@ func (f *friendDatabase) UpdateRemark(ctx context.Context, ownerUserID, friendUs
|
||||
return f.cache.DelFriend(ownerUserID, friendUserID).ExecDel(ctx)
|
||||
}
|
||||
|
||||
// 获取ownerUserID的好友列表 无结果不返回错误
|
||||
// 获取ownerUserID的好友列表 无结果不返回错误.
|
||||
func (f *friendDatabase) PageOwnerFriends(
|
||||
ctx context.Context,
|
||||
ownerUserID string,
|
||||
@@ -314,7 +314,7 @@ func (f *friendDatabase) PageOwnerFriends(
|
||||
return f.friend.FindOwnerFriends(ctx, ownerUserID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// friendUserID在哪些人的好友列表中
|
||||
// friendUserID在哪些人的好友列表中.
|
||||
func (f *friendDatabase) PageInWhoseFriends(
|
||||
ctx context.Context,
|
||||
friendUserID string,
|
||||
@@ -323,7 +323,7 @@ func (f *friendDatabase) PageInWhoseFriends(
|
||||
return f.friend.FindInWhoseFriends(ctx, friendUserID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// 获取我发出去的好友申请 无结果不返回错误
|
||||
// 获取我发出去的好友申请 无结果不返回错误.
|
||||
func (f *friendDatabase) PageFriendRequestFromMe(
|
||||
ctx context.Context,
|
||||
userID string,
|
||||
@@ -332,7 +332,7 @@ func (f *friendDatabase) PageFriendRequestFromMe(
|
||||
return f.friendRequest.FindFromUserID(ctx, userID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// 获取我收到的的好友申请 无结果不返回错误
|
||||
// 获取我收到的的好友申请 无结果不返回错误.
|
||||
func (f *friendDatabase) PageFriendRequestToMe(
|
||||
ctx context.Context,
|
||||
userID string,
|
||||
@@ -341,7 +341,7 @@ func (f *friendDatabase) PageFriendRequestToMe(
|
||||
return f.friendRequest.FindToUserID(ctx, userID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// 获取某人指定好友的信息 如果有好友不存在,也返回错误
|
||||
// 获取某人指定好友的信息 如果有好友不存在,也返回错误.
|
||||
func (f *friendDatabase) FindFriendsWithError(
|
||||
ctx context.Context,
|
||||
ownerUserID string,
|
||||
|
||||
@@ -203,7 +203,7 @@ func (g *groupDatabase) CreateGroup(
|
||||
groups []*relationTb.GroupModel,
|
||||
groupMembers []*relationTb.GroupMemberModel,
|
||||
) error {
|
||||
var cache = g.cache.NewCache()
|
||||
cache := g.cache.NewCache()
|
||||
if err := g.tx.Transaction(func(tx any) error {
|
||||
if len(groups) > 0 {
|
||||
if err := g.groupDB.NewTx(tx).Create(ctx, groups); err != nil {
|
||||
@@ -473,7 +473,7 @@ func (g *groupDatabase) UpdateGroupMember(
|
||||
}
|
||||
|
||||
func (g *groupDatabase) UpdateGroupMembers(ctx context.Context, data []*relationTb.BatchUpdateGroupMember) error {
|
||||
var cache = g.cache.NewCache()
|
||||
cache := g.cache.NewCache()
|
||||
if err := g.tx.Transaction(func(tx any) error {
|
||||
for _, item := range data {
|
||||
if err := g.groupMemberDB.NewTx(tx).Update(ctx, item.GroupID, item.UserID, item.Map); err != nil {
|
||||
|
||||
@@ -15,10 +15,14 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
relation2 "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/relation"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
|
||||
@@ -32,13 +36,11 @@ import (
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
|
||||
|
||||
"context"
|
||||
"errors"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
|
||||
pbMsg "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -103,8 +105,23 @@ type CommonMsgDatabase interface {
|
||||
MsgToPushMQ(ctx context.Context, key, conversarionID string, msg2mq *sdkws.MsgData) (int32, int64, error)
|
||||
MsgToMongoMQ(ctx context.Context, key, conversarionID string, msgs []*sdkws.MsgData, lastSeq int64) error
|
||||
|
||||
RangeUserSendCount(ctx context.Context, start time.Time, end time.Time, group bool, ase bool, pageNumber int32, showNumber int32) (msgCount int64, userCount int64, users []*unRelationTb.UserCount, dateCount map[string]int64, err error)
|
||||
RangeGroupSendCount(ctx context.Context, start time.Time, end time.Time, ase bool, pageNumber int32, showNumber int32) (msgCount int64, userCount int64, groups []*unRelationTb.GroupCount, dateCount map[string]int64, err error)
|
||||
RangeUserSendCount(
|
||||
ctx context.Context,
|
||||
start time.Time,
|
||||
end time.Time,
|
||||
group bool,
|
||||
ase bool,
|
||||
pageNumber int32,
|
||||
showNumber int32,
|
||||
) (msgCount int64, userCount int64, users []*unRelationTb.UserCount, dateCount map[string]int64, err error)
|
||||
RangeGroupSendCount(
|
||||
ctx context.Context,
|
||||
start time.Time,
|
||||
end time.Time,
|
||||
ase bool,
|
||||
pageNumber int32,
|
||||
showNumber int32,
|
||||
) (msgCount int64, userCount int64, groups []*unRelationTb.GroupCount, dateCount map[string]int64, err error)
|
||||
}
|
||||
|
||||
func NewCommonMsgDatabase(msgDocModel unRelationTb.MsgDocModelInterface, cacheModel cache.MsgModel, msgMyqModel relation.ChatLogModelInterface) CommonMsgDatabase {
|
||||
@@ -172,7 +189,7 @@ func (db *commonMsgDatabase) BatchInsertBlock(ctx context.Context, conversationI
|
||||
return nil
|
||||
}
|
||||
num := db.msg.GetSingleGocMsgNum()
|
||||
//num = 100
|
||||
// num = 100
|
||||
for i, field := range fields { // 检查类型
|
||||
var ok bool
|
||||
switch key {
|
||||
@@ -390,7 +407,7 @@ func (db *commonMsgDatabase) BatchInsertChat2Cache(ctx context.Context, conversa
|
||||
|
||||
func (db *commonMsgDatabase) getMsgBySeqs(ctx context.Context, userID, conversationID string, seqs []int64) (totalMsgs []*sdkws.MsgData, err error) {
|
||||
for docID, seqs := range db.msg.GetDocIDSeqsMap(conversationID, seqs) {
|
||||
//log.ZDebug(ctx, "getMsgBySeqs", "docID", docID, "seqs", seqs)
|
||||
// log.ZDebug(ctx, "getMsgBySeqs", "docID", docID, "seqs", seqs)
|
||||
msgs, err := db.findMsgInfoBySeq(ctx, userID, docID, seqs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -575,7 +592,22 @@ func (db *commonMsgDatabase) GetMsgBySeqs(ctx context.Context, userID string, co
|
||||
log.ZError(ctx, "get message from redis exception", err, "failedSeqs", failedSeqs, "conversationID", conversationID)
|
||||
}
|
||||
}
|
||||
log.ZInfo(ctx, "db.cache.GetMessagesBySeq", "userID", userID, "conversationID", conversationID, "seqs", seqs, "successMsgs", len(successMsgs), "failedSeqs", failedSeqs, "conversationID", conversationID)
|
||||
log.ZInfo(
|
||||
ctx,
|
||||
"db.cache.GetMessagesBySeq",
|
||||
"userID",
|
||||
userID,
|
||||
"conversationID",
|
||||
conversationID,
|
||||
"seqs",
|
||||
seqs,
|
||||
"successMsgs",
|
||||
len(successMsgs),
|
||||
"failedSeqs",
|
||||
failedSeqs,
|
||||
"conversationID",
|
||||
conversationID,
|
||||
)
|
||||
prome.Add(prome.MsgPullFromRedisSuccessCounter, len(successMsgs))
|
||||
if len(failedSeqs) > 0 {
|
||||
mongoMsgs, err := db.getMsgBySeqs(ctx, userID, conversationID, failedSeqs)
|
||||
@@ -637,7 +669,6 @@ func (db *commonMsgDatabase) UserMsgsDestruct(ctx context.Context, userID string
|
||||
log.ZDebug(ctx, "deleteMsgRecursion finished", "conversationID", conversationID, "userID", userID, "index", index)
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -652,7 +683,7 @@ func (db *commonMsgDatabase) UserMsgsDestruct(ctx context.Context, userID string
|
||||
return seqs, nil
|
||||
}
|
||||
|
||||
// this is struct for recursion
|
||||
// this is struct for recursion.
|
||||
type delMsgRecursionStruct struct {
|
||||
minSeq int64
|
||||
delDocIDs []string
|
||||
@@ -665,7 +696,7 @@ func (d *delMsgRecursionStruct) getSetMinSeq() int64 {
|
||||
// index 0....19(del) 20...69
|
||||
// seq 70
|
||||
// set minSeq 21
|
||||
// recursion 删除list并且返回设置的最小seq
|
||||
// recursion 删除list并且返回设置的最小seq.
|
||||
func (db *commonMsgDatabase) deleteMsgRecursion(ctx context.Context, conversationID string, index int64, delStruct *delMsgRecursionStruct, remainTime int64) (int64, error) {
|
||||
// find from oldest list
|
||||
msgDocModel, err := db.msgDocDatabase.GetMsgDocModelByIndex(ctx, conversationID, index, 1)
|
||||
@@ -791,15 +822,19 @@ func (db *commonMsgDatabase) CleanUpUserConversationsMsgs(ctx context.Context, u
|
||||
func (db *commonMsgDatabase) SetMaxSeq(ctx context.Context, conversationID string, maxSeq int64) error {
|
||||
return db.cache.SetMaxSeq(ctx, conversationID, maxSeq)
|
||||
}
|
||||
|
||||
func (db *commonMsgDatabase) GetMaxSeqs(ctx context.Context, conversationIDs []string) (map[string]int64, error) {
|
||||
return db.cache.GetMaxSeqs(ctx, conversationIDs)
|
||||
}
|
||||
|
||||
func (db *commonMsgDatabase) GetMaxSeq(ctx context.Context, conversationID string) (int64, error) {
|
||||
return db.cache.GetMaxSeq(ctx, conversationID)
|
||||
}
|
||||
|
||||
func (db *commonMsgDatabase) SetMinSeq(ctx context.Context, conversationID string, minSeq int64) error {
|
||||
return db.cache.SetMinSeq(ctx, conversationID, minSeq)
|
||||
}
|
||||
|
||||
func (db *commonMsgDatabase) SetMinSeqs(ctx context.Context, seqs map[string]int64) error {
|
||||
return db.cache.SetMinSeqs(ctx, seqs)
|
||||
}
|
||||
@@ -807,18 +842,23 @@ func (db *commonMsgDatabase) SetMinSeqs(ctx context.Context, seqs map[string]int
|
||||
func (db *commonMsgDatabase) GetMinSeqs(ctx context.Context, conversationIDs []string) (map[string]int64, error) {
|
||||
return db.cache.GetMinSeqs(ctx, conversationIDs)
|
||||
}
|
||||
|
||||
func (db *commonMsgDatabase) GetMinSeq(ctx context.Context, conversationID string) (int64, error) {
|
||||
return db.cache.GetMinSeq(ctx, conversationID)
|
||||
}
|
||||
|
||||
func (db *commonMsgDatabase) GetConversationUserMinSeq(ctx context.Context, conversationID string, userID string) (int64, error) {
|
||||
return db.cache.GetConversationUserMinSeq(ctx, conversationID, userID)
|
||||
}
|
||||
|
||||
func (db *commonMsgDatabase) GetConversationUserMinSeqs(ctx context.Context, conversationID string, userIDs []string) (map[string]int64, error) {
|
||||
return db.cache.GetConversationUserMinSeqs(ctx, conversationID, userIDs)
|
||||
}
|
||||
|
||||
func (db *commonMsgDatabase) SetConversationUserMinSeq(ctx context.Context, conversationID string, userID string, minSeq int64) error {
|
||||
return db.cache.SetConversationUserMinSeq(ctx, conversationID, userID, minSeq)
|
||||
}
|
||||
|
||||
func (db *commonMsgDatabase) SetConversationUserMinSeqs(ctx context.Context, conversationID string, seqs map[string]int64) (err error) {
|
||||
return db.cache.SetConversationUserMinSeqs(ctx, conversationID, seqs)
|
||||
}
|
||||
@@ -834,6 +874,7 @@ func (db *commonMsgDatabase) UserSetHasReadSeqs(ctx context.Context, userID stri
|
||||
func (db *commonMsgDatabase) SetHasReadSeq(ctx context.Context, userID string, conversationID string, hasReadSeq int64) error {
|
||||
return db.cache.SetHasReadSeq(ctx, userID, conversationID, hasReadSeq)
|
||||
}
|
||||
|
||||
func (db *commonMsgDatabase) GetHasReadSeqs(ctx context.Context, userID string, conversationIDs []string) (map[string]int64, error) {
|
||||
return db.cache.GetHasReadSeqs(ctx, userID, conversationIDs)
|
||||
}
|
||||
@@ -884,11 +925,26 @@ func (db *commonMsgDatabase) GetMinMaxSeqMongo(ctx context.Context, conversation
|
||||
return
|
||||
}
|
||||
|
||||
func (db *commonMsgDatabase) RangeUserSendCount(ctx context.Context, start time.Time, end time.Time, group bool, ase bool, pageNumber int32, showNumber int32) (msgCount int64, userCount int64, users []*unRelationTb.UserCount, dateCount map[string]int64, err error) {
|
||||
func (db *commonMsgDatabase) RangeUserSendCount(
|
||||
ctx context.Context,
|
||||
start time.Time,
|
||||
end time.Time,
|
||||
group bool,
|
||||
ase bool,
|
||||
pageNumber int32,
|
||||
showNumber int32,
|
||||
) (msgCount int64, userCount int64, users []*unRelationTb.UserCount, dateCount map[string]int64, err error) {
|
||||
return db.msgDocDatabase.RangeUserSendCount(ctx, start, end, group, ase, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
func (db *commonMsgDatabase) RangeGroupSendCount(ctx context.Context, start time.Time, end time.Time, ase bool, pageNumber int32, showNumber int32) (msgCount int64, userCount int64, groups []*unRelationTb.GroupCount, dateCount map[string]int64, err error) {
|
||||
func (db *commonMsgDatabase) RangeGroupSendCount(
|
||||
ctx context.Context,
|
||||
start time.Time,
|
||||
end time.Time,
|
||||
ase bool,
|
||||
pageNumber int32,
|
||||
showNumber int32,
|
||||
) (msgCount int64, userCount int64, groups []*unRelationTb.GroupCount, dateCount map[string]int64, err error) {
|
||||
return db.msgDocDatabase.RangeGroupSendCount(ctx, start, end, ase, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,12 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3/cont"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
type S3Database interface {
|
||||
|
||||
@@ -26,19 +26,19 @@ import (
|
||||
)
|
||||
|
||||
type UserDatabase interface {
|
||||
//获取指定用户的信息 如有userID未找到 也返回错误
|
||||
// 获取指定用户的信息 如有userID未找到 也返回错误
|
||||
FindWithError(ctx context.Context, userIDs []string) (users []*relation.UserModel, err error)
|
||||
//获取指定用户的信息 如有userID未找到 不返回错误
|
||||
// 获取指定用户的信息 如有userID未找到 不返回错误
|
||||
Find(ctx context.Context, userIDs []string) (users []*relation.UserModel, err error)
|
||||
//插入多条 外部保证userID 不重复 且在db中不存在
|
||||
// 插入多条 外部保证userID 不重复 且在db中不存在
|
||||
Create(ctx context.Context, users []*relation.UserModel) (err error)
|
||||
//更新(非零值) 外部保证userID存在
|
||||
// 更新(非零值) 外部保证userID存在
|
||||
Update(ctx context.Context, user *relation.UserModel) (err error)
|
||||
//更新(零值) 外部保证userID存在
|
||||
// 更新(零值) 外部保证userID存在
|
||||
UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error)
|
||||
//如果没找到,不返回错误
|
||||
// 如果没找到,不返回错误
|
||||
Page(ctx context.Context, pageNumber, showNumber int32) (users []*relation.UserModel, count int64, err error)
|
||||
//只要有一个存在就为true
|
||||
// 只要有一个存在就为true
|
||||
IsExist(ctx context.Context, userIDs []string) (exist bool, err error)
|
||||
//获取所有用户ID
|
||||
GetAllUserID(ctx context.Context, pageNumber, showNumber int32) ([]string, error)
|
||||
@@ -75,7 +75,7 @@ func (u *userDatabase) InitOnce(ctx context.Context, users []*relation.UserModel
|
||||
return nil
|
||||
}
|
||||
|
||||
// 获取指定用户的信息 如有userID未找到 也返回错误
|
||||
// 获取指定用户的信息 如有userID未找到 也返回错误.
|
||||
func (u *userDatabase) FindWithError(ctx context.Context, userIDs []string) (users []*relation.UserModel, err error) {
|
||||
users, err = u.cache.GetUsersInfo(ctx, userIDs)
|
||||
if err != nil {
|
||||
@@ -87,13 +87,13 @@ func (u *userDatabase) FindWithError(ctx context.Context, userIDs []string) (use
|
||||
return
|
||||
}
|
||||
|
||||
// 获取指定用户的信息 如有userID未找到 不返回错误
|
||||
// 获取指定用户的信息 如有userID未找到 不返回错误.
|
||||
func (u *userDatabase) Find(ctx context.Context, userIDs []string) (users []*relation.UserModel, err error) {
|
||||
users, err = u.cache.GetUsersInfo(ctx, userIDs)
|
||||
return
|
||||
}
|
||||
|
||||
// 插入多条 外部保证userID 不重复 且在db中不存在
|
||||
// 插入多条 外部保证userID 不重复 且在db中不存在.
|
||||
func (u *userDatabase) Create(ctx context.Context, users []*relation.UserModel) (err error) {
|
||||
if err := u.tx.Transaction(func(tx any) error {
|
||||
err = u.userDB.Create(ctx, users)
|
||||
@@ -111,7 +111,7 @@ func (u *userDatabase) Create(ctx context.Context, users []*relation.UserModel)
|
||||
return u.cache.DelUsersInfo(userIDs...).ExecDel(ctx)
|
||||
}
|
||||
|
||||
// 更新(非零值) 外部保证userID存在
|
||||
// 更新(非零值) 外部保证userID存在.
|
||||
func (u *userDatabase) Update(ctx context.Context, user *relation.UserModel) (err error) {
|
||||
if err := u.userDB.Update(ctx, user); err != nil {
|
||||
return err
|
||||
@@ -119,7 +119,7 @@ func (u *userDatabase) Update(ctx context.Context, user *relation.UserModel) (er
|
||||
return u.cache.DelUsersInfo(user.UserID).ExecDel(ctx)
|
||||
}
|
||||
|
||||
// 更新(零值) 外部保证userID存在
|
||||
// 更新(零值) 外部保证userID存在.
|
||||
func (u *userDatabase) UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error) {
|
||||
if err := u.userDB.UpdateByMap(ctx, userID, args); err != nil {
|
||||
return err
|
||||
@@ -127,7 +127,7 @@ func (u *userDatabase) UpdateByMap(ctx context.Context, userID string, args map[
|
||||
return u.cache.DelUsersInfo(userID).ExecDel(ctx)
|
||||
}
|
||||
|
||||
// 获取,如果没找到,不返回错误
|
||||
// 获取,如果没找到,不返回错误.
|
||||
func (u *userDatabase) Page(
|
||||
ctx context.Context,
|
||||
pageNumber, showNumber int32,
|
||||
@@ -135,7 +135,7 @@ func (u *userDatabase) Page(
|
||||
return u.userDB.Page(ctx, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// userIDs是否存在 只要有一个存在就为true
|
||||
// userIDs是否存在 只要有一个存在就为true.
|
||||
func (u *userDatabase) IsExist(ctx context.Context, userIDs []string) (exist bool, err error) {
|
||||
users, err := u.userDB.Find(ctx, userIDs)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user