From 409d1e99324b204433cce8d42ecb244b712f898f Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sat, 28 Sep 2019 17:40:24 -0400 Subject: [PATCH] media skipping for naughty people --- activity.go | 5 ++++- database.go | 2 +- fun.go | 23 +++++++++++++++++------ hfcs.go | 32 ++++++++++++++++++++++++++++++++ views/zonkers.html | 3 +++ web.go | 4 +++- 6 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 hfcs.go diff --git a/activity.go b/activity.go index 9259ecc..53ee522 100644 --- a/activity.go +++ b/activity.go @@ -542,6 +542,7 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk { var xonk Honk // early init + xonk.UserID = user.ID xonk.Honker, _ = item.GetString("actor") if obj != nil { if xonk.Honker == "" { @@ -655,6 +656,9 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk { } else { log.Printf("unknown attachment: %s", at) } + if skipMedia(&xonk) { + localize = false + } donk := savedonk(u, name, desc, mt, localize) if donk != nil { xonk.Donks = append(xonk.Donks, donk) @@ -713,7 +717,6 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk { } // init xonk - xonk.UserID = user.ID xonk.What = what xonk.XID = xid xonk.RID = rid diff --git a/database.go b/database.go index e8a54b8..f1ac6ac 100644 --- a/database.go +++ b/database.go @@ -435,7 +435,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' or wherefore = 'zilence')") + stmtThumbBiters = preparetodie(db, "select userid, name, wherefore from zonkers") 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/fun.go b/fun.go index a6a700f..5a2cb5d 100644 --- a/fun.go +++ b/fun.go @@ -659,6 +659,7 @@ func makeitworksomehowwithoutregardforkeycontinuity(keyname string, r *http.Requ } var thumbbiters map[int64]map[string]bool +var zoggles map[int64]map[string]bool var zordses map[int64][]*regexp.Regexp var zilences map[int64][]*regexp.Regexp var thumblock sync.Mutex @@ -674,6 +675,7 @@ func bitethethumbs() { thumblock.Lock() defer thumblock.Unlock() thumbbiters = make(map[int64]map[string]bool) + zoggles = make(map[int64]map[string]bool) zordses = make(map[int64][]*regexp.Regexp) zilences = make(map[int64][]*regexp.Regexp) for rows.Next() { @@ -696,14 +698,23 @@ func bitethethumbs() { zilences[userid] = append(zilences[userid], re) } } - continue } - m := thumbbiters[userid] - if m == nil { - m = make(map[string]bool) - thumbbiters[userid] = m + if wherefore == "zoggle" { + m := zoggles[userid] + if m == nil { + m = make(map[string]bool) + zoggles[userid] = m + } + m[name] = true + } + if wherefore == "zonker" || wherefore == "zomain" { + m := thumbbiters[userid] + if m == nil { + m = make(map[string]bool) + thumbbiters[userid] = m + } + m[name] = true } - m[name] = true } } diff --git a/hfcs.go b/hfcs.go new file mode 100644 index 0000000..4b550da --- /dev/null +++ b/hfcs.go @@ -0,0 +1,32 @@ +// +// Copyright (c) 2019 Ted Unangst +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +package main + +import ( + "log" +) + +func skipMedia(xonk *Honk) bool { + thumblock.Lock() + goggles := zoggles[xonk.UserID] + thumblock.Unlock() + + if goggles[xonk.Honker] || goggles[xonk.Oonker] { + log.Printf("skipping media") + return true + } + return false +} diff --git a/views/zonkers.html b/views/zonkers.html index 7828542..d5ed9d7 100644 --- a/views/zonkers.html +++ b/views/zonkers.html @@ -22,6 +22,9 @@

+

+ +


diff --git a/web.go b/web.go index 93696c9..4705a67 100644 --- a/web.go +++ b/web.go @@ -1265,13 +1265,15 @@ func zonkzonk(w http.ResponseWriter, r *http.Request) { case "zonvoy": case "zord": case "zilence": + case "zoggle": default: return } db := opendatabase() db.Exec("insert into zonkers (userid, name, wherefore) values (?, ?, ?)", userinfo.UserID, name, wherefore) - if wherefore == "zonker" || wherefore == "zomain" || wherefore == "zord" || wherefore == "zilence" { + + if wherefore != "zonvoy" { bitethethumbs() }