all repos — honk @ ae62659c3be421818be2278a121e73b94a3679bc

my fork of honk

tighten up some of the new honker handling
Ted Unangst tedu@tedunangst.com
Sat, 26 Oct 2019 19:13:27 -0400
commit

ae62659c3be421818be2278a121e73b94a3679bc

parent

cee33e1a7cd2a40e3286b60a8ecdeacaf4047ecc

4 files changed, 33 insertions(+), 24 deletions(-)

jump to
M database.godatabase.go

@@ -696,8 +696,8 @@ }

func prepareStatements(db *sql.DB) { stmtHonkers = preparetodie(db, "select honkerid, userid, name, xid, flavor, combos from honkers where userid = ? and (flavor = 'presub' or flavor = 'sub' or flavor = 'peep' or flavor = 'unsub') order by name") - stmtSaveHonker = preparetodie(db, "insert into honkers (userid, name, xid, flavor, combos) values (?, ?, ?, ?, ?)") - stmtUpdateFlavor = preparetodie(db, "update honkers set flavor = ? where userid = ? and xid = ? and flavor = ?") + stmtSaveHonker = preparetodie(db, "insert into honkers (userid, name, xid, flavor, combos, owner) values (?, ?, ?, ?, ?, ?)") + stmtUpdateFlavor = preparetodie(db, "update honkers set flavor = ? where userid = ? and xid = ? and name = ? and flavor = ?") stmtUpdateHonker = preparetodie(db, "update honkers set name = ?, combos = ? where honkerid = ? and userid = ?") stmtOneHonker = preparetodie(db, "select xid from honkers where name = ? and userid = ?") stmtDubbers = preparetodie(db, "select honkerid, userid, name, xid, flavor from honkers where userid = ? and flavor = 'dub'")

@@ -719,9 +719,7 @@ stmtHonksForMe = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and dt > ? and whofore = 1"+butnotthose+limit)

stmtHonksISaved = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and flags & 4 order by honks.honkid desc") stmtHonksByHonker = preparetodie(db, selecthonks+"join honkers on (honkers.xid = honks.honker or honkers.xid = honks.oonker) where honks.honkid > ? and honks.userid = ? and honkers.name = ?"+butnotthose+limit) stmtHonksByXonker = preparetodie(db, selecthonks+" where honks.honkid > ? and honks.userid = ? and (honker = ? or oonker = ?)"+butnotthose+limit) - stmtHonksByCombo = preparetodie(db, selecthonks+"join honkers on honkers.xid = honks.honker where honks.honkid > ? and honks.userid = ? and honkers.combos like ?"+butnotthose+ " union "+selecthonks+"join onts on honks.honkid = onts.honkid where honks.honkid > ? and honks.userid = ? and onts.ontology in (select xid from honkers where combos like ?)"+butnotthose+limit) - - + stmtHonksByCombo = preparetodie(db, selecthonks+"join honkers on honkers.xid = honks.honker where honks.honkid > ? and honks.userid = ? and honkers.combos like ?"+butnotthose+" union "+selecthonks+"join onts on honks.honkid = onts.honkid where honks.honkid > ? and honks.userid = ? and onts.ontology in (select xid from honkers where combos like ?)"+butnotthose+limit) stmtHonksBySearch = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and (? = 0 or xid like ?) and (? = 0 or honks.honker = ? or honks.oonker = ?) and noise like ?"+butnotthose+limit) stmtHonksByConvoy = preparetodie(db, selecthonks+"where honks.honkid > ? and (honks.userid = ? or (? = -1 and whofore = 2)) and convoy = ?"+limit) stmtHonksByOntology = preparetodie(db, selecthonks+"join onts on honks.honkid = onts.honkid where honks.honkid > ? and onts.ontology = ? and (honks.userid = ? or (? = -1 and honks.whofore = 2))"+limit)
M schema.sqlschema.sql

@@ -2,7 +2,7 @@

create table honks (honkid integer primary key, userid integer, what text, honker text, xid text, rid text, dt text, url text, audience text, noise text, convoy text, whofore integer, format text, precis text, oonker text, flags integer); create table donks (honkid integer, fileid integer); create table filemeta (fileid integer primary key, xid text, name text, description text, url text, media text, local integer); -create table honkers (honkerid integer primary key, userid integer, name text, xid text, flavor text, combos text); +create table honkers (honkerid integer primary key, userid integer, name text, xid text, flavor text, combos text, owner text); create table xonkers (xonkerid integer primary key, name text, info text, flavor text); create table zonkers (zonkerid integer primary key, userid integer, name text, wherefore text); create table doovers(dooverid integer primary key, dt text, tries integer, userid integer, rcpt text, msg blob);
M upgradedb.goupgradedb.go

