2023-08-24 20:28:13 +00:00
|
|
|
import { type Event, matchFilters } from '@/deps.ts';
|
|
|
|
|
2023-08-24 22:00:08 +00:00
|
|
|
import type { DittoFilter, EventData } from '@/types.ts';
|
2023-08-24 20:28:13 +00:00
|
|
|
|
|
|
|
function matchDittoFilter(filter: DittoFilter, event: Event, data: EventData): boolean {
|
2023-08-24 22:00:08 +00:00
|
|
|
if (filter.local && !data.user) {
|
2023-08-24 20:28:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return matchFilters([filter], event);
|
|
|
|
}
|
|
|
|
|
2023-08-24 22:00:08 +00:00
|
|
|
/**
|
|
|
|
* Similar to nostr-tools `matchFilters`, but supports Ditto's custom keys.
|
|
|
|
* Database calls are needed to look up the extra data, so it's passed in as an argument.
|
|
|
|
*/
|
2023-08-24 20:28:13 +00:00
|
|
|
function matchDittoFilters(filters: DittoFilter[], event: Event, data: EventData): boolean {
|
|
|
|
for (const filter of filters) {
|
|
|
|
if (matchDittoFilter(filter, event, data)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
export { matchDittoFilters };
|