diff --git a/fun.go b/fun.go index 3bd34bf..f1d426b 100644 --- a/fun.go +++ b/fun.go @@ -76,6 +76,31 @@ func reverbolate(honks []*Honk) { } } +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 @@ func makeitworksomehowwithoutregardforkeycontinuity(keyname string, r *http.Requ } var thumbbiters map[int64]map[string]bool +var zwordses map[int64][]*regexp.Regexp var thumblock sync.Mutex func bitethethumbs() { @@ -408,6 +434,7 @@ func bitethethumbs() { 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 @@ func bitethethumbs() { 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) @@ -425,6 +461,12 @@ func bitethethumbs() { } } +func getzwords(userid int64) []*regexp.Regexp { + thumblock.Lock() + defer thumblock.Unlock() + return zwordses[userid] +} + func thoudostbitethythumb(userid int64, who []string, objid string) bool { thumblock.Lock() biters := thumbbiters[userid] diff --git a/honk.go b/honk.go index b30f9f7..369bf48 100644 --- a/honk.go +++ b/honk.go @@ -112,6 +112,7 @@ func homepage(w http.ResponseWriter, r *http.Request) { 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 @@ func honkpage(w http.ResponseWriter, r *http.Request, u *login.UserInfo, user *W 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 @@ func killitwithfire(w http.ResponseWriter, r *http.Request) { 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 @@ 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 = '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 (?, ?, ?, ?, ?)") diff --git a/views/zonkers.html b/views/zonkers.html index 7fa0b2f..9767eb1 100644 --- a/views/zonkers.html +++ b/views/zonkers.html @@ -16,6 +16,9 @@

+

+ +