zilence (collapse) posts matching regex

This commit is contained in:
Ted Unangst 2019-07-10 17:39:41 -04:00
parent 2a2019743f
commit eab34a6104
5 changed files with 38 additions and 13 deletions

View File

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

View File

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

31
fun.go
View File

@ -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,14 +63,12 @@ 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 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 {
for _, d := range h.Donks {
@ -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 {
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]

View File

@ -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 (?, ?, ?)")

View File

@ -19,6 +19,9 @@
<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>