diff --git a/database.go b/database.go index 2d3e855..4b22156 100644 --- a/database.go +++ b/database.go @@ -696,8 +696,8 @@ func preparetodie(db *sql.DB, s string) *sql.Stmt { 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 @@ func prepareStatements(db *sql.DB) { 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) diff --git a/schema.sql b/schema.sql index c84f71b..8b1f7be 100644 --- a/schema.sql +++ b/schema.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); diff --git a/upgradedb.go b/upgradedb.go index 7336b7d..4bb2dc5 100644 --- a/upgradedb.go +++ b/upgradedb.go @@ -24,7 +24,7 @@ import ( "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 @@ func upgradedb() { 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) diff --git a/web.go b/web.go index b3af9a3..4aa9d68 100644 --- a/web.go +++ b/web.go @@ -458,6 +458,7 @@ func serverinbox(w http.ResponseWriter, r *http.Request) { 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 @@ func serverinbox(w http.ResponseWriter, r *http.Request) { 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 @@ func serverinbox(w http.ResponseWriter, r *http.Request) { 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 @@ func serverinbox(w http.ResponseWriter, r *http.Request) { 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 @@ func serverinbox(w http.ResponseWriter, r *http.Request) { 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 @@ func submithonker(w http.ResponseWriter, r *http.Request) { 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 @@ func submithonker(w http.ResponseWriter, r *http.Request) { 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 @@ func submithonker(w http.ResponseWriter, r *http.Request) { 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