@me page just for me
This commit is contained in:
parent
e8c5a307ce
commit
770e57797e
11
activity.go
11
activity.go
|
@ -243,7 +243,7 @@ func needxonk(user *WhatAbout, x *Honk) bool {
|
|||
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 @@ func savexonk(x *Honk) {
|
|||
}
|
||||
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 @@ func peeppeep() {
|
|||
xonk := xonkxonk(item)
|
||||
if xonk != nil && needxonk(user, xonk) {
|
||||
xonk.UserID = user.ID
|
||||
savexonk(xonk)
|
||||
savexonk(user, xonk)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
39
honk.go
39
honk.go
|
@ -109,7 +109,11 @@ func homepage(w http.ResponseWriter, r *http.Request) {
|
|||
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 @@ func inbox(w http.ResponseWriter, r *http.Request) {
|
|||
xonk := xonkxonk(j)
|
||||
if xonk != nil && needxonk(user, xonk) {
|
||||
xonk.UserID = user.ID
|
||||
savexonk(xonk)
|
||||
savexonk(user, xonk)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -596,6 +600,11 @@ func gethonksforuser(userid int64) []*Honk {
|
|||
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 @@ func savebonk(w http.ResponseWriter, r *http.Request) {
|
|||
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
|
||||
|
@ -703,8 +718,6 @@ func savebonk(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
user, _ := butwhatabout(userinfo.Username)
|
||||
|
||||
go honkworldwide(user, &bonk)
|
||||
|
||||
}
|
||||
|
@ -827,9 +840,15 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -843,8 +862,6 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
user, _ := butwhatabout(userinfo.Username)
|
||||
|
||||
go honkworldwide(user, &honk)
|
||||
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
|
@ -1015,6 +1032,7 @@ func serve() {
|
|||
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 @@ func serve() {
|
|||
}
|
||||
|
||||
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 @@ func prepareStatements(db *sql.DB) {
|
|||
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 (?, ?)")
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -54,6 +54,12 @@ func upgradedb() {
|
|||
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)
|
||||
}
|
||||
|
|
2
util.go
2
util.go
|
@ -70,7 +70,7 @@ var dbtimeformat = "2006-01-02 15:04:05"
|
|||
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")
|
||||
|
|
|
@ -12,14 +12,15 @@
|
|||
<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>
|
||||
|
|
Loading…
Reference in New Issue