Merge branch 'errcode' of github.com:OpenIMSDK/Open-IM-Server into errcode

# Conflicts:
#	pkg/common/db/model/group.go
test-errcode
wangchuxiao 2 years ago
parent eea7adb1b8
commit 727bf623b3

@ -90,7 +90,7 @@ func deleteMongoMsg(operationID string, ID string, index int64, delStruct *delMs
msgs, err := db.DB.GetUserMsgListByIndex(ID, index)
if err != nil || msgs.UID == "" {
if err != nil {
if err == mongo.ErrMsgListNotExist {
if err == mongoDB.ErrMsgListNotExist {
log.NewInfo(operationID, utils.GetSelfFuncName(), "ID:", ID, "index:", index, err.Error())
} else {
log.NewError(operationID, utils.GetSelfFuncName(), "GetUserMsgListByIndex failed", err.Error(), index, ID)
@ -104,7 +104,7 @@ func deleteMongoMsg(operationID string, ID string, index int64, delStruct *delMs
return delStruct.getSetMinSeq() + 1, nil
}
log.NewDebug(operationID, "ID:", ID, "index:", index, "uid:", msgs.UID, "len:", len(msgs.Msg))
if len(msgs.Msg) > mongo.GetSingleGocMsgNum() {
if len(msgs.Msg) > mongoDB.GetSingleGocMsgNum() {
log.NewWarn(operationID, utils.GetSelfFuncName(), "msgs too large", len(msgs.Msg), msgs.UID)
}
if msgs.Msg[len(msgs.Msg)-1].SendTime+(int64(config.Config.Mongo.DBRetainChatRecords)*24*60*60*1000) > utils.GetCurrentTimestampByMill() && msgListIsFull(msgs) {
@ -150,7 +150,7 @@ func deleteMongoMsg(operationID string, ID string, index int64, delStruct *delMs
return seq, utils.Wrap(err, "deleteMongoMsg failed")
}
func msgListIsFull(chat *mongo.UserChat) bool {
func msgListIsFull(chat *mongoDB.UserChat) bool {
index, _ := strconv.Atoi(strings.Split(chat.UID, ":")[1])
if index == 0 {
if len(chat.Msg) >= 4999 {

@ -71,14 +71,14 @@ func (mmc *ModifyMsgConsumerHandler) ModifyMsg(cMsg *sarama.ConsumerMessage, msg
}
if !notification.IsReact {
// first time to modify
var reactionExtensionList = make(map[string]mongo.KeyValue)
extendMsg := mongo.ExtendMsg{
var reactionExtensionList = make(map[string]mongoDB.KeyValue)
extendMsg := mongoDB.ExtendMsg{
ReactionExtensionList: reactionExtensionList,
ClientMsgID: notification.ClientMsgID,
MsgFirstModifyTime: notification.MsgFirstModifyTime,
}
for _, v := range notification.SuccessReactionExtensionList {
reactionExtensionList[v.TypeKey] = mongo.KeyValue{
reactionExtensionList[v.TypeKey] = mongoDB.KeyValue{
TypeKey: v.TypeKey,
Value: v.Value,
LatestUpdateTime: v.LatestUpdateTime,

@ -297,7 +297,7 @@ func (s *officeServer) SendMsg2Tag(_ context.Context, req *pbOffice.SendMsg2TagR
}
}
var tagSendLogs mongo.TagSendLog
var tagSendLogs mongoDB.TagSendLog
var wg sync.WaitGroup
wg.Add(len(successUserIDList))
var lock sync.Mutex
@ -310,7 +310,7 @@ func (s *officeServer) SendMsg2Tag(_ context.Context, req *pbOffice.SendMsg2TagR
return
}
lock.Lock()
tagSendLogs.UserList = append(tagSendLogs.UserList, mongo.TagUser{
tagSendLogs.UserList = append(tagSendLogs.UserList, mongoDB.TagUser{
UserID: userID,
UserName: userName,
})
@ -389,10 +389,10 @@ func (s *officeServer) GetUserTagByID(_ context.Context, req *pbOffice.GetUserTa
func (s *officeServer) CreateOneWorkMoment(_ context.Context, req *pbOffice.CreateOneWorkMomentReq) (resp *pbOffice.CreateOneWorkMomentResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp = &pbOffice.CreateOneWorkMomentResp{CommonResp: &pbOffice.CommonResp{}}
workMoment := mongo.WorkMoment{
Comments: []*mongo.Comment{},
LikeUserList: []*mongo.WorkMomentUser{},
PermissionUserList: []*mongo.WorkMomentUser{},
workMoment := mongoDB.WorkMoment{
Comments: []*mongoDB.Comment{},
LikeUserList: []*mongoDB.WorkMomentUser{},
PermissionUserList: []*mongoDB.WorkMomentUser{},
}
createUser, err := imdb.GetUserByUserID(req.WorkMoment.UserID)
if err != nil {
@ -406,14 +406,14 @@ func (s *officeServer) CreateOneWorkMoment(_ context.Context, req *pbOffice.Crea
workMoment.UserName = createUser.Nickname
workMoment.FaceURL = createUser.FaceURL
workMoment.PermissionUserIDList = s.getPermissionUserIDList(req.OperationID, req.WorkMoment.PermissionGroupList, req.WorkMoment.PermissionUserList)
workMoment.PermissionUserList = []*mongo.WorkMomentUser{}
workMoment.PermissionUserList = []*mongoDB.WorkMomentUser{}
for _, userID := range workMoment.PermissionUserIDList {
userName, err := imdb.GetUserNameByUserID(userID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserNameByUserID failed", err.Error())
continue
}
workMoment.PermissionUserList = append(workMoment.PermissionUserList, &mongo.WorkMomentUser{
workMoment.PermissionUserList = append(workMoment.PermissionUserList, &mongoDB.WorkMomentUser{
UserID: userID,
UserName: userName,
})
@ -503,7 +503,7 @@ func (s *officeServer) DeleteOneWorkMoment(_ context.Context, req *pbOffice.Dele
return resp, nil
}
func isUserCanSeeWorkMoment(userID string, workMoment mongo.WorkMoment) bool {
func isUserCanSeeWorkMoment(userID string, workMoment mongoDB.WorkMoment) bool {
if userID != workMoment.UserID {
switch workMoment.Permission {
case constant.WorkMomentPublic:
@ -570,7 +570,7 @@ func (s *officeServer) CommentOneWorkMoment(_ context.Context, req *pbOffice.Com
return resp, nil
}
}
comment := &mongo.Comment{
comment := &mongoDB.Comment{
UserID: req.UserID,
UserName: commentUser.Nickname,
ReplyUserID: req.ReplyUserID,
@ -644,7 +644,7 @@ func (s *officeServer) GetUserWorkMoments(_ context.Context, req *pbOffice.GetUs
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp = &pbOffice.GetUserWorkMomentsResp{CommonResp: &pbOffice.CommonResp{}, WorkMoments: []*pbOffice.WorkMoment{}}
resp.Pagination = &pbCommon.ResponsePagination{CurrentPage: req.Pagination.PageNumber, ShowNumber: req.Pagination.ShowNumber}
var workMoments []mongo.WorkMoment
var workMoments []mongoDB.WorkMoment
if req.UserID == req.OpUserID {
workMoments, err = db.DB.GetUserSelfWorkMoments(req.UserID, req.Pagination.ShowNumber, req.Pagination.PageNumber)
} else {

@ -23,7 +23,7 @@ type GroupCache struct {
func NewGroupCache(rdb redis.UniversalClient, db *mysql.Group, opts rockscache.Options) *GroupCache {
rcClient := &rockscache.Client{
Options: opts,
Options: rockscache.Options{},
}
redisClient := NewRedisClient(rdb)
return &GroupCache{rcClient: rcClient, expireTime: GroupExpireTime, db: db, redisClient: redisClient}

@ -608,7 +608,7 @@ func DelConversationFromCache(ctx context.Context, ownerUserID, conversationID s
return utils.Wrap(db.DB.Rc.TagAsDeleted(conversationCache+ownerUserID+":"+conversationID), "DelConversationFromCache err")
}
func GetExtendMsg(ctx context.Context, sourceID string, sessionType int32, clientMsgID string, firstModifyTime int64) (extendMsg *mongo.ExtendMsg, err error) {
func GetExtendMsg(ctx context.Context, sourceID string, sessionType int32, clientMsgID string, firstModifyTime int64) (extendMsg *mongoDB.ExtendMsg, err error) {
getExtendMsg := func() (string, error) {
extendMsg, err := db.DB.GetExtendMsg(sourceID, sessionType, clientMsgID, firstModifyTime)
if err != nil {
@ -628,7 +628,7 @@ func GetExtendMsg(ctx context.Context, sourceID string, sessionType int32, clien
if err != nil {
return nil, utils.Wrap(err, "Fetch failed")
}
extendMsg = &mongo.ExtendMsg{}
extendMsg = &mongoDB.ExtendMsg{}
err = json.Unmarshal([]byte(extendMsgStr), extendMsg)
return extendMsg, utils.Wrap(err, "Unmarshal failed")
}

@ -2,13 +2,13 @@ package model
import (
"Open_IM/pkg/common/db/cache"
"Open_IM/pkg/common/db/mongo"
"Open_IM/pkg/common/db/mongoDB"
"Open_IM/pkg/common/db/mysql"
"Open_IM/pkg/common/trace_log"
"Open_IM/pkg/utils"
"context"
"encoding/json"
"github.com/dtm-labs/rockscache"
"github.com/go-redis/redis/v8"
"go.mongodb.org/mongo-driver/mongo"
"gorm.io/gorm"
//"time"
)
@ -16,17 +16,17 @@ import (
type GroupModel struct {
db *mysql.Group
cache *cache.GroupCache
mongo *mongo.Client
mongo *mongoDB.Client
}
func NewGroupModel() *GroupModel {
func NewGroupModel(db *mysql.Group, rdb redis.UniversalClient, mdb *mongo.Client) *GroupModel {
var groupModel GroupModel
groupModel.db = mysql.NewGroupDB()
groupModel.cache = cache.NewGroupCache(cache.InitRedis(), groupModel.db, rockscache.Options{
groupModel.db = db
groupModel.cache = cache.NewGroupCache(rdb, db, rockscache.Options{
DisableCacheRead: false,
StrongConsistency: true,
})
groupModel.mongo = mongo.NewMongoClient()
groupModel.mongo = mongoDB.NewMongoClient(mdb)
return &groupModel
}

@ -1,4 +1,4 @@
package mongo
package mongoDB
import (
"Open_IM/pkg/common/config"

@ -1,4 +1,4 @@
package mongo
package mongoDB
import (
"Open_IM/pkg/common/config"

@ -1,4 +1,4 @@
package mongo
package mongoDB
import (
"Open_IM/pkg/common/config"
@ -17,10 +17,8 @@ type Client struct {
mongo *mongo.Client
}
func NewMongoClient() *Client {
var client Client
client.mongo = initMongo()
return &client
func NewMongoClient(mdb *mongo.Client) *Client {
return &Client{mongo: mdb}
}
func initMongo() *mongo.Client {

@ -1,4 +1,4 @@
package mongo
package mongoDB
import (
"Open_IM/pkg/common/config"
Loading…
Cancel
Save