diff --git a/activity.go b/activity.go index 4683efc..98552aa 100644 --- a/activity.go +++ b/activity.go @@ -922,6 +922,10 @@ func itakeitallback(user *WhatAbout, xid string) { } func subsub(user *WhatAbout, xid string) { + if xid == "" { + log.Printf("can't subscribe to empty") + return + } j := junk.New() j["@context"] = itiswhatitis j["id"] = user.URL + "/sub/" + url.QueryEscape(xid) diff --git a/views/honkers.html b/views/honkers.html index b6f87c9..e257e7f 100644 --- a/views/honkers.html +++ b/views/honkers.html @@ -39,7 +39,11 @@ function expandstuff() {
combos: -
depart: +{{ if eq .Flavor "sub" }} +
unsub: +{{ else }} +
resub: +{{ end }}
diff --git a/web.go b/web.go index 71dcc12..a086a2a 100644 --- a/web.go +++ b/web.go @@ -1183,20 +1183,43 @@ func submithonker(w http.ResponseWriter, r *http.Request) { db := opendatabase() row := db.QueryRow("select xid from honkers where honkerid = ? and userid = ?", honkerid, u.UserID) - var xid string - err := row.Scan(&xid) + err := row.Scan(&url) if err != nil { log.Printf("can't get honker xid: %s", err) return } - log.Printf("unsubscribing from %s", xid) + log.Printf("unsubscribing from %s", url) user, _ := butwhatabout(u.Username) - go itakeitallback(user, xid) - _, err = stmtUpdateFlavor.Exec("unsub", u.UserID, xid, "sub") + _, err = stmtUpdateFlavor.Exec("unsub", u.UserID, url, "sub") if err != nil { log.Printf("error updating honker: %s", err) return } + go itakeitallback(user, url) + + http.Redirect(w, r, "/honkers", http.StatusSeeOther) + return + } + if goodbye == "X" { + db := opendatabase() + row := db.QueryRow("select xid from honkers where honkerid = ? and userid = ?", + honkerid, u.UserID) + err := row.Scan(&url) + 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") + if err == nil { + _, err = stmtUpdateFlavor.Exec("presub", u.UserID, url, "peep") + } + if err != nil { + log.Printf("error updating honker: %s", err) + return + } + go subsub(user, url) http.Redirect(w, r, "/honkers", http.StatusSeeOther) return