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

Commit ce479c5

Browse files
authored
comply with strict and strictNullChecks (#11161)
1 parent 879832a commit ce479c5

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/Searching.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { MatrixClient } from "matrix-js-sdk/src/matrix";
2929

3030
import { ISearchArgs } from "./indexing/BaseEventIndexManager";
3131
import EventIndexPeg from "./indexing/EventIndexPeg";
32+
import { isNotUndefined } from "./Typeguards";
3233

3334
const SEARCH_LIMIT = 10;
3435

@@ -468,8 +469,8 @@ function combineEvents(
468469
*/
469470
function combineResponses(
470471
previousSearchResult: ISeshatSearchResults,
471-
localEvents: IResultRoomEvents,
472-
serverEvents: IResultRoomEvents,
472+
localEvents?: IResultRoomEvents,
473+
serverEvents?: IResultRoomEvents,
473474
): IResultRoomEvents {
474475
// Combine our events first.
475476
const response = combineEvents(previousSearchResult, localEvents, serverEvents);
@@ -480,11 +481,14 @@ function combineResponses(
480481
if (previousSearchResult.count) {
481482
response.count = previousSearchResult.count;
482483
} else {
483-
response.count = localEvents.count + serverEvents.count;
484+
const localEventCount = localEvents?.count ?? 0;
485+
const serverEventCount = serverEvents?.count ?? 0;
486+
487+
response.count = localEventCount + serverEventCount;
484488
}
485489

486490
// Update our next batch tokens for the given search sources.
487-
if (localEvents) {
491+
if (localEvents && isNotUndefined(previousSearchResult.seshatQuery)) {
488492
previousSearchResult.seshatQuery.next_batch = localEvents.next_batch;
489493
}
490494
if (serverEvents) {
@@ -505,7 +509,11 @@ function combineResponses(
505509
// pagination request.
506510
//
507511
// Provide a fake next batch token for that case.
508-
if (!response.next_batch && previousSearchResult.cachedEvents.length > 0) {
512+
if (
513+
!response.next_batch &&
514+
isNotUndefined(previousSearchResult.cachedEvents) &&
515+
previousSearchResult.cachedEvents.length > 0
516+
) {
509517
response.next_batch = "cached";
510518
}
511519

@@ -565,16 +573,12 @@ async function combinedPagination(
565573

566574
// Fetch events from the server if we have a token for it and if it's the
567575
// local indexes turn or the local index has exhausted its results.
568-
if (searchResult.serverSideNextBatch && (oldestEventFrom === "local" || !searchArgs.next_batch)) {
576+
if (searchResult.serverSideNextBatch && (oldestEventFrom === "local" || !searchArgs?.next_batch)) {
569577
const body = { body: searchResult._query!, next_batch: searchResult.serverSideNextBatch };
570578
serverSideResult = await client.search(body);
571579
}
572580

573-
let serverEvents: IResultRoomEvents | undefined;
574-
575-
if (serverSideResult) {
576-
serverEvents = serverSideResult.search_categories.room_events;
577-
}
581+
const serverEvents: IResultRoomEvents | undefined = serverSideResult?.search_categories.room_events;
578582

579583
// Combine our events.
580584
const combinedResult = combineResponses(searchResult, localResult, serverEvents);

0 commit comments

Comments
 (0)