feed: subscribe to pow events
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/pr/woodpecker Pipeline was successful Details

if difficulty-filter is set the subscription of the global feed
can filter only ids with 0-prefix to save bandwidth.

as there may not be many pow events within the last 24h, the
date range is now only enabled if there is no diffculty-filter
set so that the feed is not empty.

if this works as expected it could also only subscripe to
reactions and profile info with pow ids.
OFF0 1 year ago
parent 24acabb192
commit b4bb503bdd
Signed by: offbyn
GPG Key ID: 94A2F643C51F37FA

@ -3,10 +3,10 @@ import {zeroLeadingBitsCount} from './utils/crypto';
import {elem} from './utils/dom';
import {bounce} from './utils/time';
import {isWssUrl} from './utils/url';
import {closeSettingsView, config, toggleSettingsView} from './settings';
import {sub24hFeed, subNote, subProfile} from './subscriptions'
import {getReplyTo, hasEventTag, isMention, sortByCreatedAt, sortEventCreatedAt} from './events';
import {clearView, getViewContent, getViewElem, getViewOptions, setViewElem, view} from './view';
import {closeSettingsView, config, toggleSettingsView} from './settings';
import {handleReaction, handleUpvote} from './reactions';
import {closePublishView, openWriteInput, togglePublishView} from './write';
import {handleMetadata, renderProfile} from './profiles';

@ -1,5 +1,6 @@
import {Event} from 'nostr-tools';
import {getReplyTo, hasEventTag, isMention} from './events';
import {config} from './settings';
import {sub, subOnce, unsubAll} from './relays';
type SubCallback = (
@ -13,6 +14,7 @@ export const sub24hFeed = (onEvent: SubCallback) => {
const now = Math.floor(Date.now() * 0.001);
const pubkeys = new Set<string>();
const notes = new Set<string>();
const prefix = Math.floor(config.filterDifficulty * 0.25);
sub({ // get past events
cb: (evt, relay) => {
pubkeys.add(evt.pubkey);
@ -20,9 +22,10 @@ export const sub24hFeed = (onEvent: SubCallback) => {
onEvent(evt, relay);
},
filter: {
...(prefix && {ids: ['0'.repeat(prefix)]}),
kinds: [1],
until: now,
since: Math.floor(now - (24 * 60 * 60)),
...(!prefix && {since: Math.floor(now - (24 * 60 * 60))}),
limit: 100,
},
unsub: true

Loading…
Cancel
Save