all repos — honk @ 909871a7834f224e37d9a26546e2a2e04671a524

my fork of honk

zilence (collapse) posts matching regex
Ted Unangst tedu@tedunangst.com
Wed, 10 Jul 2019 17:39:41 -0400
commit

909871a7834f224e37d9a26546e2a2e04671a524

parent

0dec695e683f3cd0e9a7d4d459f91ecec2fd87d9

5 files changed, 38 insertions(+), 13 deletions(-)

jump to
M docs/changelog.txtdocs/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.
M docs/manual.txtdocs/manual.txt

@@ -59,6 +59,8 @@

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
M fun.gofun.go

@@ -33,6 +33,7 @@ )

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 @@ }

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 @@ h.Donks = h.Donks[:j]

} } -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 @@ }

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 @@ thumblock.Lock()

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 @@ if err != nil {

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 }

@@ -540,6 +551,12 @@ func getzords(userid int64) []*regexp.Regexp {

thumblock.Lock() defer thumblock.Unlock() 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 {
M honk.gohonk.go

@@ -1270,13 +1270,14 @@ case "zonker":

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 @@ stmtAddDoover = preparetodie(db, "insert into doovers (dt, tries, username, rcpt, msg) values (?, ?, ?, ?, ?)")

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 (?, ?, ?)")
M views/zonkers.htmlviews/zonkers.html

@@ -19,6 +19,9 @@ <label for="iszonvoy">Zonvoy</label>

<p> <input type="radio" id="iszord" name="wherefore" value="zord"> <label for="iszord">Zord</label> +<p> +<input type="radio" id="iszilence" name="wherefore" value="zilence"> +<label for="iszilence">Zilence</label> <p><br><input tabindex=1 type="submit" name="zonk" value="zonk!"> </form> </div>