all repos — honk @ f147a779c3f346118c604ab5f0e29c6babb76f23

my fork of honk

beta/prototype of Update
Ted Unangst tedu@tedunangst.com
Mon, 16 Sep 2019 18:00:13 -0400
commit

f147a779c3f346118c604ab5f0e29c6babb76f23

parent

96116fdb4d4c9da30ff3c5bbd6a41c745276b67c

M activity.goactivity.go

@@ -464,6 +464,7 @@ var err error

var xid, rid, url, content, precis, convoy, oonker string var obj junk.Junk var ok bool + isUpdate := false switch what { case "Announce": obj, ok = item.GetMap("object")

@@ -482,6 +483,10 @@ log.Printf("error getting bonk: %s: %s", xid, err)

} origin = originate(xid) what = "bonk" + case "Update": + log.Printf("should be updating") + isUpdate = true + fallthrough case "Create": obj, ok = item.GetMap("object") if !ok {

@@ -695,6 +700,19 @@ xonk.Whofore = 1

} } + if isUpdate { + prev := getxonk(user.ID, xonk.XID) + if prev == nil { + log.Printf("didn't find old version for update: %s", xonk.XID) + return nil + } + prev.Noise = xonk.Noise + prev.Precis = xonk.Precis + prev.Date = xonk.Date + updatehonk(prev) + return nil + } + if needxonk(user, &xonk) { if rid != "" { if needxonkid(user, rid) {

@@ -789,10 +807,16 @@ j["cc"] = h.Audience[1:]

} switch h.What { + case "update": + fallthrough case "tonk": fallthrough case "honk": - j["type"] = "Create" + if h.What == "update" { + j["type"] = "Update" + } else { + j["type"] = "Create" + } jo = junk.New() jo["id"] = h.XID
M database.godatabase.go

@@ -239,15 +239,20 @@ log.Printf("err saving honk: %s", err)

return err } h.ID, _ = res.LastInsertId() + err = saveextras(h) + return err +} + +func saveextras(h *Honk) error { for _, d := range h.Donks { - _, err = stmtSaveDonk.Exec(h.ID, d.FileID) + _, err := stmtSaveDonk.Exec(h.ID, d.FileID) if err != nil { log.Printf("err saving donk: %s", err) return err } } for _, o := range h.Onts { - _, err = stmtSaveOnt.Exec(strings.ToLower(o), h.ID) + _, err := stmtSaveOnt.Exec(strings.ToLower(o), h.ID) if err != nil { log.Printf("error saving ont: %s", err) return err

@@ -256,7 +261,7 @@ }

return nil } -func deletehonk(honkid int64) { +func deleteextras(honkid int64) { _, err := stmtDeleteDonks.Exec(honkid) if err != nil { log.Printf("error deleting: %s", err)

@@ -265,12 +270,31 @@ _, err = stmtDeleteOnts.Exec(honkid)

if err != nil { log.Printf("error deleting: %s", err) } - _, err = stmtDeleteHonk.Exec(honkid) +} + +func deletehonk(honkid int64) { + deleteextras(honkid) + _, err := stmtDeleteHonk.Exec(honkid) if err != nil { log.Printf("error deleting: %s", err) } } +func updatehonk(h *Honk) { + old := getxonk(h.UserID, h.XID) + _, err := stmtSaveOld.Exec(old.ID, old.Precis, old.Noise) + if err != nil { + log.Printf("error saving old: %s", err) + return + } + deleteextras(h.ID) + + dt := h.Date.UTC().Format(dbtimeformat) + stmtUpdateHonk.Exec(h.Precis, h.Noise, dt, h.ID) + + saveextras(h) +} + func cleanupdb(arg string) { db := opendatabase() days, err := strconv.Atoi(arg)

@@ -299,6 +323,7 @@ var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover, stmtOneHonker *sql.Stmt

var stmtThumbBiters, stmtDeleteHonk, stmtDeleteDonks, stmtDeleteOnts, stmtSaveZonker *sql.Stmt var stmtGetZonkers, stmtRecentHonkers, stmtGetXonker, stmtSaveXonker, stmtDeleteXonker *sql.Stmt var stmtSelectOnts, stmtSaveOnt, stmtUpdateFlags, stmtClearFlags *sql.Stmt +var stmtSaveOld, stmtUpdateHonk *sql.Stmt func preparetodie(db *sql.DB, s string) *sql.Stmt { stmt, err := db.Prepare(s)

@@ -332,8 +357,10 @@ stmtHonksBySearch = preparetodie(db, selecthonks+"where honks.userid = ? and noise like ?"+limit)

stmtHonksByConvoy = preparetodie(db, selecthonks+"where (honks.userid = ? or (? = -1 and whofore = 2)) and convoy = ?"+limit) stmtHonksByOntology = preparetodie(db, selecthonks+"join onts on honks.honkid = onts.honkid where onts.ontology = ? and (honks.userid = ? or (? = -1 and honks.whofore = 2))"+limit) + stmtSaveOld = preparetodie(db, "insert into forsaken (honkid, precis, noise) values (?, ?, ?)") stmtSaveHonk = preparetodie(db, "insert into honks (userid, what, honker, xid, rid, dt, url, audience, noise, convoy, whofore, format, precis, oonker, flags, onts) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") stmtDeleteHonk = preparetodie(db, "delete from honks where honkid = ?") + stmtUpdateHonk = preparetodie(db, "update honks set precis = ?, noise = ?, dt = ? where honkid = ?") stmtSaveOnt = preparetodie(db, "insert into onts (ontology, honkid) values (?, ?)") stmtDeleteOnts = preparetodie(db, "delete from onts where honkid = ?") stmtSaveDonk = preparetodie(db, "insert into donks (honkid, fileid) values (?, ?)")
M docs/changelog.txtdocs/changelog.txt

@@ -2,6 +2,8 @@ changelog

-- next ++++ Editing honks (Update activity). + + Quick mention @alias. + Image descriptions.
M schema.sqlschema.sql

@@ -7,6 +7,7 @@ create table xonkers (xonkerid integer primary key, name text, info text, flavor 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 onts (ontology text, honkid integer); +create table forsaken (honkid integer, precis text, noise text); create index idx_honksxid on honks(xid); create index idx_honksconvoy on honks(convoy);
M upgradedb.goupgradedb.go

@@ -189,6 +189,10 @@ doordie(db, "update files set description = name")

doordie(db, "update config set value = 17 where key = 'dbversion'") fallthrough case 17: + doordie(db, "create table forsaken (xid text, noise text)") + doordie(db, "update config set value = 18 where key = 'dbversion'") + fallthrough + case 18: default: log.Fatalf("can't upgrade unknown version %d", dbversion) }
M util.goutil.go

@@ -72,7 +72,7 @@

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

@@ -87,6 +87,7 @@ <button onclick="deackit(this, '{{ .Honk.XID }}');">deack</button>

{{ else }} <button onclick="ackit(this, '{{ .Honk.XID }}');">ack</button> {{ end }} +<button><a href="/edit?xid={{ .Honk.XID }}">edit</a></button> </div> </details> <p>
M views/honkform.htmlviews/honkform.html

@@ -4,6 +4,7 @@ <form id="honkform" action="/honk" method="POST" enctype="multipart/form-data" style="display: none">

<p> in reply to: <input type="text" name="rid" id="ridinput" value="{{ .InReplyTo }}" autocomplete=off> <input type="hidden" name="CSRF" value="{{ .HonkCSRF }}"> +<input type="hidden" name="updatexid" value = "{{ .UpdateXID }}"> <p> <label id="donker">attach: {{ if .SavedFile }} {{ .SavedFile }} {{ else }} <input onchange="updatedonker();" type="file" name="donk"><span></span> {{ end }}</label> <input type="hidden" name="donkxid" value="{{ .SavedFile }}">
M web.goweb.go

@@ -348,6 +348,9 @@ case "Person":

return case "Question": return + case "Note": + go consumeactivity(user, j, origin) + return } } log.Printf("unknown Update activity")

@@ -822,6 +825,30 @@ return

} } +func edithonkpage(w http.ResponseWriter, r *http.Request) { + u := login.GetUserInfo(r) + user, _ := butwhatabout(u.Username) + xid := r.FormValue("xid") + honk := getxonk(u.UserID, xid) + if honk == nil || honk.Honker != user.URL || honk.What != "honk" { + log.Printf("no edit") + return + } + + honks := []*Honk{honk} + reverbolate(u.UserID, honks) + templinfo := getInfo(r) + templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r) + templinfo["Honks"] = honks + templinfo["Noise"] = honk.Noise + templinfo["ServerMessage"] = "honk edit" + templinfo["UpdateXID"] = honk.XID + err := readviews.Execute(w, "honkpage.html", templinfo) + if err != nil { + log.Print(err) + } +} + func submithonk(w http.ResponseWriter, r *http.Request) { rid := r.FormValue("rid") noise := r.FormValue("noise")

@@ -830,18 +857,30 @@ userinfo := login.GetUserInfo(r)

user, _ := butwhatabout(userinfo.Username) dt := time.Now().UTC() - xid := fmt.Sprintf("%s/%s/%s", user.URL, honkSep, xfiltrate()) - what := "honk" - if rid != "" { - what = "tonk" - } - honk := Honk{ - UserID: userinfo.UserID, - Username: userinfo.Username, - What: "honk", - Honker: user.URL, - XID: xid, - Date: dt, + updatexid := r.FormValue("updatexid") + var honk *Honk + if updatexid != "" { + honk = getxonk(userinfo.UserID, updatexid) + if honk == nil || honk.Honker != user.URL || honk.What != "honk" { + log.Printf("not saving edit") + return + } + honk.Date = dt + honk.What = "update" + } else { + xid := fmt.Sprintf("%s/%s/%s", user.URL, honkSep, xfiltrate()) + what := "honk" + if rid != "" { + what = "tonk" + } + honk = &Honk{ + UserID: userinfo.UserID, + Username: userinfo.Username, + What: what, + Honker: user.URL, + XID: xid, + Date: dt, + } } if strings.HasPrefix(noise, "DZ:") { idx := strings.Index(noise, "\n")

@@ -977,7 +1016,7 @@ donk.Name = e.Name

honk.Donks = append(honk.Donks, donk) } } - memetize(&honk) + memetize(honk) if honk.Public { honk.Whofore = 2

@@ -985,7 +1024,7 @@ } else {

honk.Whofore = 3 } if r.FormValue("preview") == "preview" { - honks := []*Honk{&honk} + honks := []*Honk{honk} reverbolate(userinfo.UserID, honks) templinfo := getInfo(r) templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)

@@ -1002,26 +1041,30 @@ return

} honk.Onts = oneofakind(ontologies(honk.Noise)) honk.UserID = userinfo.UserID - honk.What = what - honk.XID = xid honk.RID = rid honk.Date = dt honk.Convoy = convoy honk.Format = "html" - err := savehonk(&honk) - if err != nil { - log.Printf("uh oh") - return + if updatexid != "" { + updatehonk(honk) + + } else { + + err := savehonk(honk) + if err != nil { + log.Printf("uh oh") + return + } } // reload for consistency honk.Donks = nil - donksforhonks([]*Honk{&honk}) + donksforhonks([]*Honk{honk}) - go honkworldwide(user, &honk) + go honkworldwide(user, honk) - http.Redirect(w, r, xid, http.StatusSeeOther) + http.Redirect(w, r, honk.XID, http.StatusSeeOther) } func showhonkers(w http.ResponseWriter, r *http.Request) {

@@ -1451,6 +1494,7 @@ loggedin.HandleFunc("/chpass", dochpass)

loggedin.HandleFunc("/atme", homepage) loggedin.HandleFunc("/zonkzone", zonkzone) loggedin.HandleFunc("/xzone", xzone) + loggedin.HandleFunc("/edit", edithonkpage) loggedin.Handle("/honk", login.CSRFWrap("honkhonk", http.HandlerFunc(submithonk))) loggedin.Handle("/bonk", login.CSRFWrap("honkhonk", http.HandlerFunc(submitbonk))) loggedin.Handle("/zonkit", login.CSRFWrap("honkhonk", http.HandlerFunc(zonkit)))