mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-12-05 00:57:59 +01:00
3590be1429
* match_query: unit test and rewrite for TypeScript * match_query: use new type for parse errors * match_query: avoid exceptional control flow in date parsing
25 lines
1.1 KiB
TypeScript
25 lines
1.1 KiB
TypeScript
import { Interaction, InteractionType, InteractionValue } from '../../types/booru-object';
|
|
import { FieldMatcher } from './types';
|
|
|
|
function interactionMatch(imageId: number, type: InteractionType, value: InteractionValue, interactions: Interaction[]): boolean {
|
|
return interactions.some(v => v.image_id === imageId && v.interaction_type === type && (value === null || v.value === value));
|
|
}
|
|
|
|
export function makeUserMatcher(term: string): FieldMatcher {
|
|
// Should work with most my:conditions except watched.
|
|
return (value, field, documentId) => {
|
|
switch (term) {
|
|
case 'faves':
|
|
return interactionMatch(documentId, 'faved', null, window.booru.interactions);
|
|
case 'upvotes':
|
|
return interactionMatch(documentId, 'voted', 'up', window.booru.interactions);
|
|
case 'downvotes':
|
|
return interactionMatch(documentId, 'voted', 'down', window.booru.interactions);
|
|
case 'watched':
|
|
case 'hidden':
|
|
default:
|
|
// Other my: interactions aren't supported, return false to prevent them from triggering spoiler.
|
|
return false;
|
|
}
|
|
};
|
|
}
|