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
- [ ] Fix pagination
- [ ] Relays get marked as slow too easily now
# Next
@ -23,6 +22,7 @@
# More
- [ ] Add new DM button to dms list
- [ ] Add suggested relays based on follows or topics
- [ ] 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

View File

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

View File

@ -1,7 +1,8 @@
import type {Person} from 'src/util/types'
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 {Tags} from 'src/util/nostr'
import {derived} from 'svelte/store'
import database from 'src/agent/database'
import keys from 'src/agent/keys'
@ -90,6 +91,34 @@ const user = {
canPublish,
getProfile: () => profileCopy,
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

View File

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

View File

@ -34,6 +34,9 @@ export class Tags {
values() {
return new Tags(this.tags.map(t => t[1]))
}
filter(f) {
return new Tags(this.tags.filter(f))
}
type(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 Alert from 'src/views/alerts/Alert.svelte'
import database from 'src/agent/database'
import user from 'src/agent/user'
import {lastChecked} from 'src/app/alerts'
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
// 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)
notes = sortBy(e => -e.created_at, events).slice(0, limit)

View File

@ -1,10 +1,10 @@
<script lang="ts">
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 {quantify} from 'hurdak/lib/hurdak'
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 Content from 'src/partials/Content.svelte'
import Note from "src/views/notes/Note.svelte"
@ -22,14 +22,9 @@
const since = now()
const maxNotes = 100
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 => {
// Remove people we're not interested in hearing about, sort by created date
newNotes = newNotes.filter(e => !muffle.includes(e.pubkey))
newNotes = user.muffle(newNotes)
// Load parents before showing the notes so we have hierarchy. Give it a short
// timeout, since this is really just a nice-to-have
@ -46,7 +41,7 @@
depth: 2,
notes: combined,
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 Spinner from 'src/partials/Spinner.svelte'
import Note from 'src/views/notes/Note.svelte'
import user from 'src/agent/user'
import network from 'src/agent/network'
import {sampleRelays} from 'src/agent/relays'
@ -38,7 +39,7 @@
depth: 6,
notes: [note],
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}}>
<Content>
<div class="flex justify-between mt-10">
<div class="flex justify-between">
<div class="flex gap-2 items-center">
<i class="fa fa-server fa-lg" />
<h2 class="staatliches text-2xl">Your relays</h2>