all repos — honk @ ed39930ffa00f8e100cc6bebab578c03b34e58d6

my fork of honk

rework honk schema to store more information.
add original honker for bonks.
add separate precis field for summary.
add format to prepare for changing how html is saved.
Ted Unangst tedu@tedunangst.com
Wed, 15 May 2019 16:27:50 -0400
commit

ed39930ffa00f8e100cc6bebab578c03b34e58d6

parent

1d049e80a8a03d7b9b3ff17bdc92cf6bd2a5e9da

7 files changed, 61 insertions(+), 36 deletions(-)

jump to
M activity.goactivity.go

@@ -292,7 +292,7 @@ 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) + x.Noise, x.Convoy, whofore, "html", x.Precis, x.Oonker) if err != nil { log.Printf("err saving xonk: %s", err) return

@@ -463,7 +463,7 @@ dt, _ := jsongetstring(item, "published")

var audience []string var err error - var xid, rid, url, content, convoy string + var xid, rid, url, content, precis, convoy, oonker string var obj map[string]interface{} var ok bool switch what {

@@ -511,19 +511,17 @@ if obj != nil {

if who == "" { who, _ = jsongetstring(obj, "attributedTo") } + oonker, _ = jsongetstring(obj, "attributedTo") ot, _ := jsongetstring(obj, "type") url, _ = jsongetstring(obj, "url") if ot == "Note" || ot == "Article" || ot == "Page" { audience = newphone(audience, obj) xid, _ = jsongetstring(obj, "id") + precis, _ = jsongetstring(obj, "summary") content, _ = jsongetstring(obj, "content") - summary, _ := jsongetstring(obj, "summary") if !strings.HasPrefix(content, "<p>") { content = "<p>" + content } - if summary != "" { - content = "<p>summary: " + summary + content - } rid, _ = jsongetstring(obj, "inReplyTo") convoy, _ = jsongetstring(obj, "context") if convoy == "" {

@@ -582,6 +580,9 @@ audience = append(audience, who)

audience = oneofakind(audience) + if oonker == who { + oonker = "" + } xonk.UserID = user.ID xonk.What = what xonk.Honker = who

@@ -590,8 +591,10 @@ xonk.RID = rid

xonk.Date, _ = time.Parse(time.RFC3339, dt) xonk.URL = url xonk.Noise = content + xonk.Precis = precis xonk.Audience = audience xonk.Convoy = convoy + xonk.Oonker = oonker if needxonk(user, &xonk) { if what == "tonk" {

@@ -721,22 +724,10 @@ jo["to"] = h.Audience[0]

if len(h.Audience) > 1 { jo["cc"] = h.Audience[1:] } - if strings.HasPrefix(h.Noise, "DZ:") { - // alas, it's already been turned into html - idx := strings.Index(h.Noise, "<br>") - if idx == -1 { - jo["summary"] = h.Noise - jo["content"] = "" - } else { - jo["summary"] = h.Noise[:idx] - if strings.HasPrefix(h.Noise[idx+4:], "<br>") { - idx += 4 - } - jo["content"] = mentionize(h.Noise[idx+4:]) - } + jo["summary"] = h.Precis + jo["content"] = mentionize(h.Noise) + if strings.HasPrefix(h.Precis, "DZ:") { jo["sensitive"] = true - } else { - jo["content"] = mentionize(h.Noise) } var tags []interface{} g := bunchofgrapes(h.Noise)
M fun.gofun.go

@@ -52,7 +52,11 @@ }

} zap := make(map[*Donk]bool) h.Noise = unpucker(h.Noise) - h.HTML = cleanstring(h.Noise) + precis := h.Precis + if precis != "" { + precis = "<p>summary: " + precis + "<p>" + } + h.HTML = cleanstring(precis + h.Noise) emuxifier := func(e string) string { for _, d := range h.Donks { if d.Name == e {
M honk.gohonk.go

@@ -55,11 +55,13 @@ UserID int64

Username string What string Honker string + Oonker string XID string RID string Date time.Time URL string Noise string + Precis string Convoy string Audience []string Privacy string

@@ -566,8 +568,8 @@ func getxonk(userid int64, xid string) *Honk {

h := new(Honk) var dt, aud string row := stmtOneXonk.QueryRow(userid, xid) - err := row.Scan(&h.ID, &h.UserID, &h.Username, &h.What, &h.Honker, &h.XID, &h.RID, - &dt, &h.URL, &aud, &h.Noise, &h.Convoy) + err := row.Scan(&h.ID, &h.UserID, &h.Username, &h.What, &h.Honker, &h.Oonker, &h.XID, &h.RID, + &dt, &h.URL, &aud, &h.Noise, &h.Precis, &h.Convoy) if err != nil { if err != sql.ErrNoRows { log.Printf("error scanning xonk: %s", err)

@@ -627,8 +629,8 @@ var honks []*Honk

for rows.Next() { var h Honk var dt, aud string - err = rows.Scan(&h.ID, &h.UserID, &h.Username, &h.What, &h.Honker, &h.XID, &h.RID, - &dt, &h.URL, &aud, &h.Noise, &h.Convoy) + err = rows.Scan(&h.ID, &h.UserID, &h.Username, &h.What, &h.Honker, &h.Oonker, + &h.XID, &h.RID, &dt, &h.URL, &aud, &h.Noise, &h.Precis, &h.Convoy) if err != nil { log.Printf("error scanning honks: %s", err) return nil

@@ -696,12 +698,9 @@ dt := time.Now().UTC()

bonk := Honk{ UserID: userinfo.UserID, Username: userinfo.Username, - Honker: xonk.Honker, What: "bonk", XID: xonk.XID, Date: dt, - Noise: xonk.Noise, - Convoy: xonk.Convoy, Donks: xonk.Donks, Audience: []string{thewholeworld}, }

@@ -714,7 +713,7 @@ if strings.Contains(aud, user.URL) {

whofore = 1 } res, err := stmtSaveHonk.Exec(userinfo.UserID, "bonk", "", xid, "", - dt.Format(dbtimeformat), "", aud, bonk.Noise, bonk.Convoy, whofore) + dt.Format(dbtimeformat), "", aud, xonk.Noise, xonk.Convoy, whofore, "html", xonk.Precis, xonk.Honker) if err != nil { log.Printf("error saving bonk: %s", err) return

@@ -797,6 +796,19 @@ What: "honk",

XID: xid, Date: dt, } + if strings.HasPrefix(noise, "DZ:") { + idx := strings.Index(noise, "\n") + if idx == -1 { + honk.Precis = noise + noise = "" + } else { + honk.Precis = noise[:idx] + noise = noise[idx+1:] + } + } + noise = strings.TrimSpace(noise) + honk.Precis = strings.TrimSpace(honk.Precis) + if noise != "" && noise[0] == '@' { honk.Audience = append(grapevine(noise), thewholeworld) } else {

@@ -807,7 +819,8 @@ if rid != "" {

xonk := getxonk(userinfo.UserID, rid) if xonk != nil { if xonk.Honker == "" { - rid = "https://" + serverName + "/u/" + xonk.Username + "/h/" + rid + xonk.Honker = "https://" + serverName + "/u/" + xonk.Username + rid = xonk.Honker + "/h/" + rid } honk.Audience = append(honk.Audience, xonk.Audience...) convoy = xonk.Convoy

@@ -816,6 +829,7 @@ xonkaud, c := whosthere(rid)

honk.Audience = append(honk.Audience, xonkaud...) convoy = c } + honk.Oonker = xonk.Honker honk.RID = rid } if convoy == "" {

@@ -897,7 +911,7 @@ if strings.Contains(aud, user.URL) {

whofore = 1 } res, err := stmtSaveHonk.Exec(userinfo.UserID, what, "", xid, rid, - dt.Format(dbtimeformat), "", aud, noise, convoy, whofore) + dt.Format(dbtimeformat), "", aud, noise, convoy, whofore, "html", honk.Precis, honk.Oonker) if err != nil { log.Printf("error saving honk: %s", err) return

@@ -1300,7 +1314,7 @@ stmtUpdateCombos = preparetodie(db, "update honkers set combos = ? where honkerid = ? and userid = ?")

stmtHasHonker = preparetodie(db, "select honkerid from honkers where xid = ? and userid = ?") stmtDubbers = preparetodie(db, "select honkerid, userid, name, xid, flavor from honkers where userid = ? and flavor = 'dub'") - selecthonks := "select honkid, honks.userid, username, what, honker, honks.xid, rid, dt, url, audience, noise, convoy from honks join users on honks.userid = users.userid " + selecthonks := "select honkid, honks.userid, username, what, honker, oonker, honks.xid, rid, dt, url, audience, noise, precis, convoy from honks join users on honks.userid = users.userid " limit := " order by honkid desc limit 250" butnotthose := " and convoy not in (select name from zonkers where userid = ? and wherefore = 'zonvoy' order by zonkerid desc limit 100)" stmtOneXonk = preparetodie(db, selecthonks+"where honks.userid = ? and xid = ?")

@@ -1312,7 +1326,7 @@ stmtHonksByHonker = preparetodie(db, selecthonks+"join honkers on honkers.xid = honks.honker where honks.userid = ? and honkers.name = ?"+butnotthose+limit)

stmtHonksByCombo = preparetodie(db, selecthonks+"join honkers on honkers.xid = honks.honker where honks.userid = ? and honkers.combos like ?"+butnotthose+limit) stmtHonksByConvoy = preparetodie(db, selecthonks+"where (honks.userid = ? or honker = '') and convoy = ?"+limit) - 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, format, precis, oonker) 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, 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, format text, precis text, oonker text); 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, combos text, pubkey text);
M upgradedb.goupgradedb.go

@@ -70,6 +70,15 @@ doordie(db, "delete from honks where what = 'zonk'")

doordie(db, "update config set value = 6 where key = 'dbversion'") fallthrough case 6: + doordie(db, "alter table honks add column format") + doordie(db, "update honks set format = 'html'") + doordie(db, "alter table honks add column precis") + doordie(db, "update honks set precis = ''") + doordie(db, "alter table honks add column oonker") + doordie(db, "update honks set oonker = ''") + doordie(db, "update config set value = 7 where key = 'dbversion'") + fallthrough + case 7: 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 = 6 +var myVersion = 7 func initdb() { schema, err := ioutil.ReadFile("schema.sql")
M views/honk.htmlviews/honk.html

@@ -3,11 +3,18 @@ {{ with .Honk }}

<header> <img alt="avatar" src="/a?a={{ .Honker}}"> <p><a href="{{ .Honker }}" rel=noreferrer>{{ .Username }}</a> <span class="clip">{{ .What }} {{ .Date.Format "02 Jan 2006 15:04" }} <a href="{{ .URL }}" rel=noreferrer>{{ .URL }}</a></span> +{{ if .Oonker }} +<br> +<span style="margin-left: 3em;" class="clip"> +original: {{ .Oonker }} +</span> +{{ else }} {{ if .RID }} <br> <span style="margin-left: 3em;" class="clip"> in reply to: <a href="{{ .RID }}" rel=noreferrer>{{ .RID }}</a> </span> +{{ end }} {{ end }} <br> <span style="margin-left: 3em;" class="clip">