From a0934329fec605d67da635b2f2797d6b074d4829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 10 Jun 2020 15:41:55 +0200 Subject: [PATCH] Searching: Restore the encryption state for the paginated results. --- src/Searching.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Searching.js b/src/Searching.js index 6c31a5ca1a..b1507e6a49 100644 --- a/src/Searching.js +++ b/src/Searching.js @@ -133,6 +133,9 @@ async function combinedSearch(searchTerm) { const result = client._processRoomEventsSearch(emptyResult, response); + // Restore our encryption info so we can properly re-verify the events. + restoreEncryptionInfo(result.results); + return result; } @@ -197,6 +200,10 @@ async function localPagination(searchResult) { const localResult = await eventIndex.search(searchArgs); searchResult.seshatQuery.next_batch = localResult.next_batch; + // We only need to restore the encryption state for the new results, so + // remember how many of them we got. + const newResultCount = localResult.results.length; + const response = { search_categories: { room_events: localResult, @@ -204,6 +211,11 @@ async function localPagination(searchResult) { }; const result = MatrixClientPeg.get()._processRoomEventsSearch(searchResult, response); + + // Restore our encryption info so we can properly re-verify the events. + const newSlice = result.results.slice(Math.max(result.results.length - newResultCount, 0)); + restoreEncryptionInfo(newSlice); + searchResult.pendingRequest = null; return result; @@ -505,12 +517,17 @@ async function combinedPagination(searchResult) { }, }; + const oldResultCount = searchResult.results.length; + // Let the client process the combined result. const result = client._processRoomEventsSearch(searchResult, response); - searchResult.pendingRequest = null; - // Restore our encryption info so we can properly re-verify the events. + const newResultCount = result.results.length - oldResultCount; + const newSlice = result.results.slice(Math.max(result.results.length - newResultCount, 0)); + restoreEncryptionInfo(newSlice); + + searchResult.pendingRequest = null; return result; }