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

This commit is contained in:
wangchuxiao 2023-05-26 16:22:08 +08:00
commit 753c0d9803
4 changed files with 70 additions and 56 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
unRelationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" unRelationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
@ -16,6 +17,7 @@ import (
) )
func (m *msgServer) RevokeMsg(ctx context.Context, req *msg.RevokeMsgReq) (*msg.RevokeMsgResp, error) { func (m *msgServer) RevokeMsg(ctx context.Context, req *msg.RevokeMsgReq) (*msg.RevokeMsgResp, error) {
defer log.ZInfo(ctx, "RevokeMsg return line")
if req.UserID == "" { if req.UserID == "" {
return nil, errs.ErrArgs.Wrap("user_id is empty") return nil, errs.ErrArgs.Wrap("user_id is empty")
} }

View File

@ -84,7 +84,7 @@ const (
ConversationPrivateChatNotification = 1701 ConversationPrivateChatNotification = 1701
ConversationUnreadNotification = 1702 ConversationUnreadNotification = 1702
MsgRevokeNotification = 1750 MsgRevokeNotification = 2101
BusinessNotificationBegin = 2000 BusinessNotificationBegin = 2000
BusinessNotification = 2001 BusinessNotification = 2001

View File

@ -247,6 +247,9 @@ func (db *commonMsgDatabase) BatchInsertBlock(ctx context.Context, conversationI
} }
func (db *commonMsgDatabase) BatchInsertChat2DB(ctx context.Context, conversationID string, msgList []*sdkws.MsgData, currentMaxSeq int64) error { func (db *commonMsgDatabase) BatchInsertChat2DB(ctx context.Context, conversationID string, msgList []*sdkws.MsgData, currentMaxSeq int64) error {
if len(msgList) == 0 {
return errs.ErrArgs.Wrap("msgList is empty")
}
msgs := make([]any, len(msgList)) msgs := make([]any, len(msgList))
for i, msg := range msgList { for i, msg := range msgList {
if msg == nil { if msg == nil {
@ -286,7 +289,18 @@ func (db *commonMsgDatabase) BatchInsertChat2DB(ctx context.Context, conversatio
Ex: msg.Ex, Ex: msg.Ex,
} }
} }
return db.BatchInsertBlock(ctx, conversationID, msgs, updateKeyMsg, currentMaxSeq-int64(len(msgList))) return db.BatchInsertBlock(ctx, conversationID, msgs, updateKeyMsg, msgList[0].Seq)
}
func (db *commonMsgDatabase) MarkUserDeleteMsg(ctx context.Context, conversationID string, seq int64, userIDs []string) error {
if len(userIDs) == 0 {
return nil
}
msgs := make([]any, len(userIDs))
for i, userID := range userIDs {
msgs[i] = userID
}
return db.BatchInsertBlock(ctx, conversationID, msgs, updateKeyDel, seq)
} }
func (db *commonMsgDatabase) RevokeMsg(ctx context.Context, conversationID string, seq int64, revoke *unRelationTb.RevokeModel) error { func (db *commonMsgDatabase) RevokeMsg(ctx context.Context, conversationID string, seq int64, revoke *unRelationTb.RevokeModel) error {

View File

@ -153,16 +153,18 @@ func GetDB() *commonMsgDatabase {
func Test_Insert(t *testing.T) { func Test_Insert(t *testing.T) {
db := GetDB() db := GetDB()
ctx := context.Background() ctx := context.Background()
var arr []*unRelationTb.MsgInfoModel var arr []any
for i := 0; i < 345; i++ { for i := 0; i < 345; i++ {
arr = append(arr, &unRelationTb.MsgInfoModel{ if i%2 == 0 {
Msg: &unRelationTb.MsgDataModel{ arr = append(arr, (*unRelationTb.MsgDataModel)(nil))
Seq: int64(i), continue
Content: fmt.Sprintf("test-%d", i), }
}, arr = append(arr, &unRelationTb.MsgDataModel{
Seq: int64(i),
Content: fmt.Sprintf("test-%d", i),
}) })
} }
if err := db.BatchInsertBlock(ctx, "test", arr, 0); err != nil { if err := db.BatchInsertBlock(ctx, "test", arr, updateKeyMsg, 0); err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
@ -170,17 +172,15 @@ func Test_Insert(t *testing.T) {
func Test_Revoke(t *testing.T) { func Test_Revoke(t *testing.T) {
db := GetDB() db := GetDB()
ctx := context.Background() ctx := context.Background()
var arr []*unRelationTb.MsgInfoModel var arr []any
for i := 0; i < 456; i++ { for i := 0; i < 456; i++ {
arr = append(arr, &unRelationTb.MsgInfoModel{ arr = append(arr, &unRelationTb.RevokeModel{
Revoke: &unRelationTb.RevokeModel{ UserID: "uid_" + strconv.Itoa(i),
UserID: "uid_" + strconv.Itoa(i), Nickname: "uname_" + strconv.Itoa(i),
Nickname: "uname_" + strconv.Itoa(i), Time: time.Now().UnixMilli(),
Time: time.Now().UnixMilli(),
},
}) })
} }
if err := db.BatchInsertBlock(ctx, "test", arr, 123); err != nil { if err := db.BatchInsertBlock(ctx, "test", arr, updateKeyRevoke, 123); err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
@ -188,48 +188,46 @@ func Test_Revoke(t *testing.T) {
func Test_Delete(t *testing.T) { func Test_Delete(t *testing.T) {
db := GetDB() db := GetDB()
ctx := context.Background() ctx := context.Background()
var arr []*unRelationTb.MsgInfoModel var arr []any
for i := 0; i < 123; i++ { for i := 0; i < 123; i++ {
arr = append(arr, &unRelationTb.MsgInfoModel{ arr = append(arr, []string{"uid_1", "uid_2"})
DelList: []string{"uid_1", "uid_2"},
})
} }
if err := db.BatchInsertBlock(ctx, "test", arr, 210); err != nil { if err := db.BatchInsertBlock(ctx, "test", arr, updateKeyDel, 210); err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
func Test_Delete1(t *testing.T) { //func Test_Delete1(t *testing.T) {
config.Config.Mongo.DBAddress = []string{"192.168.44.128:37017"} // config.Config.Mongo.DBAddress = []string{"192.168.44.128:37017"}
config.Config.Mongo.DBTimeout = 60 // config.Config.Mongo.DBTimeout = 60
config.Config.Mongo.DBDatabase = "openIM" // config.Config.Mongo.DBDatabase = "openIM"
config.Config.Mongo.DBSource = "admin" // config.Config.Mongo.DBSource = "admin"
config.Config.Mongo.DBUserName = "root" // config.Config.Mongo.DBUserName = "root"
config.Config.Mongo.DBPassword = "openIM123" // config.Config.Mongo.DBPassword = "openIM123"
config.Config.Mongo.DBMaxPoolSize = 100 // config.Config.Mongo.DBMaxPoolSize = 100
config.Config.Mongo.DBRetainChatRecords = 3650 // config.Config.Mongo.DBRetainChatRecords = 3650
config.Config.Mongo.ChatRecordsClearTime = "0 2 * * 3" // config.Config.Mongo.ChatRecordsClearTime = "0 2 * * 3"
//
mongo, err := unrelation.NewMongo() // mongo, err := unrelation.NewMongo()
if err != nil { // if err != nil {
panic(err) // panic(err)
} // }
err = mongo.GetDatabase().Client().Ping(context.Background(), nil) // err = mongo.GetDatabase().Client().Ping(context.Background(), nil)
if err != nil { // if err != nil {
panic(err) // panic(err)
} // }
//
c := mongo.GetClient().Database("openIM").Collection("msg") // c := mongo.GetClient().Database("openIM").Collection("msg")
//
var o unRelationTb.MsgDocModel // var o unRelationTb.MsgDocModel
//
err = c.FindOne(context.Background(), bson.M{"doc_id": "test:0"}).Decode(&o) // err = c.FindOne(context.Background(), bson.M{"doc_id": "test:0"}).Decode(&o)
if err != nil { // if err != nil {
panic(err) // panic(err)
} // }
//
for i, model := range o.Msg { // for i, model := range o.Msg {
fmt.Println(i, model == nil) // fmt.Println(i, model == nil)
} // }
//
} //}