Skip to content

Commit

Permalink
fix: SearchLocalMessages no such table (#737)
Browse files Browse the repository at this point in the history
* feat: code adjustment

* feat: Cmd2Value carry caller

* feat: Cmd2Value carry caller

* feat: Cmd2Value carry caller

* feat: Cmd2Value carry caller

* fix: SearchLocalMessages no such table
  • Loading branch information
withchao authored Oct 14, 2024
1 parent 0e75df9 commit 1dcc7a7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
4 changes: 2 additions & 2 deletions internal/conversation_msg/conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions test/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
)

const (
PlatformID = constant.LinuxPlatformID
Secret = "openIM123"
PlatformID = constant.LinuxPlatformID
Secret = "openIM123"
AdminUserID = "imAdmin"
)
9 changes: 8 additions & 1 deletion test/conversation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
27 changes: 19 additions & 8 deletions test/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<<<<<<<<<<<<<<<<<<------------------------")
Expand All @@ -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)
}
Expand All @@ -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)
}

0 comments on commit 1dcc7a7

Please sign in to comment.