Skip to content

Commit

Permalink
filter out muted npubs from events returned from reqs
Browse files Browse the repository at this point in the history
  • Loading branch information
mleku committed Nov 29, 2024
1 parent 7d8d6d0 commit 5106d76
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
35 changes: 33 additions & 2 deletions realy/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"sort"
"time"

"realy.lol/kinds"
"realy.lol/units"

"github.com/dgraph-io/badger/v4"
Expand Down Expand Up @@ -592,7 +593,7 @@ func (s *Server) doReq(c Ctx, ws *web.Socket, req B, sto store.I) (r B) {
}
}
}
var events []*event.T
var events event.Ts
log.D.F("query from %s %0x,%s", ws.RealRemote(), ws.AuthedBytes(), f.Serialize())
if events, err = sto.QueryEvents(c, f); err != nil {
log.E.F("eventstore: %v", err)
Expand All @@ -601,7 +602,37 @@ func (s *Server) doReq(c Ctx, ws *web.Socket, req B, sto store.I) (r B) {
}
continue
}

// filter out events from authors in the user's mute list, because they are literally a
// waste of bandwidth from a user's perspective
if aut := ws.Authed(); ws.IsAuthed() {
var mutes event.Ts
if mutes, err = sto.QueryEvents(c, &filter.T{Authors: tag.New(aut),
Kinds: kinds.New(kind.MuteList)}); !chk.E(err) {
// found the users mute list, now, generate the list so we can filter on it
var mutePubs []B
for _, ev := range mutes {
for _, t := range ev.Tags.F() {
if equals(t.Key(), B("p")) {
var p B
if p, err = hex.Dec(S(t.Value())); chk.E(err) {
continue
}
mutePubs = append(mutePubs, p)
}
}
}
var tmp event.Ts
for _, ev := range events {
for _, pk := range mutePubs {
if equals(ev.PubKey, pk) {
continue
}
tmp = append(tmp, ev)
}
}
events = tmp
}
}
// sort in reverse chronological order
sort.Slice(events, func(i, j int) bool {
return events[i].CreatedAt.Int() > events[j].CreatedAt.Int()
Expand Down
2 changes: 1 addition & 1 deletion realy/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.2.24
v1.2.25

0 comments on commit 5106d76

Please sign in to comment.