Spec compliance, /search doesn't have to return results

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
pull/21833/head
Michael Telatynski 2020-10-19 12:46:55 +01:00
parent b10f7a47fd
commit 9789f8cf94
2 changed files with 7 additions and 7 deletions

View File

@ -360,7 +360,7 @@ function combineEvents(previousSearchResult, localEvents = undefined, serverEven
let oldestEventFrom = previousSearchResult.oldestEventFrom; let oldestEventFrom = previousSearchResult.oldestEventFrom;
response.highlights = previousSearchResult.highlights; 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 // 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.
@ -379,7 +379,7 @@ function combineEvents(previousSearchResult, localEvents = undefined, serverEven
oldestEventFrom = "local"; oldestEventFrom = "local";
} }
combineEventSources(previousSearchResult, response, localEvents.results, cachedEvents); 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, // 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.
// Change the source of the oldest event if our server event is older // 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; return response;
} }
function restoreEncryptionInfo(searchResultSlice) { function restoreEncryptionInfo(searchResultSlice = []) {
for (let i = 0; i < searchResultSlice.length; i++) { for (let i = 0; i < searchResultSlice.length; i++) {
const timeline = searchResultSlice[i].context.getTimeline(); 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. // Let the client process the combined result.
const result = client._processRoomEventsSearch(searchResult, response); const result = client._processRoomEventsSearch(searchResult, response);

View File

@ -1258,7 +1258,7 @@ export default class RoomView extends React.Component<IProps, IState> {
} }
if (!this.state.searchResults.next_batch) { if (!this.state.searchResults.next_batch) {
if (this.state.searchResults.results.length == 0) { if (!this.state.searchResults?.results?.length) {
ret.push(<li key="search-top-marker"> ret.push(<li key="search-top-marker">
<h2 className="mx_RoomView_topMarker">{ _t("No results") }</h2> <h2 className="mx_RoomView_topMarker">{ _t("No results") }</h2>
</li>, </li>,
@ -1282,7 +1282,7 @@ export default class RoomView extends React.Component<IProps, IState> {
let lastRoomId; 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 result = this.state.searchResults.results[i];
const mxEv = result.context.getEvent(); const mxEv = result.context.getEvent();
@ -1944,7 +1944,7 @@ export default class RoomView extends React.Component<IProps, IState> {
if (this.state.searchResults) { if (this.state.searchResults) {
// show searching spinner // show searching spinner
if (this.state.searchResults.results === undefined) { if (this.state.searchResults.count === undefined) {
searchResultsPanel = ( searchResultsPanel = (
<div className="mx_RoomView_messagePanel mx_RoomView_messagePanelSearchSpinner" /> <div className="mx_RoomView_messagePanel mx_RoomView_messagePanelSearchSpinner" />
); );