From 447fdab6545d72e17bf62494f3b865c2c3327ebc Mon Sep 17 00:00:00 2001 From: Jonathan Staab Date: Fri, 3 Mar 2023 10:11:09 -0600 Subject: [PATCH] Improve feed quality by separating kind 1 and 7 filters --- CHANGELOG.md | 5 +++++ ROADMAP.md | 4 +--- src/util/misc.ts | 4 ++-- src/util/nostr.ts | 7 +++++-- src/views/notes/Feed.svelte | 6 +++--- src/views/notes/Follows.svelte | 5 ++++- src/views/notes/Network.svelte | 5 ++++- 7 files changed, 24 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9545ec6..a946160a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 0.2.16 + +- [x] Add search by nip05 +- [x] Fix feed to show more variety + ## 0.2.15 - [x] Add zaps diff --git a/ROADMAP.md b/ROADMAP.md index 91aa2824..752897af 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -1,8 +1,6 @@ # Current -- [ ] Search by nip05 alias - - nevent1qqsdt4ux9c0zvd6hzpwnzznjsmd7a337mpxdspu9wd4fq8drvqejdmqpz3mhxue69uhhyetvv9ujuerpd46hxtnfduqs6amnwvaz7tmwdaejumr0dsffemjp -- [ ] Fix feeds +- [ ] Show image upload rather than plop url in - [ ] Hash pubkey so we can track usage by unique user - [ ] Try adding boxes/separation on feeds based on user feedback - [ ] Strip zero width spaces from compose diff --git a/src/util/misc.ts b/src/util/misc.ts index 55a51dde..e2e4c29b 100644 --- a/src/util/misc.ts +++ b/src/util/misc.ts @@ -150,7 +150,7 @@ export const getLastSync = (k, fallback = 0) => { export class Cursor { until: number limit: number - constructor(limit = 10) { + constructor(limit = 50) { this.until = now() this.limit = limit } @@ -170,7 +170,7 @@ export class Cursor { if (events.length > 1) { const timestamps = sortBy(identity, pluck('created_at', events)) const gaps = aperture(2, timestamps).map(([a, b]) => b - a) - const gap = quantile(gaps, 0.5) + const gap = quantile(gaps, 0.1) this.until -= Math.round(gap * events.length) } diff --git a/src/util/nostr.ts b/src/util/nostr.ts index 37875863..5c514808 100644 --- a/src/util/nostr.ts +++ b/src/util/nostr.ts @@ -1,5 +1,5 @@ import type {DisplayEvent} from 'src/util/types' -import {fromPairs, last, identity, objOf, prop, flatten, uniq} from 'ramda' +import {is, fromPairs, mergeLeft, last, identity, objOf, prop, flatten, uniq} from 'ramda' import {nip19} from 'nostr-tools' import {ensurePlural, ellipsize, first} from 'hurdak/lib/hurdak' @@ -80,7 +80,7 @@ export const displayPerson = p => { } } -export const isLike = content => ['', '+', '🤙', '👍', '❤️'].includes(content) +export const isLike = content => ['', '+', '🤙', '👍', '❤️', '😎', '🏅'].includes(content) export const isAlert = (e, pubkey) => { if (![1, 7, 9735].includes(e.kind)) { @@ -130,3 +130,6 @@ export const toHex = (data: string): string | null => { return null } } + +export const mergeFilter = (filter, extra) => + is(Array, filter) ? filter.map(mergeLeft(extra)) : {...filter, ...extra} diff --git a/src/views/notes/Feed.svelte b/src/views/notes/Feed.svelte index 27c91717..e212dc05 100644 --- a/src/views/notes/Feed.svelte +++ b/src/views/notes/Feed.svelte @@ -4,7 +4,7 @@ import {slide} from 'svelte/transition' import {quantify} from 'hurdak/lib/hurdak' import {createScroller, now, Cursor} from 'src/util/misc' - import {asDisplayEvent} from 'src/util/nostr' + import {asDisplayEvent, mergeFilter} from 'src/util/nostr' import Spinner from 'src/partials/Spinner.svelte' import Content from 'src/partials/Content.svelte' import Note from "src/views/notes/Note.svelte" @@ -78,14 +78,14 @@ } onMount(() => { - const sub = network.listen({relays, filter: {...filter, since}, onChunk}) + const sub = network.listen({relays, filter: mergeFilter(filter, {since}), onChunk}) const scroller = createScroller(() => { if ($modal) { return } - return network.load({relays, filter: {...filter, ...cursor.getFilter()}, onChunk}) + return network.load({relays, filter: mergeFilter(filter, cursor.getFilter()), onChunk}) }) return () => { diff --git a/src/views/notes/Follows.svelte b/src/views/notes/Follows.svelte index 929f0ae8..a74eb9d9 100644 --- a/src/views/notes/Follows.svelte +++ b/src/views/notes/Follows.svelte @@ -6,7 +6,10 @@ const authors = shuffle(getUserFollows()).slice(0, 256) const relays = sampleRelays(getAllPubkeyWriteRelays(authors)) - const filter = {kinds: [1, 7], authors} + + // Separate notes and reactions into two queries since otherwise reactions dominate, + // we never find their parents (or reactions are mostly to a few posts), and the feed sucks + const filter = [{kinds: [1], authors}, {kinds: [7], authors}] diff --git a/src/views/notes/Network.svelte b/src/views/notes/Network.svelte index 5f56a2c4..059bf9bc 100644 --- a/src/views/notes/Network.svelte +++ b/src/views/notes/Network.svelte @@ -8,7 +8,10 @@ // sending too many pubkeys. This will also result in some variety. const authors = shuffle(getUserNetwork()).slice(0, 256) const relays = sampleRelays(getAllPubkeyWriteRelays(authors)) - const filter = {kinds: [1, 7], authors} + + // Separate notes and reactions into two queries since otherwise reactions dominate, + // we never find their parents (or reactions are mostly to a few posts), and the feed sucks + const filter = [{kinds: [1], authors}, {kinds: [7], authors}]