@@ -24,7 +24,7 @@ "strings"

"time" ) -var myVersion = 29 +var myVersion = 30 func doordie(db *sql.DB, s string, args ...interface{}) { _, err := db.Exec(s, args...)

@@ -312,6 +312,11 @@ doordie(db, "create table doovers(dooverid integer primary key, dt text, tries integer, userid integer, rcpt text, msg blob)")

doordie(db, "update config set value = 29 where key = 'dbversion'") fallthrough case 29: + doordie(db, "alter table honkers add column owner text") + doordie(db, "update honkers set owner = xid") + doordie(db, "update config set value = 30 where key = 'dbversion'") + fallthrough + case 30: default: log.Fatalf("can't upgrade unknown version %d", dbversion)
M web.goweb.go

@@ -458,6 +458,7 @@ }

if rejectactor(user.ID, who) { return } + re_ont := regexp.MustCompile("https://" + serverName + "/o/([[:alnum:]]+)") what, _ := j.GetString("type") log.Printf("server got a %s", what) switch what {

@@ -467,7 +468,6 @@ if obj == user.URL {

log.Printf("can't follow the server!") return } - re_ont := regexp.MustCompile("https://" + serverName + "/o/([[:alnum:]]+)") m := re_ont.FindStringSubmatch(obj) if len(m) == 2 { ont := "#" + m[1]

@@ -477,9 +477,8 @@ row := db.QueryRow("select xid from honkers where name = ? and xid = ? and userid = ? and flavor in ('dub', 'undub')", ont, who, user.ID)

var x string err = row.Scan(&x) if err != sql.ErrNoRows { - // incomplete... log.Printf("duplicate follow request: %s", who) - _, err = stmtUpdateFlavor.Exec("dub", user.ID, who, "undub") + _, err = stmtUpdateFlavor.Exec("dub", user.ID, who, ont, "undub") if err != nil { log.Printf("error updating honker: %s", err) }

@@ -487,6 +486,8 @@ } else {

stmtSaveDub.Exec(user.ID, ont, who, "dub") } go rubadubdub(user, j) + } else { + log.Printf("not sure how to handle this") } case "Undo": obj, ok := j.GetMap("object")

@@ -496,12 +497,18 @@ } else {

what, _ := obj.GetString("type") switch what { case "Follow": - // incomplete... - log.Printf("updating honker undo: %s", who) - _, err = stmtUpdateFlavor.Exec("undub", user.ID, who, "dub") - if err != nil { - log.Printf("error updating honker: %s", err) - return + targ, _ := obj.GetString("object") + m := re_ont.FindStringSubmatch(targ) + if len(m) == 2 { + ont := "#" + m[1] + log.Printf("updating honker undo: %s", who, ont) + _, err = stmtUpdateFlavor.Exec("undub", user.ID, who, ont, "dub") + if err != nil { + log.Printf("error updating honker: %s", err) + return + } + } else { + log.Printf("not sure how to handle this") } default: log.Printf("unknown undo: %s", what)

@@ -1489,26 +1496,25 @@ http.Redirect(w, r, "/honkers", http.StatusSeeOther)

return } if goodbye == "X" { + var owner string db := opendatabase() - row := db.QueryRow("select xid from honkers where honkerid = ? and userid = ? and flavor in ('unsub', 'peep')", + row := db.QueryRow("select xid, owner from honkers where honkerid = ? and userid = ? and flavor in ('unsub', 'peep')", honkerid, u.UserID) - err := row.Scan(&url) + err := row.Scan(&url, &owner) if err != nil { log.Printf("can't get honker xid: %s", err) return } log.Printf("resubscribing to %s", url) user, _ := butwhatabout(u.Username) - _, err = stmtUpdateFlavor.Exec("presub", u.UserID, url, "unsub") + _, err = stmtUpdateFlavor.Exec("presub", u.UserID, url, name, "unsub") if err == nil { - _, err = stmtUpdateFlavor.Exec("presub", u.UserID, url, "peep") + _, err = stmtUpdateFlavor.Exec("presub", u.UserID, url, name, "peep") } if err != nil { log.Printf("error updating honker: %s", err) return } - // incomplete - owner := url go subsub(user, url, owner) http.Redirect(w, r, "/honkers", http.StatusSeeOther)

@@ -1534,7 +1540,7 @@ flavor = "peep"

if name == "" { name = url } - _, err := stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos) + _, err := stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos, url) if err != nil { log.Print(err) return

@@ -1565,7 +1571,7 @@

if name == "" { name = info.Name } - _, err = stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos) + _, err = stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos, info.Owner) if err != nil { log.Print(err) return