more precise filter matching

This commit is contained in:
Ted Unangst 2019-11-24 23:20:33 -05:00
parent cad5dc4387
commit 9539ce5df6
1 changed files with 25 additions and 11 deletions

36
hfcs.go
View File

@ -214,21 +214,29 @@ func stealthmode(userid int64, r *http.Request) bool {
} }
func matchfilter(h *Honk, f *Filter) bool { func matchfilter(h *Honk, f *Filter) bool {
return matchfilterX(h, f) != ""
}
func matchfilterX(h *Honk, f *Filter) string {
rv := ""
match := true match := true
if match && f.Actor != "" { if match && f.Actor != "" {
match = false match = false
if f.Actor == h.Honker || f.Actor == h.Oonker { if f.Actor == h.Honker || f.Actor == h.Oonker {
match = true match = true
rv = f.Actor
} }
if !match && (f.Actor == originate(h.Honker) || if !match && (f.Actor == originate(h.Honker) ||
f.Actor == originate(h.Oonker) || f.Actor == originate(h.Oonker) ||
f.Actor == originate(h.XID)) { f.Actor == originate(h.XID)) {
match = true match = true
rv = f.Actor
} }
if !match && f.IncludeAudience { if !match && f.IncludeAudience {
for _, a := range h.Audience { for _, a := range h.Audience {
if f.Actor == a || f.Actor == originate(a) { if f.Actor == a || f.Actor == originate(a) {
match = true match = true
rv = f.Actor
break break
} }
} }
@ -239,23 +247,33 @@ func matchfilter(h *Honk, f *Filter) bool {
if (f.AnnounceOf == "" && h.Oonker != "") || f.AnnounceOf == h.Oonker || if (f.AnnounceOf == "" && h.Oonker != "") || f.AnnounceOf == h.Oonker ||
f.AnnounceOf == originate(h.Oonker) { f.AnnounceOf == originate(h.Oonker) {
match = true match = true
rv += " announce"
} }
} }
if match && f.Text != "" { if match && f.Text != "" {
match = false match = false
re := f.re_text re := f.re_text
if re.MatchString(h.Noise) || re.MatchString(h.Precis) { m := re.FindString(h.Precis)
match = true if m == "" {
m = re.FindString(h.Noise)
} }
if !match { if m == "" {
for _, d := range h.Donks { for _, d := range h.Donks {
if re.MatchString(d.Desc) { m = re.FindString(d.Desc)
match = true if m != "" {
break
} }
} }
} }
if m != "" {
match = true
rv = m
}
} }
return match if match {
return rv
}
return ""
} }
func rejectxonk(xonk *Honk) bool { func rejectxonk(xonk *Honk) bool {
@ -282,11 +300,7 @@ func skipMedia(xonk *Honk) bool {
func unsee(userid int64, h *Honk) { func unsee(userid int64, h *Honk) {
filts := getfilters(userid, filtCollapse) filts := getfilters(userid, filtCollapse)
for _, f := range filts { for _, f := range filts {
if matchfilter(h, f) { if bad := matchfilterX(h, f); bad != "" {
bad := f.Text
if f.Actor != "" {
bad = f.Actor
}
if h.Precis == "" { if h.Precis == "" {
h.Precis = bad h.Precis = bad
} }