From 1e632a8ddb3d19e57a2492f7083d137993be0569 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Wed, 9 Sep 2020 14:33:12 -0400 Subject: [PATCH] move more follow code into activity.go --- activity.go | 39 +++++++++++++++++++++++++++++++++++++++ web.go | 49 +++++++------------------------------------------ 2 files changed, 46 insertions(+), 42 deletions(-) diff --git a/activity.go b/activity.go index 6330066..304ddc8 100644 --- a/activity.go +++ b/activity.go @@ -1733,6 +1733,45 @@ func followyou(user *WhatAbout, target string) { } +func refollowyou(user *WhatAbout, honkerid int64) { + var url, owner string + db := opendatabase() + row := db.QueryRow("select xid, owner from honkers where honkerid = ? and userid = ? and flavor in ('unsub', 'peep', 'presub', 'sub')", + honkerid, user.ID) + err := row.Scan(&url, &owner) + if err != nil { + log.Printf("can't get honker xid: %s", err) + return + } + log.Printf("resubscribing to %s", url) + _, err = db.Exec("update honkers set flavor = ? where honkerid = ?", "presub", honkerid) + if err != nil { + log.Printf("error updating honker: %s", err) + return + } + go subsub(user, url, owner) + +} +func unfollowyou(user *WhatAbout, honkerid int64) { + var url string + db := opendatabase() + row := db.QueryRow("select xid from honkers where honkerid = ? and userid = ? and flavor in ('sub')", + honkerid, user.ID) + err := row.Scan(&url) + if err != nil { + log.Printf("can't get honker xid: %s", err) + return + } + log.Printf("unsubscribing from %s", url) + _, err = db.Exec("update honkers set flavor = ? where honkerid = ?", "unsub", honkerid) + if err != nil { + log.Printf("error updating honker: %s", err) + return + } + go itakeitallback(user, url) + +} + func followyou2(user *WhatAbout, j junk.Junk) { who, _ := j.GetString("actor") diff --git a/web.go b/web.go index d337d6a..58900a4 100644 --- a/web.go +++ b/web.go @@ -1819,6 +1819,7 @@ func showcombos(w http.ResponseWriter, r *http.Request) { func submithonker(w http.ResponseWriter, r *http.Request) { u := login.GetUserInfo(r) + user, _ := butwhatabout(u.Username) name := strings.TrimSpace(r.FormValue("name")) url := strings.TrimSpace(r.FormValue("url")) peep := r.FormValue("peep") @@ -1835,48 +1836,12 @@ func submithonker(w http.ResponseWriter, r *http.Request) { if honkerid > 0 { goodbye := r.FormValue("goodbye") if goodbye == "F" { - db := opendatabase() - row := db.QueryRow("select xid from honkers where honkerid = ? and userid = ? and flavor in ('sub')", - honkerid, u.UserID) - err := row.Scan(&url) - if err != nil { - log.Printf("can't get honker xid: %s", err) - return - } - log.Printf("unsubscribing from %s", url) - user, _ := butwhatabout(u.Username) - _, err = stmtUpdateFlavor.Exec("unsub", u.UserID, name, url, "sub") - if err != nil { - log.Printf("error updating honker: %s", err) - return - } - go itakeitallback(user, url) - + unfollowyou(user, honkerid) http.Redirect(w, r, "/honkers", http.StatusSeeOther) return } if goodbye == "X" { - var owner string - db := opendatabase() - row := db.QueryRow("select xid, owner from honkers where honkerid = ? and userid = ? and flavor in ('unsub', 'peep', 'presub', 'sub')", - honkerid, u.UserID) - 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, name, url, "unsub") - if err == nil { - _, err = stmtUpdateFlavor.Exec("presub", u.UserID, name, url, "peep") - } - if err != nil { - log.Printf("error updating honker: %s", err) - return - } - go subsub(user, url, owner) - + refollowyou(user, honkerid) http.Redirect(w, r, "/honkers", http.StatusSeeOther) return } @@ -1921,6 +1886,10 @@ func submithonker(w http.ResponseWriter, r *http.Request) { } url = info.XID + if name == "" { + name = info.Name + } + var x string db := opendatabase() row := db.QueryRow("select xid from honkers where xid = ? and userid = ? and flavor in ('sub', 'unsub', 'peep')", url, u.UserID) @@ -1933,16 +1902,12 @@ func submithonker(w http.ResponseWriter, r *http.Request) { return } - if name == "" { - name = info.Name - } _, err = stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos, info.Owner, mj) if err != nil { log.Print(err) return } if flavor == "presub" { - user, _ := butwhatabout(u.Username) go subsub(user, url, info.Owner) } http.Redirect(w, r, "/honkers", http.StatusSeeOther)