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.
This commit is contained in:
Ted Unangst 2019-05-15 16:27:50 -04:00
parent 6ab3c1d07d
commit 90c7001e15
7 changed files with 61 additions and 36 deletions

View File

@ -292,7 +292,7 @@ func savexonk(user *WhatAbout, x *Honk) {
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 @@ func xonkxonk(user *WhatAbout, item interface{}) *Honk {
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 @@ func xonkxonk(user *WhatAbout, item interface{}) *Honk {
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 @@ func xonkxonk(user *WhatAbout, item interface{}) *Honk {
audience = oneofakind(audience)
if oonker == who {
oonker = ""
}
xonk.UserID = user.ID
xonk.What = what
xonk.Honker = who
@ -590,8 +591,10 @@ func xonkxonk(user *WhatAbout, item interface{}) *Honk {
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 @@ func jonkjonk(user *WhatAbout, h *Honk) (map[string]interface{}, map[string]inte
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["sensitive"] = true
} else {
jo["summary"] = h.Precis
jo["content"] = mentionize(h.Noise)
if strings.HasPrefix(h.Precis, "DZ:") {
jo["sensitive"] = true
}
var tags []interface{}
g := bunchofgrapes(h.Noise)

6
fun.go
View File

@ -52,7 +52,11 @@ func reverbolate(honks []*Honk) {
}
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 {

38
honk.go
View File

@ -55,11 +55,13 @@ type Honk struct {
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 @@ func getsomehonks(rows *sql.Rows, err error) []*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 @@ func savebonk(w http.ResponseWriter, r *http.Request) {
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 @@ func savebonk(w http.ResponseWriter, r *http.Request) {
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 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
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 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
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 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
honk.Audience = append(honk.Audience, xonkaud...)
convoy = c
}
honk.Oonker = xonk.Honker
honk.RID = rid
}
if convoy == "" {
@ -897,7 +911,7 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
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 @@ func prepareStatements(db *sql.DB) {
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 @@ func prepareStatements(db *sql.DB) {
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 (?, ?)")

View File

@ -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);

View File

@ -70,6 +70,15 @@ func upgradedb() {
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)
}

View File

@ -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 = 6
var myVersion = 7
func initdb() {
schema, err := ioutil.ReadFile("schema.sql")

View File

@ -3,12 +3,19 @@
<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">
convoy: <a href="/t?c={{ .Convoy }}">{{ .Convoy }}</a>