From 7e42ffb150c24cafbce76af556880aa6b32a1cb8 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 6 Jun 2024 21:22:37 +0100 Subject: [PATCH] Fix incorrect assumptions about required fields in /search response (#12575) Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/Searching.ts | 12 ++++++------ src/components/structures/RoomSearchView.tsx | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Searching.ts b/src/Searching.ts index 691600d591..ce3ea96c72 100644 --- a/src/Searching.ts +++ b/src/Searching.ts @@ -248,7 +248,7 @@ async function localPagination( // 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 newResultCount = localResult.results?.length ?? 0; const response = { search_categories: { @@ -419,21 +419,21 @@ function combineEvents( // This is a first search call, combine the events from the server and // the local index. Note where our oldest event came from, we shall // fetch the next batch of events from the other source. - if (compareOldestEvents(localEvents.results, serverEvents.results) < 0) { + if (compareOldestEvents(localEvents.results ?? [], serverEvents.results) < 0) { oldestEventFrom = "local"; } - combineEventSources(previousSearchResult, response, localEvents.results, serverEvents.results); - response.highlights = localEvents.highlights.concat(serverEvents.highlights); + combineEventSources(previousSearchResult, response, localEvents.results ?? [], serverEvents.results); + response.highlights = (localEvents.highlights ?? []).concat(serverEvents.highlights ?? []); } else if (localEvents) { // This is a pagination call fetching more events from the local index, // meaning that our oldest event was on the server. // Change the source of the oldest event if our local event is older // than the cached one. - if (compareOldestEvents(localEvents.results, cachedEvents) < 0) { + if (compareOldestEvents(localEvents.results ?? [], cachedEvents) < 0) { oldestEventFrom = "local"; } - combineEventSources(previousSearchResult, response, localEvents.results, cachedEvents); + combineEventSources(previousSearchResult, response, localEvents.results ?? [], cachedEvents); } else if (serverEvents && serverEvents.results) { // This is a pagination call fetching more events from the server, // meaning that our oldest event was in the local index. diff --git a/src/components/structures/RoomSearchView.tsx b/src/components/structures/RoomSearchView.tsx index bfa993059b..aedf2cea39 100644 --- a/src/components/structures/RoomSearchView.tsx +++ b/src/components/structures/RoomSearchView.tsx @@ -159,7 +159,7 @@ export const RoomSearchView = forwardRef( }, []); // eslint-disable-line react-hooks/exhaustive-deps // show searching spinner - if (results?.count === undefined) { + if (results === null) { return (