all repos — honk @ 5e1af23beb3ea7d5f84cf652f8b2f183d185b5fd

my fork of honk

@me page just for me
Ted Unangst tedu@tedunangst.com
Sat, 20 Apr 2019 11:17:00 -0400
commit

5e1af23beb3ea7d5f84cf652f8b2f183d185b5fd

parent

4d307f8cbc709541d83b0e593f48532250809189

6 files changed, 49 insertions(+), 18 deletions(-)

jump to
M activity.goactivity.go

@@ -243,7 +243,7 @@ }

return true } -func savexonk(x *Honk) { +func savexonk(user *WhatAbout, x *Honk) { if x.What == "eradicate" { log.Printf("eradicating %s by %s", x.RID, x.Honker) _, err := stmtDeleteHonk.Exec(x.RID, x.Honker)

@@ -254,7 +254,12 @@ return

} dt := x.Date.UTC().Format(dbtimeformat) aud := strings.Join(x.Audience, " ") - res, err := stmtSaveHonk.Exec(x.UserID, x.What, x.Honker, x.XID, x.RID, dt, x.URL, aud, x.Noise, x.Convoy) + whofore := 0 + if strings.Contains(aud, user.URL) { + whofore = 1 + } + res, err := stmtSaveHonk.Exec(x.UserID, x.What, x.Honker, x.XID, x.RID, dt, x.URL, aud, + x.Noise, x.Convoy, whofore) if err != nil { log.Printf("err saving xonk: %s", err) return

@@ -347,7 +352,7 @@ for _, item := range items {

xonk := xonkxonk(item) if xonk != nil && needxonk(user, xonk) { xonk.UserID = user.ID - savexonk(xonk) + savexonk(user, xonk) } } }
M honk.gohonk.go

@@ -109,7 +109,11 @@ templinfo := getInfo(r)

u := GetUserInfo(r) var honks []*Honk if u != nil { - honks = gethonksforuser(u.UserID) + if r.URL.Path == "/atme" { + honks = gethonksforme(u.UserID) + } else { + honks = gethonksforuser(u.UserID) + } templinfo["HonkCSRF"] = GetCSRF("honkhonk", r) } else { honks = gethonks()

@@ -354,7 +358,7 @@ default:

xonk := xonkxonk(j) if xonk != nil && needxonk(user, xonk) { xonk.UserID = user.ID - savexonk(xonk) + savexonk(user, xonk) } } }

@@ -596,6 +600,11 @@ dt := time.Now().UTC().Add(-2 * 24 * time.Hour)

rows, err := stmtHonksForUser.Query(userid, dt.Format(dbtimeformat), userid) return getsomehonks(rows, err) } +func gethonksforme(userid int64) []*Honk { + dt := time.Now().UTC().Add(-2 * 24 * time.Hour) + rows, err := stmtHonksForMe.Query(userid, dt.Format(dbtimeformat), userid) + return getsomehonks(rows, err) +} func gethonksbyhonker(userid int64, honker string) []*Honk { rows, err := stmtHonksByHonker.Query(userid, honker) return getsomehonks(rows, err)

@@ -687,9 +696,15 @@ Donks: xonk.Donks,

Audience: oneofakind(prepend(thewholeworld, xonk.Audience)), } + user, _ := butwhatabout(userinfo.Username) + aud := strings.Join(bonk.Audience, " ") + whofore := 0 + if strings.Contains(aud, user.URL) { + whofore = 1 + } res, err := stmtSaveHonk.Exec(userinfo.UserID, "bonk", "", xid, "", - dt.Format(dbtimeformat), "", aud, bonk.Noise, bonk.Convoy) + dt.Format(dbtimeformat), "", aud, bonk.Noise, bonk.Convoy, whofore) if err != nil { log.Printf("error saving bonk: %s", err) return

@@ -702,8 +717,6 @@ log.Printf("err saving donk: %s", err)

return } } - - user, _ := butwhatabout(userinfo.Username) go honkworldwide(user, &bonk)

@@ -827,9 +840,15 @@ honk.Donks = append(honk.Donks, donk)

} } + user, _ := butwhatabout(userinfo.Username) + aud := strings.Join(honk.Audience, " ") + whofore := 0 + if strings.Contains(aud, user.URL) { + whofore = 1 + } res, err := stmtSaveHonk.Exec(userinfo.UserID, what, "", xid, rid, - dt.Format(dbtimeformat), "", aud, noise, convoy) + dt.Format(dbtimeformat), "", aud, noise, convoy, whofore) if err != nil { log.Printf("error saving honk: %s", err) return

@@ -842,8 +861,6 @@ log.Printf("err saving donk: %s", err)

return } } - - user, _ := butwhatabout(userinfo.Username) go honkworldwide(user, &honk)

@@ -1015,6 +1032,7 @@ posters := mux.Methods("POST").Subrouter()

getters := mux.Methods("GET").Subrouter() getters.HandleFunc("/", homepage) + getters.Handle("/atme", LoginRequired(http.HandlerFunc(homepage))) getters.HandleFunc("/rss", showrss) getters.HandleFunc("/u/{name:[[:alnum:]]+}", viewuser) getters.HandleFunc("/u/{name:[[:alnum:]]+}/h/{xid:[[:alnum:]]+}", viewhonk)

