mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 05:25:40 +09:00
30 lines
926 B
TypeScript
30 lines
926 B
TypeScript
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
import type {MessageSearchScope} from '@app/features/search/utils/SearchUtils';
|
|
|
|
interface ResolveSearchScopeParams {
|
|
activeScope?: MessageSearchScope | null;
|
|
fallbackScope: MessageSearchScope;
|
|
parsedScope?: MessageSearchScope;
|
|
scopeOverride?: MessageSearchScope | null;
|
|
scopeOptionValues: ReadonlySet<MessageSearchScope>;
|
|
}
|
|
|
|
export const resolveSearchScope = ({
|
|
activeScope,
|
|
fallbackScope,
|
|
parsedScope,
|
|
scopeOverride,
|
|
scopeOptionValues,
|
|
}: ResolveSearchScopeParams): MessageSearchScope => {
|
|
const requestedScope = scopeOverride ?? undefined;
|
|
if (requestedScope && scopeOptionValues.has(requestedScope)) {
|
|
return requestedScope;
|
|
}
|
|
if (!requestedScope && parsedScope && scopeOptionValues.has(parsedScope)) {
|
|
return parsedScope;
|
|
}
|
|
const currentScope = activeScope ?? fallbackScope;
|
|
return scopeOptionValues.has(currentScope) ? currentScope : fallbackScope;
|
|
};
|