From 9789f8cf94457e55483fcc88b4e0838d8c9427d7 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 19 Oct 2020 12:46:55 +0100 Subject: [PATCH] Spec compliance, /search doesn't have to return results Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/Searching.js | 8 ++++---- src/components/structures/RoomView.tsx | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Searching.js b/src/Searching.js index b1507e6a49..f65b8920b3 100644 --- a/src/Searching.js +++ b/src/Searching.js @@ -360,7 +360,7 @@ function combineEvents(previousSearchResult, localEvents = undefined, serverEven let oldestEventFrom = previousSearchResult.oldestEventFrom; response.highlights = previousSearchResult.highlights; - if (localEvents && serverEvents) { + if (localEvents && serverEvents && serverEvents.results) { // 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. @@ -379,7 +379,7 @@ function combineEvents(previousSearchResult, localEvents = undefined, serverEven oldestEventFrom = "local"; } combineEventSources(previousSearchResult, response, localEvents.results, cachedEvents); - } else if (serverEvents) { + } 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. // Change the source of the oldest event if our server event is older @@ -454,7 +454,7 @@ function combineResponses(previousSearchResult, localEvents = undefined, serverE return response; } -function restoreEncryptionInfo(searchResultSlice) { +function restoreEncryptionInfo(searchResultSlice = []) { for (let i = 0; i < searchResultSlice.length; i++) { const timeline = searchResultSlice[i].context.getTimeline(); @@ -517,7 +517,7 @@ async function combinedPagination(searchResult) { }, }; - const oldResultCount = searchResult.results.length; + const oldResultCount = searchResult.results ? searchResult.results.length : 0; // Let the client process the combined result. const result = client._processRoomEventsSearch(searchResult, response); diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index 2952568e2f..0226cecf15 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -1258,7 +1258,7 @@ export default class RoomView extends React.Component { } if (!this.state.searchResults.next_batch) { - if (this.state.searchResults.results.length == 0) { + if (!this.state.searchResults?.results?.length) { ret.push(
  • { _t("No results") }

  • , @@ -1282,7 +1282,7 @@ export default class RoomView extends React.Component { let lastRoomId; - for (let i = this.state.searchResults.results.length - 1; i >= 0; i--) { + for (let i = (this.state.searchResults?.results?.length || 0) - 1; i >= 0; i--) { const result = this.state.searchResults.results[i]; const mxEv = result.context.getEvent(); @@ -1944,7 +1944,7 @@ export default class RoomView extends React.Component { if (this.state.searchResults) { // show searching spinner - if (this.state.searchResults.results === undefined) { + if (this.state.searchResults.count === undefined) { searchResultsPanel = (
    );