From 1dcc7a714c53ee107dc458bc87f307613c9f1ac8 Mon Sep 17 00:00:00 2001 From: chao <48119764+withchao@users.noreply.github.com> Date: Mon, 14 Oct 2024 16:24:33 +0800 Subject: [PATCH] fix: SearchLocalMessages no such table (#737) * feat: code adjustment * feat: Cmd2Value carry caller * feat: Cmd2Value carry caller * feat: Cmd2Value carry caller * feat: Cmd2Value carry caller * fix: SearchLocalMessages no such table --- internal/conversation_msg/conversation.go | 4 ++-- test/config.go | 5 +++-- test/conversation_test.go | 9 +++++++- test/init.go | 27 ++++++++++++++++------- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/internal/conversation_msg/conversation.go b/internal/conversation_msg/conversation.go index 25dffaaef..b514b46b9 100644 --- a/internal/conversation_msg/conversation.go +++ b/internal/conversation_msg/conversation.go @@ -423,8 +423,8 @@ func (c *Conversation) searchMessageByContentTypeAndKeyword(ctx context.Context, g.Go(func() error { sList, err := c.db.SearchMessageByContentTypeAndKeyword(ctx, contentType, conversationID, keywordList, keywordListMatchType, startTime, endTime) if err != nil { - // TODO: log.Error(operationID, "search message in group err", err.Error(), conversationID) - return err + log.ZWarn(ctx, "search conversation message", err, "conversationID", conversationID) + return nil } mu.Lock() diff --git a/test/config.go b/test/config.go index 1ce8650c3..fb0a3c7a3 100644 --- a/test/config.go +++ b/test/config.go @@ -23,6 +23,7 @@ const ( ) const ( - PlatformID = constant.LinuxPlatformID - Secret = "openIM123" + PlatformID = constant.LinuxPlatformID + Secret = "openIM123" + AdminUserID = "imAdmin" ) diff --git a/test/conversation_test.go b/test/conversation_test.go index f50abb706..f188403d3 100644 --- a/test/conversation_test.go +++ b/test/conversation_test.go @@ -165,7 +165,14 @@ func Test_InsertGroupMessageToLocalStorage(t *testing.T) { } func Test_SearchLocalMessages(t *testing.T) { - msgs, err := open_im_sdk.UserForSDK.Conversation().SearchLocalMessages(ctx, &sdk_params_callback.SearchLocalMessagesParams{}) + req := &sdk_params_callback.SearchLocalMessagesParams{ + Count: 20, + KeywordList: []string{"1"}, + MessageTypeList: []int{105}, + PageIndex: 1, + SenderUserIDList: []string{}, + } + msgs, err := open_im_sdk.UserForSDK.Conversation().SearchLocalMessages(ctx, req) if err != nil { t.Fatal(err) } diff --git a/test/init.go b/test/init.go index e931ed3a7..657206f33 100644 --- a/test/init.go +++ b/test/init.go @@ -30,9 +30,7 @@ import ( "github.com/openimsdk/openim-sdk-core/v3/pkg/ccontext" ) -var ( - ctx context.Context -) +var ctx context.Context func init() { fmt.Println("------------------------>>>>>>>>>>>>>>>>>>> test init func <<<<<<<<<<<<<<<<<<<------------------------") @@ -50,7 +48,7 @@ func init() { } ctx = open_im_sdk.UserForSDK.Context() ctx = ccontext.WithOperationID(ctx, "initOperationID_"+strconv.Itoa(int(time.Now().UnixMilli()))) - token, err := GetAdminToken(ctx, UserID, Secret) + token, err := GetUserToken(ctx, UserID, PlatformID, Secret, config) if err != nil { panic(err) } @@ -77,10 +75,23 @@ func getConf(APIADDR, WSADDR string) sdk_struct.IMConfig { return cf } -func GetAdminToken(ctx context.Context, userID string, secret string) (string, error) { - req := &auth.GetAdminTokenReq{ - UserID: userID, +func GetUserToken(ctx context.Context, userID string, platformID int32, secret string, imConf sdk_struct.IMConfig) (string, error) { + adminReq := &auth.GetAdminTokenReq{ + UserID: AdminUserID, Secret: secret, } - return api.ExtractField(ctx, api.GetAdminToken.Invoke, req, (*auth.GetAdminTokenResp).GetToken) + adminToken, err := api.ExtractField(ctx, api.GetAdminToken.Invoke, adminReq, (*auth.GetAdminTokenResp).GetToken) + if err != nil { + return "", err + } + userReq := &auth.GetUserTokenReq{ + UserID: userID, + PlatformID: platformID, + } + ctx = ccontext.WithInfo(ctx, &ccontext.GlobalConfig{ + UserID: userID, + Token: adminToken, + IMConfig: imConf, + }) + return api.ExtractField(ctx, api.GetUsersToken.Invoke, userReq, (*auth.GetUserTokenResp).GetToken) }