From eab34a6104936c910c472580f55110bdaec1c6ab Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Wed, 10 Jul 2019 17:39:41 -0400 Subject: [PATCH] zilence (collapse) posts matching regex --- docs/changelog.txt | 2 ++ docs/manual.txt | 2 ++ fun.go | 39 ++++++++++++++++++++++++++++----------- honk.go | 5 +++-- views/zonkers.html | 3 +++ 5 files changed, 38 insertions(+), 13 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 91c61fd..2942624 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -2,6 +2,8 @@ changelog -- next ++ Collapse posts based on custom regex match. + + Tonks are now honk backs. + Show both avatars for bonks. Other minor refinements to UI. diff --git a/docs/manual.txt b/docs/manual.txt index 622565c..13eb5b8 100644 --- a/docs/manual.txt +++ b/docs/manual.txt @@ -59,6 +59,8 @@ works poorly in a federated environment. It's more like please disregard. The zonkzone supports muting unwanted contacts. One may mute an actor (zonker), a domain (zomain), thread (zonvoy), or word (zord). +Posts can be collapsed, but not hidden, by specifying a zilence regex. + -- privacy Posted honks are public. The federated environment lacks robust privacy diff --git a/fun.go b/fun.go index 4d86f40..12091c6 100644 --- a/fun.go +++ b/fun.go @@ -33,6 +33,7 @@ import ( func reverbolate(userid int64, honks []*Honk) { filt := htfilter.New() + zilences := getzilences(userid) for _, h := range honks { h.What += "ed" if h.What == "tonked" { @@ -62,13 +63,11 @@ func reverbolate(userid int64, honks []*Honk) { zap := make(map[*Donk]bool) h.Noise = unpucker(h.Noise) h.Open = "open" - if userid != -1 { - if badword := unsee(userid, h.Precis, h.Noise); badword != "" { - if h.Precis == "" { - h.Precis = badword - } - h.Open = "" + if badword := unsee(zilences, h.Precis, h.Noise); badword != "" { + if h.Precis == "" { + h.Precis = badword } + h.Open = "" } h.HTML, _ = filt.String(h.Noise) emuxifier := func(e string) string { @@ -94,9 +93,15 @@ func reverbolate(userid int64, honks []*Honk) { } } -func unsee(userid int64, precis string, noise string) string { - if precis != "" { - return "more..." +func unsee(zilences []*regexp.Regexp, precis string, noise string) string { + for _, z := range zilences { + if z.MatchString(precis) || z.MatchString(noise) { + if precis == "" { + w := z.String() + return w[6 : len(w)-3] + } + return precis + } } return "" } @@ -495,6 +500,7 @@ func makeitworksomehowwithoutregardforkeycontinuity(keyname string, r *http.Requ var thumbbiters map[int64]map[string]bool var zordses map[int64][]*regexp.Regexp +var zilences map[int64][]*regexp.Regexp var thumblock sync.Mutex func bitethethumbs() { @@ -509,6 +515,7 @@ func bitethethumbs() { defer thumblock.Unlock() thumbbiters = make(map[int64]map[string]bool) zordses = make(map[int64][]*regexp.Regexp) + zilences = make(map[int64][]*regexp.Regexp) for rows.Next() { var userid int64 var name, wherefore string @@ -517,13 +524,17 @@ func bitethethumbs() { log.Printf("error scanning zonker: %s", err) continue } - if wherefore == "zord" { + if wherefore == "zord" || wherefore == "zilence" { zord := "\\b(?i:" + name + ")\\b" re, err := regexp.Compile(zord) if err != nil { log.Printf("error compiling zord: %s", err) } else { - zordses[userid] = append(zordses[userid], re) + if wherefore == "zord" { + zordses[userid] = append(zordses[userid], re) + } else { + zilences[userid] = append(zilences[userid], re) + } } continue } @@ -542,6 +553,12 @@ func getzords(userid int64) []*regexp.Regexp { return zordses[userid] } +func getzilences(userid int64) []*regexp.Regexp { + thumblock.Lock() + defer thumblock.Unlock() + return zilences[userid] +} + func thoudostbitethythumb(userid int64, who []string, objid string) bool { thumblock.Lock() biters := thumbbiters[userid] diff --git a/honk.go b/honk.go index 707a8c8..70f344e 100644 --- a/honk.go +++ b/honk.go @@ -1270,13 +1270,14 @@ func zonkzonk(w http.ResponseWriter, r *http.Request) { case "zomain": case "zonvoy": case "zord": + case "zilence": default: return } db := opendatabase() db.Exec("insert into zonkers (userid, name, wherefore) values (?, ?, ?)", userinfo.UserID, name, wherefore) - if wherefore == "zonker" || wherefore == "zomain" || wherefore == "zord" { + if wherefore == "zonker" || wherefore == "zomain" || wherefore == "zord" || wherefore == "zilence" { bitethethumbs() } @@ -1573,7 +1574,7 @@ func prepareStatements(db *sql.DB) { stmtGetDoovers = preparetodie(db, "select dooverid, dt from doovers") stmtLoadDoover = preparetodie(db, "select tries, username, rcpt, msg from doovers where dooverid = ?") stmtZapDoover = preparetodie(db, "delete from doovers where dooverid = ?") - stmtThumbBiters = preparetodie(db, "select userid, name, wherefore from zonkers where (wherefore = 'zonker' or wherefore = 'zomain' or wherefore = 'zord')") + stmtThumbBiters = preparetodie(db, "select userid, name, wherefore from zonkers where (wherefore = 'zonker' or wherefore = 'zomain' or wherefore = 'zord' or wherefore = 'zilence')") stmtFindZonk = preparetodie(db, "select zonkerid from zonkers where userid = ? and name = ? and wherefore = 'zonk'") stmtGetZonkers = preparetodie(db, "select zonkerid, name, wherefore from zonkers where userid = ? and wherefore <> 'zonk'") stmtSaveZonker = preparetodie(db, "insert into zonkers (userid, name, wherefore) values (?, ?, ?)") diff --git a/views/zonkers.html b/views/zonkers.html index 26a9739..7828542 100644 --- a/views/zonkers.html +++ b/views/zonkers.html @@ -19,6 +19,9 @@

+

+ +