Fix incorrect assumptions about required fields in /search response (#12575)

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
pull/28217/head
Michael Telatynski 2024-06-06 21:22:37 +01:00 committed by GitHub
parent ceafad32f9
commit 7e42ffb150
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 7 deletions

View File

@ -248,7 +248,7 @@ async function localPagination(
// We only need to restore the encryption state for the new results, so // We only need to restore the encryption state for the new results, so
// remember how many of them we got. // remember how many of them we got.
const newResultCount = localResult.results.length; const newResultCount = localResult.results?.length ?? 0;
const response = { const response = {
search_categories: { search_categories: {
@ -419,21 +419,21 @@ function combineEvents(
// This is a first search call, combine the events from the server and // 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 // the local index. Note where our oldest event came from, we shall
// fetch the next batch of events from the other source. // 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"; oldestEventFrom = "local";
} }
combineEventSources(previousSearchResult, response, localEvents.results, serverEvents.results); combineEventSources(previousSearchResult, response, localEvents.results ?? [], serverEvents.results);
response.highlights = localEvents.highlights.concat(serverEvents.highlights); response.highlights = (localEvents.highlights ?? []).concat(serverEvents.highlights ?? []);
} else if (localEvents) { } else if (localEvents) {
// This is a pagination call fetching more events from the local index, // This is a pagination call fetching more events from the local index,
// meaning that our oldest event was on the server. // meaning that our oldest event was on the server.
// Change the source of the oldest event if our local event is older // Change the source of the oldest event if our local event is older
// than the cached one. // than the cached one.
if (compareOldestEvents(localEvents.results, cachedEvents) < 0) { if (compareOldestEvents(localEvents.results ?? [], cachedEvents) < 0) {
oldestEventFrom = "local"; oldestEventFrom = "local";
} }
combineEventSources(previousSearchResult, response, localEvents.results, cachedEvents); combineEventSources(previousSearchResult, response, localEvents.results ?? [], cachedEvents);
} else if (serverEvents && serverEvents.results) { } else if (serverEvents && serverEvents.results) {
// This is a pagination call fetching more events from the server, // This is a pagination call fetching more events from the server,
// meaning that our oldest event was in the local index. // meaning that our oldest event was in the local index.

View File

@ -159,7 +159,7 @@ export const RoomSearchView = forwardRef<ScrollPanel, Props>(
}, []); // eslint-disable-line react-hooks/exhaustive-deps }, []); // eslint-disable-line react-hooks/exhaustive-deps
// show searching spinner // show searching spinner
if (results?.count === undefined) { if (results === null) {
return ( return (
<div <div
className="mx_RoomView_messagePanel mx_RoomView_messagePanelSearchSpinner" className="mx_RoomView_messagePanel mx_RoomView_messagePanelSearchSpinner"