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

Commit 5caad82

Browse files
authored
Merge pull request #5337 from matrix-org/t3chguy/fix/15484
Spec compliance, /search doesn't have to return results
2 parents 7752f92 + 9789f8c commit 5caad82

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/Searching.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ function combineEvents(previousSearchResult, localEvents = undefined, serverEven
360360
let oldestEventFrom = previousSearchResult.oldestEventFrom;
361361
response.highlights = previousSearchResult.highlights;
362362

363-
if (localEvents && serverEvents) {
363+
if (localEvents && serverEvents && serverEvents.results) {
364364
// This is a first search call, combine the events from the server and
365365
// the local index. Note where our oldest event came from, we shall
366366
// fetch the next batch of events from the other source.
@@ -379,7 +379,7 @@ function combineEvents(previousSearchResult, localEvents = undefined, serverEven
379379
oldestEventFrom = "local";
380380
}
381381
combineEventSources(previousSearchResult, response, localEvents.results, cachedEvents);
382-
} else if (serverEvents) {
382+
} else if (serverEvents && serverEvents.results) {
383383
// This is a pagination call fetching more events from the server,
384384
// meaning that our oldest event was in the local index.
385385
// Change the source of the oldest event if our server event is older
@@ -454,7 +454,7 @@ function combineResponses(previousSearchResult, localEvents = undefined, serverE
454454
return response;
455455
}
456456

457-
function restoreEncryptionInfo(searchResultSlice) {
457+
function restoreEncryptionInfo(searchResultSlice = []) {
458458
for (let i = 0; i < searchResultSlice.length; i++) {
459459
const timeline = searchResultSlice[i].context.getTimeline();
460460

@@ -517,7 +517,7 @@ async function combinedPagination(searchResult) {
517517
},
518518
};
519519

520-
const oldResultCount = searchResult.results.length;
520+
const oldResultCount = searchResult.results ? searchResult.results.length : 0;
521521

522522
// Let the client process the combined result.
523523
const result = client._processRoomEventsSearch(searchResult, response);

src/components/structures/RoomView.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ export default class RoomView extends React.Component<IProps, IState> {
12581258
}
12591259

12601260
if (!this.state.searchResults.next_batch) {
1261-
if (this.state.searchResults.results.length == 0) {
1261+
if (!this.state.searchResults?.results?.length) {
12621262
ret.push(<li key="search-top-marker">
12631263
<h2 className="mx_RoomView_topMarker">{ _t("No results") }</h2>
12641264
</li>,
@@ -1282,7 +1282,7 @@ export default class RoomView extends React.Component<IProps, IState> {
12821282

12831283
let lastRoomId;
12841284

1285-
for (let i = this.state.searchResults.results.length - 1; i >= 0; i--) {
1285+
for (let i = (this.state.searchResults?.results?.length || 0) - 1; i >= 0; i--) {
12861286
const result = this.state.searchResults.results[i];
12871287

12881288
const mxEv = result.context.getEvent();
@@ -1944,7 +1944,7 @@ export default class RoomView extends React.Component<IProps, IState> {
19441944

19451945
if (this.state.searchResults) {
19461946
// show searching spinner
1947-
if (this.state.searchResults.results === undefined) {
1947+
if (this.state.searchResults.count === undefined) {
19481948
searchResultsPanel = (
19491949
<div className="mx_RoomView_messagePanel mx_RoomView_messagePanelSearchSpinner" />
19501950
);

0 commit comments

Comments
 (0)