all repos — honk @ 8d1e814cb772ed812e0d7bb2bb1c18ef885d84e9

my fork of honk

move follow code into activity.go
Ted Unangst tedu@tedunangst.com
Wed, 09 Sep 2020 13:58:48 -0400
commit

8d1e814cb772ed812e0d7bb2bb1c18ef885d84e9

parent

e3eb76f6f7c66a6f44555f2e8a4bfa9391890c52

3 files changed, 63 insertions(+), 62 deletions(-)

jump to
M activity.goactivity.go

@@ -1700,3 +1700,55 @@ for a := range rcpts {

go deliverate(0, user.ID, a, msg) } } + +func followme(user *WhatAbout, who string, name string, j junk.Junk) { + log.Printf("updating honker follow: %s", who) + + var x string + db := opendatabase() + row := db.QueryRow("select xid from honkers where name = ? and xid = ? and userid = ? and flavor in ('dub', 'undub')", name, who, user.ID) + err := row.Scan(&x) + if err != sql.ErrNoRows { + log.Printf("duplicate follow request: %s", who) + _, err = stmtUpdateFlavor.Exec("dub", user.ID, name, who, "undub") + if err != nil { + log.Printf("error updating honker: %s", err) + } + } else { + stmtSaveDub.Exec(user.ID, name, who, "dub") + } + go rubadubdub(user, j) +} + +func unfollowme(user *WhatAbout, who string, name string, j junk.Junk) { + log.Printf("updating honker undo: %s", who) + _, err := stmtUpdateFlavor.Exec("undub", user.ID, name, who, "dub") + if err != nil { + log.Printf("error updating honker: %s", err) + return + } +} + +func followyou(user *WhatAbout, target string) { + +} + +func followyou2(user *WhatAbout, j junk.Junk) { + who, _ := j.GetString("actor") + + log.Printf("updating honker accept: %s", who) + var name string + db := opendatabase() + row := db.QueryRow("select name from honkers where userid = ? and xid = ? and flavor in ('presub')", + user.ID, who) + err := row.Scan(&name) + if err != nil { + log.Printf("can't get honker name: %s", err) + return + } + _, err = stmtUpdateFlavor.Exec("sub", user.ID, name, who, "presub") + if err != nil { + log.Printf("error updating honker: %s", err) + return + } +}
M database.godatabase.go

@@ -881,7 +881,7 @@

func prepareStatements(db *sql.DB) { stmtHonkers = preparetodie(db, "select honkerid, userid, name, xid, flavor, combos, meta 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, owner, meta, folxid) values (?, ?, ?, ?, ?, ?, ?, '')") - stmtUpdateFlavor = preparetodie(db, "update honkers set flavor = ? where userid = ? and xid = ? and name = ? and flavor = ?") + stmtUpdateFlavor = preparetodie(db, "update honkers set flavor = ? where userid = ? and name = ? and xid = ? and flavor = ?") stmtUpdateHonker = preparetodie(db, "update honkers set name = ?, combos = ?, meta = ? 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'")
M web.goweb.go

@@ -377,38 +377,9 @@ if obj != user.URL {

log.Printf("can't follow %s", obj) return } - log.Printf("updating honker follow: %s", who) - - var x string - db := opendatabase() - row := db.QueryRow("select xid from honkers where xid = ? and userid = ? and flavor in ('dub', 'undub')", who, user.ID) - err = row.Scan(&x) - if err != sql.ErrNoRows { - log.Printf("duplicate follow request: %s", who) - _, err = stmtUpdateFlavor.Exec("dub", user.ID, who, who, "undub") - if err != nil { - log.Printf("error updating honker: %s", err) - } - } else { - stmtSaveDub.Exec(user.ID, who, who, "dub") - } - go rubadubdub(user, j) + followme(user, who, who, j) case "Accept": - log.Printf("updating honker accept: %s", who) - var name string - db := opendatabase() - row := db.QueryRow("select name from honkers where userid = ? and xid = ? and flavor in ('presub')", - user.ID, who) - err := row.Scan(&name) - if err != nil { - log.Printf("can't get honker name: %s", err) - return - } - _, err = stmtUpdateFlavor.Exec("sub", user.ID, who, name, "presub") - if err != nil { - log.Printf("error updating honker: %s", err) - return - } + followyou2(user, j) case "Update": obj, ok := j.GetMap("object") if ok {

@@ -435,12 +406,7 @@ }

what, _ := obj.GetString("type") switch what { case "Follow": - log.Printf("updating honker undo: %s", who) - _, err = stmtUpdateFlavor.Exec("undub", user.ID, who, who, "dub") - if err != nil { - log.Printf("error updating honker: %s", err) - return - } + unfollowme(user, who, who, j) case "Announce": xid, _ := obj.GetString("object") log.Printf("undo announce: %s", xid)

@@ -514,21 +480,8 @@ log.Printf("not sure how to handle this")

return } ont := "#" + m[1] - log.Printf("%s wants to follow %s", who, ont) - var x string - db := opendatabase() - row := db.QueryRow("select xid from honkers where name = ? and xid = ? and userid = ? and flavor in ('dub', 'undub')", ont, who, user.ID) - err = row.Scan(&x) - if err != sql.ErrNoRows { - log.Printf("duplicate follow request: %s", who) - _, err = stmtUpdateFlavor.Exec("dub", user.ID, who, ont, "undub") - if err != nil { - log.Printf("error updating honker: %s", err) - } - } else { - stmtSaveDub.Exec(user.ID, ont, who, "dub") - } - go rubadubdub(user, j) + + followme(user, who, ont, j) case "Undo": obj, ok := j.GetMap("object") if !ok {

@@ -538,6 +491,7 @@ }

what, _ := obj.GetString("type") if what != "Follow" { log.Printf("unknown undo: %s", what) + return } targ, _ := obj.GetString("object") m := re_ont.FindStringSubmatch(targ)

@@ -546,12 +500,7 @@ log.Printf("not sure how to handle this")

return } ont := "#" + m[1] - log.Printf("updating honker undo: %s %s", who, ont) - _, err = stmtUpdateFlavor.Exec("undub", user.ID, who, ont, "dub") - if err != nil { - log.Printf("error updating honker: %s", err) - return - } + unfollowme(user, who, ont, j) default: log.Printf("unhandled server activity: %s", what) dumpactivity(j)

@@ -1896,7 +1845,7 @@ return

} log.Printf("unsubscribing from %s", url) user, _ := butwhatabout(u.Username) - _, err = stmtUpdateFlavor.Exec("unsub", u.UserID, url, name, "sub") + _, err = stmtUpdateFlavor.Exec("unsub", u.UserID, name, url, "sub") if err != nil { log.Printf("error updating honker: %s", err) return

@@ -1918,9 +1867,9 @@ return

} log.Printf("resubscribing to %s", url) user, _ := butwhatabout(u.Username) - _, err = stmtUpdateFlavor.Exec("presub", u.UserID, url, name, "unsub") + _, err = stmtUpdateFlavor.Exec("presub", u.UserID, name, url, "unsub") if err == nil { - _, err = stmtUpdateFlavor.Exec("presub", u.UserID, url, name, "peep") + _, err = stmtUpdateFlavor.Exec("presub", u.UserID, name, url, "peep") } if err != nil { log.Printf("error updating honker: %s", err)