comply with strict and strictNullChecks (#11161)

This commit is contained in:
alunturner 2023-06-29 11:20:24 +01:00 committed by GitHub
parent 879832a4eb
commit ce479c5774
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -29,6 +29,7 @@ import { MatrixClient } from "matrix-js-sdk/src/matrix";
import { ISearchArgs } from "./indexing/BaseEventIndexManager"; import { ISearchArgs } from "./indexing/BaseEventIndexManager";
import EventIndexPeg from "./indexing/EventIndexPeg"; import EventIndexPeg from "./indexing/EventIndexPeg";
import { isNotUndefined } from "./Typeguards";
const SEARCH_LIMIT = 10; const SEARCH_LIMIT = 10;
@ -468,8 +469,8 @@ function combineEvents(
*/ */
function combineResponses( function combineResponses(
previousSearchResult: ISeshatSearchResults, previousSearchResult: ISeshatSearchResults,
localEvents: IResultRoomEvents, localEvents?: IResultRoomEvents,
serverEvents: IResultRoomEvents, serverEvents?: IResultRoomEvents,
): IResultRoomEvents { ): IResultRoomEvents {
// Combine our events first. // Combine our events first.
const response = combineEvents(previousSearchResult, localEvents, serverEvents); const response = combineEvents(previousSearchResult, localEvents, serverEvents);
@ -480,11 +481,14 @@ function combineResponses(
if (previousSearchResult.count) { if (previousSearchResult.count) {
response.count = previousSearchResult.count; response.count = previousSearchResult.count;
} else { } else {
response.count = localEvents.count + serverEvents.count; const localEventCount = localEvents?.count ?? 0;
const serverEventCount = serverEvents?.count ?? 0;
response.count = localEventCount + serverEventCount;
} }
// Update our next batch tokens for the given search sources. // Update our next batch tokens for the given search sources.
if (localEvents) { if (localEvents && isNotUndefined(previousSearchResult.seshatQuery)) {
previousSearchResult.seshatQuery.next_batch = localEvents.next_batch; previousSearchResult.seshatQuery.next_batch = localEvents.next_batch;
} }
if (serverEvents) { if (serverEvents) {
@ -505,7 +509,11 @@ function combineResponses(
// pagination request. // pagination request.
// //
// Provide a fake next batch token for that case. // Provide a fake next batch token for that case.
if (!response.next_batch && previousSearchResult.cachedEvents.length > 0) { if (
!response.next_batch &&
isNotUndefined(previousSearchResult.cachedEvents) &&
previousSearchResult.cachedEvents.length > 0
) {
response.next_batch = "cached"; response.next_batch = "cached";
} }
@ -565,16 +573,12 @@ async function combinedPagination(
// Fetch events from the server if we have a token for it and if it's the // Fetch events from the server if we have a token for it and if it's the
// local indexes turn or the local index has exhausted its results. // local indexes turn or the local index has exhausted its results.
if (searchResult.serverSideNextBatch && (oldestEventFrom === "local" || !searchArgs.next_batch)) { if (searchResult.serverSideNextBatch && (oldestEventFrom === "local" || !searchArgs?.next_batch)) {
const body = { body: searchResult._query!, next_batch: searchResult.serverSideNextBatch }; const body = { body: searchResult._query!, next_batch: searchResult.serverSideNextBatch };
serverSideResult = await client.search(body); serverSideResult = await client.search(body);
} }
let serverEvents: IResultRoomEvents | undefined; const serverEvents: IResultRoomEvents | undefined = serverSideResult?.search_categories.room_events;
if (serverSideResult) {
serverEvents = serverSideResult.search_categories.room_events;
}
// Combine our events. // Combine our events.
const combinedResult = combineResponses(searchResult, localResult, serverEvents); const combinedResult = combineResponses(searchResult, localResult, serverEvents);