diff --git a/src/app/TopNav.svelte b/src/app/TopNav.svelte index a53a0ac8..07952cf6 100644 --- a/src/app/TopNav.svelte +++ b/src/app/TopNav.svelte @@ -129,7 +129,7 @@ type: "profile", text: "@" + - [profile?.name, handle?.address, profile?.display_name].filter(identity).join(" "), + [profile?.name, profile?.display_name, handle?.address].filter(identity).join(" "), } }) ) @@ -153,7 +153,7 @@ } } - $: search = fuzzy(options, {keys: ["text"], threshold: 0.3}) + $: search = fuzzy(options, {keys: ["text"], threshold: 0.5}) onMount(() => { document.querySelector("html").addEventListener("click", e => { diff --git a/src/app/shared/Note.svelte b/src/app/shared/Note.svelte index 65f55462..5b538236 100644 --- a/src/app/shared/Note.svelte +++ b/src/app/shared/Note.svelte @@ -142,7 +142,10 @@ replies = sortBy((e: Event) => -e.created_at, uniqBy(prop("id"), replies.concat(e))) } - context = uniqBy(prop("id"), (context || []).concat(e)) + context = sortBy( + (e: Event) => -e.created_at, + uniqBy(prop("id"), (context || []).concat(e)) + ) } }, "7": () => { diff --git a/src/app/shared/NoteContentQuote.svelte b/src/app/shared/NoteContentQuote.svelte index 1df9015e..315d1765 100644 --- a/src/app/shared/NoteContentQuote.svelte +++ b/src/app/shared/NoteContentQuote.svelte @@ -7,7 +7,14 @@ import Card from "src/partials/Card.svelte" import Spinner from "src/partials/Spinner.svelte" import PersonCircle from "src/app/shared/PersonCircle.svelte" - import {load, displayPubkey, isEventMuted, getEventHints, mergeHints} from "src/engine" + import { + load, + loadPubkeys, + displayPubkey, + isEventMuted, + getEventHints, + mergeHints, + } from "src/engine" export let note export let value @@ -39,6 +46,8 @@ loading = false muted = isEventMuted(event).get() quote = event + + loadPubkeys([quote.pubkey]) }, }) diff --git a/src/engine/queries/filter.ts b/src/engine/queries/filter.ts index 4a2d091e..69c85a54 100644 --- a/src/engine/queries/filter.ts +++ b/src/engine/queries/filter.ts @@ -11,7 +11,10 @@ export const matchFilter = (filter, event) => { } if (filter.search) { - return event.content.toLowerCase().includes(filter.search.toLowerCase()) + const content = event.content.toLowerCase() + const terms = filter.search.toLowerCase().split(/\s+/g) + + return any(s => content.includes(s), terms) } return true diff --git a/src/engine/requests/notifications.ts b/src/engine/requests/notifications.ts index 95d7312e..4203b49b 100644 --- a/src/engine/requests/notifications.ts +++ b/src/engine/requests/notifications.ts @@ -49,6 +49,8 @@ export const listenForNotifications = async () => { const pubkeys = Object.keys(sessions.get()) const channelIds = pluck("id", nip28ChannelsForUser.get()) + const relays = mergeHints(pubkeys.map(pk => getPubkeyHints(pk, "read"))) + const eventIds: string[] = doPipe(events.get(), [ filter((e: Event) => noteKinds.includes(e.kind)), sortBy((e: Event) => -e.created_at), @@ -56,20 +58,30 @@ export const listenForNotifications = async () => { pluck("id"), ]) + const filters = [ + // NIP04 Messages + {kinds: [4], "#p": pubkeys, limit: 1}, + // NIP24 Messages + {kinds: [1059], "#p": pubkeys, limit: 1}, + // Mentions + {kinds: noteKinds, "#p": pubkeys, limit: 1}, + ] + + // Chat + if (channelIds.length > 0) { + filters.push({kinds: [42], "#e": channelIds, limit: 1}) + } + + // Replies + if (eventIds.length > 0) { + filters.push({kinds: noteKinds, "#e": eventIds, limit: 1}) + } + // Only grab one event from each category/relay so we have enough to show // the notification badges, but load the details lazily subscribePersistent({ - relays: mergeHints(pubkeys.map(pk => getPubkeyHints(pk, "read"))), - filters: [ - // Messages - {kinds: [4], "#p": pubkeys, limit: 1}, - {kinds: [1059], "#p": pubkeys, limit: 1}, - // Chat - {kinds: [42], "#e": channelIds, limit: 1}, - // Mentions/replies - {kinds: noteKinds, "#p": pubkeys, limit: 1}, - {kinds: noteKinds, "#e": eventIds, limit: 1}, - ], + relays, + filters, onEvent: (e: Event) => { if (kinds.includes(e.kind) && !isEventMuted(e).get()) { events.key(e.id).set(e)