Apply muffle to replies

This commit is contained in:
Jonathan Staab 2023-02-24 09:22:39 -06:00
parent 040e8955de
commit 7c9223a37f
9 changed files with 50 additions and 17 deletions

View File

@ -1,7 +1,6 @@
# Current # Current
- [ ] Fix pagination - [ ] Fix pagination
- [ ] Relays get marked as slow too easily now
# Next # Next
@ -23,6 +22,7 @@
# More # More
- [ ] Add new DM button to dms list
- [ ] Add suggested relays based on follows or topics - [ ] Add suggested relays based on follows or topics
- [ ] Combine alerts/messages and any other top-level subscriptions to avoid sub limit - [ ] Combine alerts/messages and any other top-level subscriptions to avoid sub limit
- [ ] Clean up person detail actions, maybe click one circle and show the rest - [ ] Clean up person detail actions, maybe click one circle and show the rest

View File

@ -31,7 +31,7 @@ class Connection {
this.status = 'new' this.status = 'new'
this.stats = { this.stats = {
timeouts: 0, timeouts: 0,
subCount: 0, subsCount: 0,
eoseCount: 0, eoseCount: 0,
eoseTimer: 0, eoseTimer: 0,
eventsCount: 0, eventsCount: 0,
@ -87,8 +87,8 @@ class Connection {
return [0, "Failed to connect"] return [0, "Failed to connect"]
} }
const {timeouts, subCount, eoseTimer, eoseCount} = this.stats const {timeouts, subsCount, eoseTimer, eoseCount} = this.stats
const timeoutRate = timeouts > 0 ? timeouts / subCount : null const timeoutRate = timeouts > 0 ? timeouts / subsCount : null
const eoseQuality = eoseCount > 0 ? Math.max(1, 500 / (eoseTimer / eoseCount)) : null const eoseQuality = eoseCount > 0 ? Math.max(1, 500 / (eoseTimer / eoseCount)) : null
if (timeoutRate && timeoutRate > 0.5) { if (timeoutRate && timeoutRate > 0.5) {

View File

@ -1,7 +1,8 @@
import type {Person} from 'src/util/types' import type {Person} from 'src/util/types'
import type {Readable} from 'svelte/store' import type {Readable} from 'svelte/store'
import {prop, find, pipe, assoc, whereEq, when, concat, reject, nth, map} from 'ramda' import {last, prop, find, pipe, assoc, whereEq, when, concat, reject, nth, map} from 'ramda'
import {synced} from 'src/util/misc' import {synced} from 'src/util/misc'
import {Tags} from 'src/util/nostr'
import {derived} from 'svelte/store' import {derived} from 'svelte/store'
import database from 'src/agent/database' import database from 'src/agent/database'
import keys from 'src/agent/keys' import keys from 'src/agent/keys'
@ -90,6 +91,34 @@ const user = {
canPublish, canPublish,
getProfile: () => profileCopy, getProfile: () => profileCopy,
getPubkey: () => profileCopy?.pubkey, getPubkey: () => profileCopy?.pubkey,
muffle: events => {
const muffle = user.getMuffle()
return events.filter(e => !muffle.has(e.pubkey))
},
getMuffle: () => {
return new Set(
Tags
.wrap((profileCopy?.muffle || []))
.filter(t => Math.random() > parseFloat(last(t)))
.values()
.all()
)
},
mute: events => {
const mutes = user.getMutes()
return events.filter(e => !mutes.has(e.pubkey))
},
getMutes: () => {
return new Set(
Tags
.wrap((profileCopy?.muffle || []))
.filter(t => parseFloat(last(t)) === 0)
.values()
.all()
)
},
// Petnames // Petnames

View File

@ -99,6 +99,10 @@ export const publishWithToast = (relays, thunk) =>
extra.push(`${timeouts.size} timed out`) extra.push(`${timeouts.size} timed out`)
} }
if (pending.size > 0) {
extra.push(`${pending.size} pending`)
}
if (extra.length > 0) { if (extra.length > 0) {
message += ` (${extra.join(', ')})` message += ` (${extra.join(', ')})`
} }

View File

@ -34,6 +34,9 @@ export class Tags {
values() { values() {
return new Tags(this.tags.map(t => t[1])) return new Tags(this.tags.map(t => t[1]))
} }
filter(f) {
return new Tags(this.tags.filter(f))
}
type(type) { type(type) {
return new Tags(this.tags.filter(t => t[0] === type)) return new Tags(this.tags.filter(t => t[0] === type))
} }

View File

@ -11,6 +11,7 @@
import ImageCircle from "src/partials/ImageCircle.svelte" import ImageCircle from "src/partials/ImageCircle.svelte"
import Alert from 'src/views/alerts/Alert.svelte' import Alert from 'src/views/alerts/Alert.svelte'
import database from 'src/agent/database' import database from 'src/agent/database'
import user from 'src/agent/user'
import {lastChecked} from 'src/app/alerts' import {lastChecked} from 'src/app/alerts'
import {modal, routes} from 'src/app/ui' import {modal, routes} from 'src/app/ui'
@ -25,7 +26,7 @@
// Filter out alerts for which we failed to find the required context. The bug // Filter out alerts for which we failed to find the required context. The bug
// is really upstream of this, but it's an easy fix // is really upstream of this, but it's an easy fix
const events = database.alerts.all() const events = user.mute(database.alerts.all())
.filter(e => e.replies.length > 0 || e.likedBy.length > 0 || e.isMention) .filter(e => e.replies.length > 0 || e.likedBy.length > 0 || e.isMention)
notes = sortBy(e => -e.created_at, events).slice(0, limit) notes = sortBy(e => -e.created_at, events).slice(0, limit)

View File

@ -1,10 +1,10 @@
<script lang="ts"> <script lang="ts">
import {onMount} from 'svelte' import {onMount} from 'svelte'
import {partition, last, propEq, uniqBy, sortBy, prop} from 'ramda' import {partition, propEq, uniqBy, sortBy, prop} from 'ramda'
import {slide} from 'svelte/transition' import {slide} from 'svelte/transition'
import {quantify} from 'hurdak/lib/hurdak' import {quantify} from 'hurdak/lib/hurdak'
import {createScroller, now, Cursor} from 'src/util/misc' import {createScroller, now, Cursor} from 'src/util/misc'
import {asDisplayEvent, Tags} from 'src/util/nostr' import {asDisplayEvent} from 'src/util/nostr'
import Spinner from 'src/partials/Spinner.svelte' import Spinner from 'src/partials/Spinner.svelte'
import Content from 'src/partials/Content.svelte' import Content from 'src/partials/Content.svelte'
import Note from "src/views/notes/Note.svelte" import Note from "src/views/notes/Note.svelte"
@ -22,14 +22,9 @@
const since = now() const since = now()
const maxNotes = 100 const maxNotes = 100
const cursor = new Cursor() const cursor = new Cursor()
const {profile} = user
const muffle = Tags
.wrap(($profile?.muffle || []).filter(t => Math.random() > parseFloat(last(t))))
.values().all()
const processNewNotes = async newNotes => { const processNewNotes = async newNotes => {
// Remove people we're not interested in hearing about, sort by created date newNotes = user.muffle(newNotes)
newNotes = newNotes.filter(e => !muffle.includes(e.pubkey))
// Load parents before showing the notes so we have hierarchy. Give it a short // Load parents before showing the notes so we have hierarchy. Give it a short
// timeout, since this is really just a nice-to-have // timeout, since this is really just a nice-to-have
@ -46,7 +41,7 @@
depth: 2, depth: 2,
notes: combined, notes: combined,
onChunk: context => { onChunk: context => {
notes = network.applyContext(notes, context) notes = network.applyContext(notes, user.muffle(context))
}, },
}) })

View File

@ -8,6 +8,7 @@
import Content from 'src/partials/Content.svelte' import Content from 'src/partials/Content.svelte'
import Spinner from 'src/partials/Spinner.svelte' import Spinner from 'src/partials/Spinner.svelte'
import Note from 'src/views/notes/Note.svelte' import Note from 'src/views/notes/Note.svelte'
import user from 'src/agent/user'
import network from 'src/agent/network' import network from 'src/agent/network'
import {sampleRelays} from 'src/agent/relays' import {sampleRelays} from 'src/agent/relays'
@ -38,7 +39,7 @@
depth: 6, depth: 6,
notes: [note], notes: [note],
onChunk: context => { onChunk: context => {
note = first(network.applyContext([note], context)) note = first(network.applyContext([note], user.muffle(context)))
}, },
}) })
} }

View File

@ -12,7 +12,7 @@
<div in:fly={{y: 20}}> <div in:fly={{y: 20}}>
<Content> <Content>
<div class="flex justify-between mt-10"> <div class="flex justify-between">
<div class="flex gap-2 items-center"> <div class="flex gap-2 items-center">
<i class="fa fa-server fa-lg" /> <i class="fa fa-server fa-lg" />
<h2 class="staatliches text-2xl">Your relays</h2> <h2 class="staatliches text-2xl">Your relays</h2>