feat: follow and mute

This commit is contained in:
Shusui MOYATANI
2023-04-21 23:42:41 +09:00
parent 748e12df7b
commit 02d9969945
14 changed files with 440 additions and 154 deletions

View File

@@ -1,4 +1,4 @@
import { createSignal, createEffect, onCleanup } from 'solid-js';
import { createSignal, createEffect, onCleanup, on } from 'solid-js';
import type { Event as NostrEvent, Filter, SubscriptionOptions } from 'nostr-tools';
import uniqBy from 'lodash/uniqBy';
import usePool from '@/nostr/usePool';
@@ -35,10 +35,20 @@ setInterval(() => {
}, 1000);
const useSubscription = (propsProvider: () => UseSubscriptionProps | null) => {
const { config } = useConfig();
const { config, shouldMuteEvent } = useConfig();
const pool = usePool();
const [events, setEvents] = createSignal<NostrEvent[]>([]);
createEffect(
on(
() => [config().mutedPubkeys, config().mutedKeywords],
() => {
setEvents((currentEvents) => currentEvents.filter((event) => !shouldMuteEvent(event)));
},
{ defer: true },
),
);
const startSubscription = () => {
const props = propsProvider();
if (props == null) return;
@@ -58,7 +68,7 @@ const useSubscription = (propsProvider: () => UseSubscriptionProps | null) => {
if (onEvent != null) {
onEvent(event as NostrEvent & { id: string });
}
if (config().mutedPubkeys.includes(event.pubkey)) {
if (shouldMuteEvent(event)) {
return;
}
if (props.clientEventFilter != null && !props.clientEventFilter(event)) {