all repos — honk @ f7b3efa4db79996be4360f171a0d9459c7bd9407

my fork of honk

zword zonking
Ted Unangst tedu@tedunangst.com
Thu, 30 May 2019 18:29:59 -0400
commit

f7b3efa4db79996be4360f171a0d9459c7bd9407

parent

6778d96af7b264b0a99f89d8a0f3a2cd245e2357

3 files changed, 50 insertions(+), 2 deletions(-)

jump to
M fun.gofun.go

@@ -76,6 +76,31 @@ h.Donks = h.Donks[:j]

} } +func osmosis(honks []*Honk, userid int64) []*Honk { + zwords := getzwords(userid) + collapse := false + for i, h := range honks { + for _, z := range zwords { + if z.MatchString(h.Noise) { + honks[i] = nil + collapse = true + break + } + } + } + if collapse { + j := 0 + for i := 0; i < len(honks); i++ { + if honks[i] != nil { + honks[j] = honks[i] + j++ + } + } + return honks[0:j] + } + return honks +} + func shortxid(xid string) string { idx := strings.LastIndexByte(xid, '/') if idx == -1 {

@@ -396,6 +421,7 @@ return zag(r, payload)

} var thumbbiters map[int64]map[string]bool +var zwordses map[int64][]*regexp.Regexp var thumblock sync.Mutex func bitethethumbs() {

@@ -408,6 +434,7 @@ defer rows.Close()

thumblock.Lock() defer thumblock.Unlock() thumbbiters = make(map[int64]map[string]bool) + zwordses = make(map[int64][]*regexp.Regexp) for rows.Next() { var userid int64 var name, wherefore string

@@ -416,6 +443,15 @@ if err != nil {

log.Printf("error scanning zonker: %s", err) continue } + if wherefore == "zword" { + re, err := regexp.Compile("\\b" + name + "\\b") + if err != nil { + log.Printf("error compiling zword: %s", err) + } else { + zwordses[userid] = append(zwordses[userid], re) + } + continue + } m := thumbbiters[userid] if m == nil { m = make(map[string]bool)

@@ -423,6 +459,12 @@ thumbbiters[userid] = m

} m[name] = true } +} + +func getzwords(userid int64) []*regexp.Regexp { + thumblock.Lock() + defer thumblock.Unlock() + return zwordses[userid] } func thoudostbitethythumb(userid int64, who []string, objid string) bool {
M honk.gohonk.go

@@ -112,6 +112,7 @@ if r.URL.Path == "/atme" {

honks = gethonksforme(u.UserID) } else { honks = gethonksforuser(u.UserID) + honks = osmosis(honks, u.UserID) } templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r) } else {

@@ -486,6 +487,7 @@ honks []*Honk, infomsg string) {

reverbolate(honks) templinfo := getInfo(r) if u != nil { + honks = osmosis(honks, u.UserID) templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r) } if u == nil {

@@ -1096,13 +1098,14 @@ switch wherefore {

case "zonker": case "zurl": case "zonvoy": + case "zword": default: return } db := opendatabase() db.Exec("insert into zonkers (userid, name, wherefore) values (?, ?, ?)", userinfo.UserID, name, wherefore) - if wherefore == "zonker" || wherefore == "zurl" { + if wherefore == "zonker" || wherefore == "zurl" || wherefore == "zword" { bitethethumbs() }

@@ -1380,7 +1383,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 = 'zurl')") + stmtThumbBiters = preparetodie(db, "select userid, name, wherefore from zonkers where (wherefore = 'zonker' or wherefore = 'zurl' or wherefore = 'zword')") stmtSaveZonker = preparetodie(db, "insert into zonkers (userid, name, wherefore) values (?, ?, ?)") stmtGetBoxes = preparetodie(db, "select ibox, obox, sbox from xonkers where xid = ?") stmtSaveBoxes = preparetodie(db, "insert into xonkers (xid, ibox, obox, sbox, pubkey) values (?, ?, ?, ?, ?)")
M views/zonkers.htmlviews/zonkers.html

@@ -16,6 +16,9 @@ <label for="iszurl">Zurl</label>

<p> <input type="radio" id="iszonvoy" name="wherefore" value="zonvoy"> <label for="iszonvoy">Zonvoy</label> +<p> +<input type="radio" id="iszword" name="wherefore" value="zword"> +<label for="iszword">Zword</label> <p><input tabindex=1 type="submit" name="kill" value="kill"> </form> </div>