all repos — honk @ 3cd37d058cfd4b51c0d8fc470faabba9af050458

my fork of honk

more precise filter matching
Ted Unangst tedu@tedunangst.com
Sun, 24 Nov 2019 23:20:33 -0500
commit

3cd37d058cfd4b51c0d8fc470faabba9af050458

parent

cf308cb62a501e99906693c55137ba31ab9a3197

1 files changed, 25 insertions(+), 11 deletions(-)

jump to
M hfcs.gohfcs.go

@@ -214,21 +214,29 @@ return false

} func matchfilter(h *Honk, f *Filter) bool { + return matchfilterX(h, f) != "" +} + +func matchfilterX(h *Honk, f *Filter) string { + rv := "" match := true if match && f.Actor != "" { match = false if f.Actor == h.Honker || f.Actor == h.Oonker { match = true + rv = f.Actor } if !match && (f.Actor == originate(h.Honker) || f.Actor == originate(h.Oonker) || f.Actor == originate(h.XID)) { match = true + rv = f.Actor } if !match && f.IncludeAudience { for _, a := range h.Audience { if f.Actor == a || f.Actor == originate(a) { match = true + rv = f.Actor break } }

@@ -239,23 +247,33 @@ match = false

if (f.AnnounceOf == "" && h.Oonker != "") || f.AnnounceOf == h.Oonker || f.AnnounceOf == originate(h.Oonker) { match = true + rv += " announce" } } if match && f.Text != "" { match = false re := f.re_text - if re.MatchString(h.Noise) || re.MatchString(h.Precis) { - match = true + m := re.FindString(h.Precis) + if m == "" { + m = re.FindString(h.Noise) } - if !match { + if m == "" { for _, d := range h.Donks { - if re.MatchString(d.Desc) { - match = true + m = re.FindString(d.Desc) + if m != "" { + break } } } + if m != "" { + match = true + rv = m + } } - return match + if match { + return rv + } + return "" } func rejectxonk(xonk *Honk) bool {

@@ -282,11 +300,7 @@

func unsee(userid int64, h *Honk) { filts := getfilters(userid, filtCollapse) for _, f := range filts { - if matchfilter(h, f) { - bad := f.Text - if f.Actor != "" { - bad = f.Actor - } + if bad := matchfilterX(h, f); bad != "" { if h.Precis == "" { h.Precis = bad }