move more follow code into activity.go

This commit is contained in:
Ted Unangst 2020-09-09 14:33:12 -04:00
parent 4ffc647549
commit 1e632a8ddb
2 changed files with 46 additions and 42 deletions

View File

@ -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) { func followyou2(user *WhatAbout, j junk.Junk) {
who, _ := j.GetString("actor") who, _ := j.GetString("actor")

49
web.go
View File

@ -1819,6 +1819,7 @@ func showcombos(w http.ResponseWriter, r *http.Request) {
func submithonker(w http.ResponseWriter, r *http.Request) { func submithonker(w http.ResponseWriter, r *http.Request) {
u := login.GetUserInfo(r) u := login.GetUserInfo(r)
user, _ := butwhatabout(u.Username)
name := strings.TrimSpace(r.FormValue("name")) name := strings.TrimSpace(r.FormValue("name"))
url := strings.TrimSpace(r.FormValue("url")) url := strings.TrimSpace(r.FormValue("url"))
peep := r.FormValue("peep") peep := r.FormValue("peep")
@ -1835,48 +1836,12 @@ func submithonker(w http.ResponseWriter, r *http.Request) {
if honkerid > 0 { if honkerid > 0 {
goodbye := r.FormValue("goodbye") goodbye := r.FormValue("goodbye")
if goodbye == "F" { if goodbye == "F" {
db := opendatabase() unfollowyou(user, honkerid)
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)
http.Redirect(w, r, "/honkers", http.StatusSeeOther) http.Redirect(w, r, "/honkers", http.StatusSeeOther)
return return
} }
if goodbye == "X" { if goodbye == "X" {
var owner string refollowyou(user, honkerid)
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)
http.Redirect(w, r, "/honkers", http.StatusSeeOther) http.Redirect(w, r, "/honkers", http.StatusSeeOther)
return return
} }
@ -1921,6 +1886,10 @@ func submithonker(w http.ResponseWriter, r *http.Request) {
} }
url = info.XID url = info.XID
if name == "" {
name = info.Name
}
var x string var x string
db := opendatabase() db := opendatabase()
row := db.QueryRow("select xid from honkers where xid = ? and userid = ? and flavor in ('sub', 'unsub', 'peep')", url, u.UserID) 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 return
} }
if name == "" {
name = info.Name
}
_, err = stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos, info.Owner, mj) _, err = stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos, info.Owner, mj)
if err != nil { if err != nil {
log.Print(err) log.Print(err)
return return
} }
if flavor == "presub" { if flavor == "presub" {
user, _ := butwhatabout(u.Username)
go subsub(user, url, info.Owner) go subsub(user, url, info.Owner)
} }
http.Redirect(w, r, "/honkers", http.StatusSeeOther) http.Redirect(w, r, "/honkers", http.StatusSeeOther)