@@ -1049,7 +1067,7 @@ }

} var stmtHonkers, stmtDubbers, stmtOneXonk, stmtHonks, stmtUserHonks *sql.Stmt -var stmtHonksForUser, stmtDeleteHonk, stmtSaveDub *sql.Stmt +var stmtHonksForUser, stmtHonksForMe, stmtDeleteHonk, stmtSaveDub *sql.Stmt var stmtHonksByHonker, stmtSaveHonk, stmtFileData, stmtWhatAbout *sql.Stmt var stmtFindXonk, stmtSaveDonk, stmtFindFile, stmtSaveFile *sql.Stmt var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover *sql.Stmt

@@ -1070,8 +1088,9 @@ stmtOneXonk = preparetodie(db, "select honkid, honks.userid, users.username, what, honker, xid, rid, dt, url, audience, noise, convoy from honks join users on honks.userid = users.userid where xid = ?")

stmtHonks = preparetodie(db, "select honkid, honks.userid, users.username, what, honker, xid, rid, dt, url, audience, noise, convoy from honks join users on honks.userid = users.userid where honker = '' order by honkid desc limit 50") stmtUserHonks = preparetodie(db, "select honkid, honks.userid, username, what, honker, xid, rid, dt, url, audience, noise, convoy from honks join users on honks.userid = users.userid where honker = '' and username = ? order by honkid desc limit 50") stmtHonksForUser = preparetodie(db, "select honkid, honks.userid, users.username, what, honker, xid, rid, dt, url, audience, noise, convoy from honks join users on honks.userid = users.userid where honks.userid = ? and dt > ? and convoy not in (select name from zonkers where userid = ? and wherefore = 'zonvoy' order by zonkerid desc limit 100) order by honkid desc limit 250") + stmtHonksForMe = preparetodie(db, "select honkid, honks.userid, users.username, what, honker, xid, rid, dt, url, audience, noise, convoy from honks join users on honks.userid = users.userid where honks.userid = ? and dt > ? and whofore = 1 and convoy not in (select name from zonkers where userid = ? and wherefore = 'zonvoy' order by zonkerid desc limit 100) order by honkid desc limit 250") stmtHonksByHonker = preparetodie(db, "select honkid, honks.userid, users.username, what, honker, honks.xid, rid, dt, url, audience, noise, convoy from honks join users on honks.userid = users.userid join honkers on honkers.xid = honks.honker where honks.userid = ? and honkers.name = ? order by honkid desc limit 50") - stmtSaveHonk = preparetodie(db, "insert into honks (userid, what, honker, xid, rid, dt, url, audience, noise, convoy) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") + stmtSaveHonk = preparetodie(db, "insert into honks (userid, what, honker, xid, rid, dt, url, audience, noise, convoy, whofore) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") stmtFileData = preparetodie(db, "select media, content from files where xid = ?") stmtFindXonk = preparetodie(db, "select honkid from honks where userid = ? and xid = ?") stmtSaveDonk = preparetodie(db, "insert into donks (honkid, fileid) values (?, ?)")
M schema.sqlschema.sql

@@ -1,5 +1,5 @@

-create table honks (honkid integer primary key, userid integer, what text, honker text, xid text, rid text, dt text, url text, audience text, noise text, convoy text); +create table honks (honkid integer primary key, userid integer, what text, honker text, xid text, rid text, dt text, url text, audience text, noise text, convoy text, whofore integer); create table donks (honkid integer, fileid integer); create table files(fileid integer primary key, xid text, name text, url text, media text, content blob); create table honkers (honkerid integer primary key, userid integer, name text, xid text, flavor text, pubkey text);
M upgradedb.goupgradedb.go

@@ -54,6 +54,12 @@ doordie(db, "create index idx_zonkersname on zonkers(name)")

doordie(db, "update config set value = 3 where key = 'dbversion'") fallthrough case 3: + doordie(db, "alter table honks add column whofore integer") + doordie(db, "update honks set whofore = 0") + doordie(db, "update honks set whofore = 1 where honkid in (select honkid from honks join users on honks.userid = users.userid where instr(audience, username) > 0)") + doordie(db, "update config set value = 4 where key = 'dbversion'") + fallthrough + case 4: default: log.Fatalf("can't upgrade unknown version %d", dbversion) }
M util.goutil.go

@@ -70,7 +70,7 @@

var alreadyopendb *sql.DB var dbname = "honk.db" var stmtConfig *sql.Stmt -var myVersion = 3 +var myVersion = 4 func initdb() { schema, err := ioutil.ReadFile("schema.sql")
M views/header.htmlviews/header.html

@@ -12,14 +12,15 @@ </head>

<body> <div class="header"> <span><a href="/">honk</a></span> -{{ if .ShowRSS }} -<span><a href="/rss">rss</a></span> -{{ end }} {{ if .UserInfo }} +<span><a href="/atme">@me</a></span> <span><a href="/u/{{ .UserInfo.Username }}">{{ .UserInfo.Username }}</a></span> <span><a href="/honkers">honkers</a></span> <span><a href="/logout?CSRF={{ .LogoutCSRF }}">logout</a></span> {{ else }} <span><a href="/login">login</a></span> +{{ end }} +{{ if .ShowRSS }} +<span><a href="/rss">rss</a></span> {{ end }} </div>