mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-12-17 22:47:59 +01:00
32 lines
1.1 KiB
TypeScript
32 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;
|
|
}
|
|
};
|
|
}
|