From 9dbc39869074f3b394ae6ceda5dff64a74358255 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Thu, 27 Jul 2023 10:45:01 -0700 Subject: [PATCH] Add RowIndex field to search results for more efficient UI searching --- event/common.go | 1 + peer/cwtch_peer.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/event/common.go b/event/common.go index 83fd20d..ca9984c 100644 --- a/event/common.go +++ b/event/common.go @@ -276,6 +276,7 @@ const ( EventID = Field("EventID") EventContext = Field("EventContext") Index = Field("Index") + RowIndex = Field("RowIndex") ContentHash = Field("ContentHash") // Handle denotes a contact handle of any type. diff --git a/peer/cwtch_peer.go b/peer/cwtch_peer.go index 13b6b41..46c7e3d 100644 --- a/peer/cwtch_peer.go +++ b/peer/cwtch_peer.go @@ -844,7 +844,8 @@ func (cp *cwtchPeer) doSearch(ctx context.Context, searchID string, pattern stri } for _, matchingMessage := range matchingMessages { // publish this search result... - cp.PublishEvent(event.NewEvent(event.SearchResult, map[event.Field]string{event.SearchID: searchID, event.ConversationID: strconv.Itoa(conversation.ID), event.Index: strconv.Itoa(matchingMessage.ID)})) + index, _ := cp.storage.GetRowNumberByMessageID(conversation.ID, 0, matchingMessage.ID) + cp.PublishEvent(event.NewEvent(event.SearchResult, map[event.Field]string{event.SearchID: searchID, event.RowIndex: strconv.Itoa(index), event.ConversationID: strconv.Itoa(conversation.ID), event.Index: strconv.Itoa(matchingMessage.ID)})) log.Debugf("found matching message: %q", matchingMessage) } }