mirror of https://github.com/vector-im/riot-web
Searching: Split out more logic that combines the events.
parent
b6198e0ab9
commit
c2e0e10553
|
@ -184,18 +184,9 @@ async function localPagination(searchResult) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function combineEvents(localEvents = undefined, serverEvents = undefined, cachedEvents = undefined) {
|
||||||
* Combine the local and server search results
|
|
||||||
*/
|
|
||||||
function combineResponses(previousSearchResult, localEvents = undefined, serverEvents = undefined) {
|
|
||||||
const response = {};
|
const response = {};
|
||||||
|
|
||||||
if (previousSearchResult.count) {
|
|
||||||
response.count = previousSearchResult.count;
|
|
||||||
} else {
|
|
||||||
response.count = localEvents.count + serverEvents.count;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (localEvents && serverEvents) {
|
if (localEvents && serverEvents) {
|
||||||
response.results = localEvents.results.concat(serverEvents.results).sort(compareEvents);
|
response.results = localEvents.results.concat(serverEvents.results).sort(compareEvents);
|
||||||
response.highlights = localEvents.highlights.concat(serverEvents.highlights);
|
response.highlights = localEvents.highlights.concat(serverEvents.highlights);
|
||||||
|
@ -207,6 +198,21 @@ function combineResponses(previousSearchResult, localEvents = undefined, serverE
|
||||||
response.highlights = serverEvents.highlights;
|
response.highlights = serverEvents.highlights;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combine the local and server search responses
|
||||||
|
*/
|
||||||
|
function combineResponses(previousSearchResult, localEvents = undefined, serverEvents = undefined) {
|
||||||
|
const response = combineEvents(localEvents, serverEvents);
|
||||||
|
|
||||||
|
if (previousSearchResult.count) {
|
||||||
|
response.count = previousSearchResult.count;
|
||||||
|
} else {
|
||||||
|
response.count = localEvents.count + serverEvents.count;
|
||||||
|
}
|
||||||
|
|
||||||
if (localEvents) {
|
if (localEvents) {
|
||||||
previousSearchResult.seshatQuery.next_batch = localEvents.next_batch;
|
previousSearchResult.seshatQuery.next_batch = localEvents.next_batch;
|
||||||
response.next_batch = localEvents.next_batch;
|
response.next_batch = localEvents.next_batch;
|
||||||
|
|
Loading…
Reference in New Issue