Skip to content

Commit

Permalink
fix: search message sort and bug fix. (#410)
Browse files Browse the repository at this point in the history
Signed-off-by: Gordon <[email protected]>
  • Loading branch information
FGadvancer authored Nov 17, 2023
1 parent c62ef72 commit 2c938ac
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
45 changes: 45 additions & 0 deletions internal/conversation_msg/conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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++
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion internal/conversation_msg/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 7 additions & 6 deletions pkg/sdk_params_callback/conversation_msg_sdk_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2c938ac

Please sign in to comment.