update follow request instead of creating dupes

This commit is contained in:
Ted Unangst 2019-10-06 21:57:31 -04:00
parent 2b01dc8935
commit 86f05b7166
1 changed files with 14 additions and 1 deletions

13
web.go
View File

@ -324,7 +324,20 @@ func inbox(w http.ResponseWriter, r *http.Request) {
obj, _ := j.GetString("object") obj, _ := j.GetString("object")
if obj == user.URL { if obj == user.URL {
log.Printf("updating honker follow: %s", who) log.Printf("updating honker follow: %s", who)
db := opendatabase()
row := db.QueryRow("select xid from honkers where xid = ? and userid = ? and flavor in ('dub', 'undub')", who, user.ID)
var x string
err = row.Scan(&x)
if err != sql.ErrNoRows {
log.Printf("duplicate follow request: %s", who)
_, err = stmtUpdateFlavor.Exec("dub", user.ID, who, "undub")
if err != nil {
log.Printf("error updating honker: %s", err)
}
} else {
stmtSaveDub.Exec(user.ID, who, who, "dub") stmtSaveDub.Exec(user.ID, who, who, "dub")
}
go rubadubdub(user, j) go rubadubdub(user, j)
} else { } else {
log.Printf("can't follow %s", obj) log.Printf("can't follow %s", obj)