diff --git a/internal/conversation_msg/conversation.go b/internal/conversation_msg/conversation.go index 330d77af4..d5f9732a7 100644 --- a/internal/conversation_msg/conversation.go +++ b/internal/conversation_msg/conversation.go @@ -405,6 +405,9 @@ func (c *Conversation) searchLocalMessages(ctx context.Context, searchParam *sdk log.ZError(ctx, "Parsing data error:", err, "msg", temp) continue } + if c.filterMsg(&temp, searchParam) { + continue + } if temp.ContentType == constant.File && !c.judgeMultipleSubString(searchParam.KeywordList, temp.FileElem.FileName, searchParam.KeywordListMatchType) { continue } @@ -441,6 +444,7 @@ func (c *Conversation) searchLocalMessages(ctx context.Context, searchParam *sdk searchResultItem.ConversationID = conversationID searchResultItem.FaceURL = localConversation.FaceURL searchResultItem.ShowName = localConversation.ShowName + searchResultItem.LatestMsgSendTime = localConversation.LatestMsgSendTime searchResultItem.ConversationType = localConversation.ConversationType searchResultItem.MessageList = append(searchResultItem.MessageList, &temp) searchResultItem.MessageCount++ @@ -456,8 +460,49 @@ func (c *Conversation) searchLocalMessages(ctx context.Context, searchParam *sdk r.TotalCount += v.MessageCount } + sort.Slice(r.SearchResultItems, func(i, j int) bool { + return r.SearchResultItems[i].LatestMsgSendTime > r.SearchResultItems[j].LatestMsgSendTime + }) return &r, nil } +func (c *Conversation) filterMsg(temp *sdk_struct.MsgStruct, searchParam *sdk.SearchLocalMessagesParams) bool { + switch temp.ContentType { + case constant.Text: + return !c.judgeMultipleSubString(searchParam.KeywordList, temp.TextElem.Content, + searchParam.KeywordListMatchType) + case constant.AtText: + return !c.judgeMultipleSubString(searchParam.KeywordList, temp.AtTextElem.Text, + searchParam.KeywordListMatchType) + case constant.File: + return !c.judgeMultipleSubString(searchParam.KeywordList, temp.FileElem.FileName, + searchParam.KeywordListMatchType) + case constant.Merger: + if !c.judgeMultipleSubString(searchParam.KeywordList, temp.MergeElem.Title, searchParam.KeywordListMatchType) { + for _, msgStruct := range temp.MergeElem.MultiMessage { + if c.filterMsg(msgStruct, searchParam) { + continue + } else { + break + } + } + + } + case constant.Card: + return !c.judgeMultipleSubString(searchParam.KeywordList, temp.CardElem.Nickname, + searchParam.KeywordListMatchType) + case constant.Location: + return !c.judgeMultipleSubString(searchParam.KeywordList, temp.LocationElem.Description, + searchParam.KeywordListMatchType) + case constant.Custom: + return !c.judgeMultipleSubString(searchParam.KeywordList, temp.CustomElem.Description, + searchParam.KeywordListMatchType) + case constant.Quote: + if !c.judgeMultipleSubString(searchParam.KeywordList, temp.QuoteElem.Text, searchParam.KeywordListMatchType) { + return c.filterMsg(temp.QuoteElem.QuoteMessage, searchParam) + } + } + return false +} func (c *Conversation) delMsgBySeq(seqList []uint32) error { var SPLIT = 1000 diff --git a/internal/conversation_msg/sdk.go b/internal/conversation_msg/sdk.go index 3cf4c0f52..dc739195f 100644 --- a/internal/conversation_msg/sdk.go +++ b/internal/conversation_msg/sdk.go @@ -1114,7 +1114,6 @@ func (c *Conversation) InsertGroupMessageToLocalStorage(ctx context.Context, s * } func (c *Conversation) SearchLocalMessages(ctx context.Context, searchParam *sdk_params_callback.SearchLocalMessagesParams) (*sdk_params_callback.SearchLocalMessagesCallback, error) { - searchParam.KeywordList = utils.TrimStringList(searchParam.KeywordList) return c.searchLocalMessages(ctx, searchParam) diff --git a/pkg/sdk_params_callback/conversation_msg_sdk_struct.go b/pkg/sdk_params_callback/conversation_msg_sdk_struct.go index e6980eb21..bf8a53999 100644 --- a/pkg/sdk_params_callback/conversation_msg_sdk_struct.go +++ b/pkg/sdk_params_callback/conversation_msg_sdk_struct.go @@ -70,12 +70,13 @@ type SearchLocalMessagesCallback struct { SearchResultItems []*SearchByConversationResult `json:"searchResultItems"` } type SearchByConversationResult struct { - ConversationID string `json:"conversationID"` - ConversationType int32 `json:"conversationType"` - ShowName string `json:"showName"` - FaceURL string `json:"faceURL"` - MessageCount int `json:"messageCount"` - MessageList []*sdk_struct.MsgStruct `json:"messageList"` + ConversationID string `json:"conversationID"` + ConversationType int32 `json:"conversationType"` + ShowName string `json:"showName"` + FaceURL string `json:"faceURL"` + LatestMsgSendTime int64 `json:"latestMsgSendTime,omitempty"` + MessageCount int `json:"messageCount"` + MessageList []*sdk_struct.MsgStruct `json:"messageList"` } type SetMessageReactionExtensionsParams []*server_api_params.KeyValue