Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Fix incorrect assumptions about required fields in /search response (#…
Browse files Browse the repository at this point in the history
…12575)

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
  • Loading branch information
t3chguy authored Jun 6, 2024
1 parent ceafad3 commit 7e42ffb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/Searching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/RoomSearchView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const RoomSearchView = forwardRef<ScrollPanel, Props>(
}, []); // eslint-disable-line react-hooks/exhaustive-deps

// show searching spinner
if (results?.count === undefined) {
if (results === null) {
return (
<div
className="mx_RoomView_messagePanel mx_RoomView_messagePanelSearchSpinner"
Expand Down

0 comments on commit 7e42ffb

Please sign in to comment.