add combos for the micromanagement of friends
This commit is contained in:
parent
0bc4ea427f
commit
cf9a144a6c
53
honk.go
53
honk.go
|
@ -33,6 +33,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -86,6 +87,7 @@ type Honker struct {
|
||||||
Name string
|
Name string
|
||||||
XID string
|
XID string
|
||||||
Flavor string
|
Flavor string
|
||||||
|
Combos []string
|
||||||
}
|
}
|
||||||
|
|
||||||
var serverName string
|
var serverName string
|
||||||
|
@ -423,6 +425,13 @@ func viewhonker(w http.ResponseWriter, r *http.Request) {
|
||||||
honkpage(w, r, nil, nil, honks)
|
honkpage(w, r, nil, nil, honks)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func viewcombo(w http.ResponseWriter, r *http.Request) {
|
||||||
|
name := mux.Vars(r)["name"]
|
||||||
|
u := GetUserInfo(r)
|
||||||
|
honks := gethonksbycombo(u.UserID, name)
|
||||||
|
honkpage(w, r, nil, nil, honks)
|
||||||
|
}
|
||||||
|
|
||||||
func fingerlicker(w http.ResponseWriter, r *http.Request) {
|
func fingerlicker(w http.ResponseWriter, r *http.Request) {
|
||||||
orig := r.FormValue("resource")
|
orig := r.FormValue("resource")
|
||||||
|
|
||||||
|
@ -542,7 +551,9 @@ func gethonkers(userid int64) []*Honker {
|
||||||
var honkers []*Honker
|
var honkers []*Honker
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var f Honker
|
var f Honker
|
||||||
err = rows.Scan(&f.ID, &f.UserID, &f.Name, &f.XID, &f.Flavor)
|
var combos string
|
||||||
|
err = rows.Scan(&f.ID, &f.UserID, &f.Name, &f.XID, &f.Flavor, &combos)
|
||||||
|
f.Combos = strings.Split(strings.TrimSpace(combos), " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error scanning honker: %s", err)
|
log.Printf("error scanning honker: %s", err)
|
||||||
return nil
|
return nil
|
||||||
|
@ -616,6 +627,11 @@ func gethonksbyhonker(userid int64, honker string) []*Honk {
|
||||||
rows, err := stmtHonksByHonker.Query(userid, honker)
|
rows, err := stmtHonksByHonker.Query(userid, honker)
|
||||||
return getsomehonks(rows, err)
|
return getsomehonks(rows, err)
|
||||||
}
|
}
|
||||||
|
func gethonksbycombo(userid int64, combo string) []*Honk {
|
||||||
|
combo = "% " + combo + " %"
|
||||||
|
rows, err := stmtHonksByCombo.Query(userid, combo)
|
||||||
|
return getsomehonks(rows, err)
|
||||||
|
}
|
||||||
|
|
||||||
func getsomehonks(rows *sql.Rows, err error) []*Honk {
|
func getsomehonks(rows *sql.Rows, err error) []*Honk {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -874,7 +890,7 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
|
|
||||||
func showhonkers(w http.ResponseWriter, r *http.Request) {
|
func viewhonkers(w http.ResponseWriter, r *http.Request) {
|
||||||
userinfo := GetUserInfo(r)
|
userinfo := GetUserInfo(r)
|
||||||
templinfo := getInfo(r)
|
templinfo := getInfo(r)
|
||||||
templinfo["Honkers"] = gethonkers(userinfo.UserID)
|
templinfo["Honkers"] = gethonkers(userinfo.UserID)
|
||||||
|
@ -926,14 +942,27 @@ func gofish(name string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func savehonker(w http.ResponseWriter, r *http.Request) {
|
func savehonker(w http.ResponseWriter, r *http.Request) {
|
||||||
|
u := GetUserInfo(r)
|
||||||
name := r.FormValue("name")
|
name := r.FormValue("name")
|
||||||
url := r.FormValue("url")
|
url := r.FormValue("url")
|
||||||
peep := r.FormValue("peep")
|
peep := r.FormValue("peep")
|
||||||
|
combos := r.FormValue("combos")
|
||||||
|
honkerid, _ := strconv.ParseInt(r.FormValue("honkerid"), 10, 0)
|
||||||
|
|
||||||
|
if honkerid > 0 {
|
||||||
|
combos = " " + strings.TrimSpace(combos) + " "
|
||||||
|
_, err := stmtUpdateHonker.Exec(combos, honkerid, u.UserID)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("update honker err: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
http.Redirect(w, r, "/honkers", http.StatusSeeOther)
|
||||||
|
}
|
||||||
|
|
||||||
flavor := "presub"
|
flavor := "presub"
|
||||||
if peep == "peep" {
|
if peep == "peep" {
|
||||||
flavor = "peep"
|
flavor = "peep"
|
||||||
}
|
}
|
||||||
|
|
||||||
if url == "" {
|
if url == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -943,13 +972,10 @@ func savehonker(w http.ResponseWriter, r *http.Request) {
|
||||||
if url == "" {
|
if url == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
_, err := stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos)
|
||||||
u := GetUserInfo(r)
|
|
||||||
db := opendatabase()
|
|
||||||
_, err := db.Exec("insert into honkers (userid, name, xid, flavor) values (?, ?, ?, ?)",
|
|
||||||
u.UserID, name, url, flavor)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if flavor == "presub" {
|
if flavor == "presub" {
|
||||||
user, _ := butwhatabout(u.Username)
|
user, _ := butwhatabout(u.Username)
|
||||||
|
@ -1115,8 +1141,9 @@ func serve() {
|
||||||
loggedin.Handle("/zonkit", CSRFWrap("honkhonk", http.HandlerFunc(zonkit)))
|
loggedin.Handle("/zonkit", CSRFWrap("honkhonk", http.HandlerFunc(zonkit)))
|
||||||
loggedin.Handle("/killitwithfire", CSRFWrap("killitwithfire", http.HandlerFunc(killitwithfire)))
|
loggedin.Handle("/killitwithfire", CSRFWrap("killitwithfire", http.HandlerFunc(killitwithfire)))
|
||||||
loggedin.Handle("/saveuser", CSRFWrap("saveuser", http.HandlerFunc(saveuser)))
|
loggedin.Handle("/saveuser", CSRFWrap("saveuser", http.HandlerFunc(saveuser)))
|
||||||
loggedin.HandleFunc("/honkers", showhonkers)
|
loggedin.HandleFunc("/honkers", viewhonkers)
|
||||||
loggedin.HandleFunc("/h/{name:[[:alnum:]]+}", viewhonker)
|
loggedin.HandleFunc("/h/{name:[[:alnum:]]+}", viewhonker)
|
||||||
|
loggedin.HandleFunc("/c/{name:[[:alnum:]]+}", viewcombo)
|
||||||
loggedin.Handle("/savehonker", CSRFWrap("savehonker", http.HandlerFunc(savehonker)))
|
loggedin.Handle("/savehonker", CSRFWrap("savehonker", http.HandlerFunc(savehonker)))
|
||||||
|
|
||||||
err = http.Serve(listener, mux)
|
err = http.Serve(listener, mux)
|
||||||
|
@ -1125,7 +1152,8 @@ func serve() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var stmtHonkers, stmtDubbers, stmtOneXonk, stmtHonks, stmtUserHonks *sql.Stmt
|
var stmtHonkers, stmtDubbers, stmtSaveHonker, stmtUpdateHonker *sql.Stmt
|
||||||
|
var stmtOneXonk, stmtHonks, stmtUserHonks, stmtHonksByCombo *sql.Stmt
|
||||||
var stmtHonksForUser, stmtHonksForMe, stmtDeleteHonk, stmtSaveDub *sql.Stmt
|
var stmtHonksForUser, stmtHonksForMe, stmtDeleteHonk, stmtSaveDub *sql.Stmt
|
||||||
var stmtHonksByHonker, stmtSaveHonk, stmtFileData, stmtWhatAbout *sql.Stmt
|
var stmtHonksByHonker, stmtSaveHonk, stmtFileData, stmtWhatAbout *sql.Stmt
|
||||||
var stmtFindXonk, stmtSaveDonk, stmtFindFile, stmtSaveFile *sql.Stmt
|
var stmtFindXonk, stmtSaveDonk, stmtFindFile, stmtSaveFile *sql.Stmt
|
||||||
|
@ -1141,7 +1169,9 @@ func preparetodie(db *sql.DB, s string) *sql.Stmt {
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareStatements(db *sql.DB) {
|
func prepareStatements(db *sql.DB) {
|
||||||
stmtHonkers = preparetodie(db, "select honkerid, userid, name, xid, flavor from honkers where userid = ? and flavor = 'sub' or flavor = 'peep'")
|
stmtHonkers = preparetodie(db, "select honkerid, userid, name, xid, flavor, combos from honkers where userid = ? and flavor = 'sub' or flavor = 'peep'")
|
||||||
|
stmtSaveHonker = preparetodie(db, "insert into honkers (userid, name, xid, flavor, combos) values (?, ?, ?, ?, ?)")
|
||||||
|
stmtUpdateHonker = preparetodie(db, "update honkers set combos = ? where honkerid = ? and userid = ?")
|
||||||
stmtDubbers = preparetodie(db, "select honkerid, userid, name, xid, flavor from honkers where userid = ? and flavor = 'dub'")
|
stmtDubbers = preparetodie(db, "select honkerid, userid, name, xid, flavor from honkers where userid = ? and flavor = 'dub'")
|
||||||
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 = ?")
|
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")
|
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")
|
||||||
|
@ -1149,6 +1179,7 @@ func prepareStatements(db *sql.DB) {
|
||||||
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")
|
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")
|
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")
|
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")
|
||||||
|
stmtHonksByCombo = 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.combos like ? order by honkid desc limit 50")
|
||||||
stmtSaveHonk = preparetodie(db, "insert into honks (userid, what, honker, xid, rid, dt, url, audience, noise, convoy, whofore) 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 = ?")
|
stmtFileData = preparetodie(db, "select media, content from files where xid = ?")
|
||||||
stmtFindXonk = preparetodie(db, "select honkid from honks where userid = ? and xid = ?")
|
stmtFindXonk = preparetodie(db, "select honkid from honks where userid = ? and xid = ?")
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
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 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 donks (honkid integer, fileid integer);
|
||||||
create table files(fileid integer primary key, xid text, name text, url text, media text, content blob);
|
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);
|
create table honkers (honkerid integer primary key, userid integer, name text, xid text, flavor text, combos text, pubkey text);
|
||||||
create table xonkers (xonkerid integer primary key, xid text, ibox text, obox text, sbox text, pubkey text);
|
create table xonkers (xonkerid integer primary key, xid text, ibox text, obox text, sbox text, pubkey text);
|
||||||
create table zonkers (zonkerid integer primary key, userid integer, name text, wherefore text);
|
create table zonkers (zonkerid integer primary key, userid integer, name text, wherefore text);
|
||||||
create table doovers(dooverid integer primary key, dt text, tries integer, username text, rcpt text, msg blob);
|
create table doovers(dooverid integer primary key, dt text, tries integer, username text, rcpt text, msg blob);
|
||||||
|
|
|
@ -60,6 +60,11 @@ func upgradedb() {
|
||||||
doordie(db, "update config set value = 4 where key = 'dbversion'")
|
doordie(db, "update config set value = 4 where key = 'dbversion'")
|
||||||
fallthrough
|
fallthrough
|
||||||
case 4:
|
case 4:
|
||||||
|
doordie(db, "alter table honkers add column combos text")
|
||||||
|
doordie(db, "update honkers set combos = ''")
|
||||||
|
doordie(db, "update config set value = 5 where key = 'dbversion'")
|
||||||
|
fallthrough
|
||||||
|
case 5:
|
||||||
default:
|
default:
|
||||||
log.Fatalf("can't upgrade unknown version %d", dbversion)
|
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 alreadyopendb *sql.DB
|
||||||
var dbname = "honk.db"
|
var dbname = "honk.db"
|
||||||
var stmtConfig *sql.Stmt
|
var stmtConfig *sql.Stmt
|
||||||
var myVersion = 4
|
var myVersion = 5
|
||||||
|
|
||||||
func initdb() {
|
func initdb() {
|
||||||
schema, err := ioutil.ReadFile("schema.sql")
|
schema, err := ioutil.ReadFile("schema.sql")
|
||||||
|
|
|
@ -12,14 +12,19 @@
|
||||||
<p><input tabindex=1 type="submit" name="add honker" value="add honker">
|
<p><input tabindex=1 type="submit" name="add honker" value="add honker">
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
{{ $honkercsrf := .HonkerCSRF }}
|
||||||
{{ range .Honkers }}
|
{{ range .Honkers }}
|
||||||
<div class="honk" id="honker{{ .ID }}">
|
<form action="/savehonker" method="POST" class="honk">
|
||||||
<p>
|
<input type="hidden" name="CSRF" value="{{ $honkercsrf }}">
|
||||||
<span class="linktitle">{{ .Name }}</span>
|
<input type="hidden" name="honkerid" value="{{ .ID }}">
|
||||||
|
<p>name: {{ .Name }}
|
||||||
<p>url: {{ .XID }}
|
<p>url: {{ .XID }}
|
||||||
<p><a href="/h/{{ .Name }}">honks</a>
|
|
||||||
<p>flavor: {{ .Flavor }}
|
<p>flavor: {{ .Flavor }}
|
||||||
</div>
|
<p><a href="/h/{{ .Name }}">honks</a>
|
||||||
|
<p>combos:{{ range .Combos }} <a href="/c/{{ . }}">{{ . }}</a>{{ end }}
|
||||||
|
<p>combos: <input type="text" name="combos" value="{{ range .Combos }}{{ . }} {{end}}">
|
||||||
|
<p><input type="submit" name="save" value="save">
|
||||||
|
</form>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue