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:
parent
6ab3c1d07d
commit
90c7001e15
33
activity.go
33
activity.go
|
@ -292,7 +292,7 @@ func savexonk(user *WhatAbout, x *Honk) {
|
||||||
whofore = 1
|
whofore = 1
|
||||||
}
|
}
|
||||||
res, err := stmtSaveHonk.Exec(x.UserID, x.What, x.Honker, x.XID, x.RID, dt, x.URL, aud,
|
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 {
|
if err != nil {
|
||||||
log.Printf("err saving xonk: %s", err)
|
log.Printf("err saving xonk: %s", err)
|
||||||
return
|
return
|
||||||
|
@ -463,7 +463,7 @@ func xonkxonk(user *WhatAbout, item interface{}) *Honk {
|
||||||
|
|
||||||
var audience []string
|
var audience []string
|
||||||
var err error
|
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 obj map[string]interface{}
|
||||||
var ok bool
|
var ok bool
|
||||||
switch what {
|
switch what {
|
||||||
|
@ -511,19 +511,17 @@ func xonkxonk(user *WhatAbout, item interface{}) *Honk {
|
||||||
if who == "" {
|
if who == "" {
|
||||||
who, _ = jsongetstring(obj, "attributedTo")
|
who, _ = jsongetstring(obj, "attributedTo")
|
||||||
}
|
}
|
||||||
|
oonker, _ = jsongetstring(obj, "attributedTo")
|
||||||
ot, _ := jsongetstring(obj, "type")
|
ot, _ := jsongetstring(obj, "type")
|
||||||
url, _ = jsongetstring(obj, "url")
|
url, _ = jsongetstring(obj, "url")
|
||||||
if ot == "Note" || ot == "Article" || ot == "Page" {
|
if ot == "Note" || ot == "Article" || ot == "Page" {
|
||||||
audience = newphone(audience, obj)
|
audience = newphone(audience, obj)
|
||||||
xid, _ = jsongetstring(obj, "id")
|
xid, _ = jsongetstring(obj, "id")
|
||||||
|
precis, _ = jsongetstring(obj, "summary")
|
||||||
content, _ = jsongetstring(obj, "content")
|
content, _ = jsongetstring(obj, "content")
|
||||||
summary, _ := jsongetstring(obj, "summary")
|
|
||||||
if !strings.HasPrefix(content, "<p>") {
|
if !strings.HasPrefix(content, "<p>") {
|
||||||
content = "<p>" + content
|
content = "<p>" + content
|
||||||
}
|
}
|
||||||
if summary != "" {
|
|
||||||
content = "<p>summary: " + summary + content
|
|
||||||
}
|
|
||||||
rid, _ = jsongetstring(obj, "inReplyTo")
|
rid, _ = jsongetstring(obj, "inReplyTo")
|
||||||
convoy, _ = jsongetstring(obj, "context")
|
convoy, _ = jsongetstring(obj, "context")
|
||||||
if convoy == "" {
|
if convoy == "" {
|
||||||
|
@ -582,6 +580,9 @@ func xonkxonk(user *WhatAbout, item interface{}) *Honk {
|
||||||
|
|
||||||
audience = oneofakind(audience)
|
audience = oneofakind(audience)
|
||||||
|
|
||||||
|
if oonker == who {
|
||||||
|
oonker = ""
|
||||||
|
}
|
||||||
xonk.UserID = user.ID
|
xonk.UserID = user.ID
|
||||||
xonk.What = what
|
xonk.What = what
|
||||||
xonk.Honker = who
|
xonk.Honker = who
|
||||||
|
@ -590,8 +591,10 @@ func xonkxonk(user *WhatAbout, item interface{}) *Honk {
|
||||||
xonk.Date, _ = time.Parse(time.RFC3339, dt)
|
xonk.Date, _ = time.Parse(time.RFC3339, dt)
|
||||||
xonk.URL = url
|
xonk.URL = url
|
||||||
xonk.Noise = content
|
xonk.Noise = content
|
||||||
|
xonk.Precis = precis
|
||||||
xonk.Audience = audience
|
xonk.Audience = audience
|
||||||
xonk.Convoy = convoy
|
xonk.Convoy = convoy
|
||||||
|
xonk.Oonker = oonker
|
||||||
|
|
||||||
if needxonk(user, &xonk) {
|
if needxonk(user, &xonk) {
|
||||||
if what == "tonk" {
|
if what == "tonk" {
|
||||||
|
@ -721,22 +724,10 @@ func jonkjonk(user *WhatAbout, h *Honk) (map[string]interface{}, map[string]inte
|
||||||
if len(h.Audience) > 1 {
|
if len(h.Audience) > 1 {
|
||||||
jo["cc"] = h.Audience[1:]
|
jo["cc"] = h.Audience[1:]
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(h.Noise, "DZ:") {
|
jo["summary"] = h.Precis
|
||||||
// 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["content"] = mentionize(h.Noise)
|
jo["content"] = mentionize(h.Noise)
|
||||||
|
if strings.HasPrefix(h.Precis, "DZ:") {
|
||||||
|
jo["sensitive"] = true
|
||||||
}
|
}
|
||||||
var tags []interface{}
|
var tags []interface{}
|
||||||
g := bunchofgrapes(h.Noise)
|
g := bunchofgrapes(h.Noise)
|
||||||
|
|
6
fun.go
6
fun.go
|
@ -52,7 +52,11 @@ func reverbolate(honks []*Honk) {
|
||||||
}
|
}
|
||||||
zap := make(map[*Donk]bool)
|
zap := make(map[*Donk]bool)
|
||||||
h.Noise = unpucker(h.Noise)
|
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 {
|
emuxifier := func(e string) string {
|
||||||
for _, d := range h.Donks {
|
for _, d := range h.Donks {
|
||||||
if d.Name == e {
|
if d.Name == e {
|
||||||
|
|
38
honk.go
38
honk.go
|
@ -55,11 +55,13 @@ type Honk struct {
|
||||||
Username string
|
Username string
|
||||||
What string
|
What string
|
||||||
Honker string
|
Honker string
|
||||||
|
Oonker string
|
||||||
XID string
|
XID string
|
||||||
RID string
|
RID string
|
||||||
Date time.Time
|
Date time.Time
|
||||||
URL string
|
URL string
|
||||||
Noise string
|
Noise string
|
||||||
|
Precis string
|
||||||
Convoy string
|
Convoy string
|
||||||
Audience []string
|
Audience []string
|
||||||
Privacy string
|
Privacy string
|
||||||
|
@ -566,8 +568,8 @@ func getxonk(userid int64, xid string) *Honk {
|
||||||
h := new(Honk)
|
h := new(Honk)
|
||||||
var dt, aud string
|
var dt, aud string
|
||||||
row := stmtOneXonk.QueryRow(userid, xid)
|
row := stmtOneXonk.QueryRow(userid, xid)
|
||||||
err := row.Scan(&h.ID, &h.UserID, &h.Username, &h.What, &h.Honker, &h.XID, &h.RID,
|
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.Convoy)
|
&dt, &h.URL, &aud, &h.Noise, &h.Precis, &h.Convoy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != sql.ErrNoRows {
|
if err != sql.ErrNoRows {
|
||||||
log.Printf("error scanning xonk: %s", err)
|
log.Printf("error scanning xonk: %s", err)
|
||||||
|
@ -627,8 +629,8 @@ func getsomehonks(rows *sql.Rows, err error) []*Honk {
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var h Honk
|
var h Honk
|
||||||
var dt, aud string
|
var dt, aud string
|
||||||
err = rows.Scan(&h.ID, &h.UserID, &h.Username, &h.What, &h.Honker, &h.XID, &h.RID,
|
err = rows.Scan(&h.ID, &h.UserID, &h.Username, &h.What, &h.Honker, &h.Oonker,
|
||||||
&dt, &h.URL, &aud, &h.Noise, &h.Convoy)
|
&h.XID, &h.RID, &dt, &h.URL, &aud, &h.Noise, &h.Precis, &h.Convoy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error scanning honks: %s", err)
|
log.Printf("error scanning honks: %s", err)
|
||||||
return nil
|
return nil
|
||||||
|
@ -696,12 +698,9 @@ func savebonk(w http.ResponseWriter, r *http.Request) {
|
||||||
bonk := Honk{
|
bonk := Honk{
|
||||||
UserID: userinfo.UserID,
|
UserID: userinfo.UserID,
|
||||||
Username: userinfo.Username,
|
Username: userinfo.Username,
|
||||||
Honker: xonk.Honker,
|
|
||||||
What: "bonk",
|
What: "bonk",
|
||||||
XID: xonk.XID,
|
XID: xonk.XID,
|
||||||
Date: dt,
|
Date: dt,
|
||||||
Noise: xonk.Noise,
|
|
||||||
Convoy: xonk.Convoy,
|
|
||||||
Donks: xonk.Donks,
|
Donks: xonk.Donks,
|
||||||
Audience: []string{thewholeworld},
|
Audience: []string{thewholeworld},
|
||||||
}
|
}
|
||||||
|
@ -714,7 +713,7 @@ func savebonk(w http.ResponseWriter, r *http.Request) {
|
||||||
whofore = 1
|
whofore = 1
|
||||||
}
|
}
|
||||||
res, err := stmtSaveHonk.Exec(userinfo.UserID, "bonk", "", xid, "",
|
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 {
|
if err != nil {
|
||||||
log.Printf("error saving bonk: %s", err)
|
log.Printf("error saving bonk: %s", err)
|
||||||
return
|
return
|
||||||
|
@ -797,6 +796,19 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
|
||||||
XID: xid,
|
XID: xid,
|
||||||
Date: dt,
|
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] == '@' {
|
if noise != "" && noise[0] == '@' {
|
||||||
honk.Audience = append(grapevine(noise), thewholeworld)
|
honk.Audience = append(grapevine(noise), thewholeworld)
|
||||||
} else {
|
} else {
|
||||||
|
@ -807,7 +819,8 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
|
||||||
xonk := getxonk(userinfo.UserID, rid)
|
xonk := getxonk(userinfo.UserID, rid)
|
||||||
if xonk != nil {
|
if xonk != nil {
|
||||||
if xonk.Honker == "" {
|
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...)
|
honk.Audience = append(honk.Audience, xonk.Audience...)
|
||||||
convoy = xonk.Convoy
|
convoy = xonk.Convoy
|
||||||
|
@ -816,6 +829,7 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
|
||||||
honk.Audience = append(honk.Audience, xonkaud...)
|
honk.Audience = append(honk.Audience, xonkaud...)
|
||||||
convoy = c
|
convoy = c
|
||||||
}
|
}
|
||||||
|
honk.Oonker = xonk.Honker
|
||||||
honk.RID = rid
|
honk.RID = rid
|
||||||
}
|
}
|
||||||
if convoy == "" {
|
if convoy == "" {
|
||||||
|
@ -897,7 +911,7 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
|
||||||
whofore = 1
|
whofore = 1
|
||||||
}
|
}
|
||||||
res, err := stmtSaveHonk.Exec(userinfo.UserID, what, "", xid, rid,
|
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 {
|
if err != nil {
|
||||||
log.Printf("error saving honk: %s", err)
|
log.Printf("error saving honk: %s", err)
|
||||||
return
|
return
|
||||||
|
@ -1300,7 +1314,7 @@ func prepareStatements(db *sql.DB) {
|
||||||
stmtHasHonker = preparetodie(db, "select honkerid from honkers where xid = ? 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'")
|
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"
|
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)"
|
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 = ?")
|
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)
|
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)
|
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 = ?")
|
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 = ?")
|
||||||
stmtSaveDonk = preparetodie(db, "insert into donks (honkid, fileid) values (?, ?)")
|
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, 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 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, combos text, pubkey text);
|
create table honkers (honkerid integer primary key, userid integer, name text, xid text, flavor text, combos text, pubkey text);
|
||||||
|
|
|
@ -70,6 +70,15 @@ func upgradedb() {
|
||||||
doordie(db, "update config set value = 6 where key = 'dbversion'")
|
doordie(db, "update config set value = 6 where key = 'dbversion'")
|
||||||
fallthrough
|
fallthrough
|
||||||
case 6:
|
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:
|
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 = 6
|
var myVersion = 7
|
||||||
|
|
||||||
func initdb() {
|
func initdb() {
|
||||||
schema, err := ioutil.ReadFile("schema.sql")
|
schema, err := ioutil.ReadFile("schema.sql")
|
||||||
|
|
|
@ -3,12 +3,19 @@
|
||||||
<header>
|
<header>
|
||||||
<img alt="avatar" src="/a?a={{ .Honker}}">
|
<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>
|
<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 }}
|
{{ if .RID }}
|
||||||
<br>
|
<br>
|
||||||
<span style="margin-left: 3em;" class="clip">
|
<span style="margin-left: 3em;" class="clip">
|
||||||
in reply to: <a href="{{ .RID }}" rel=noreferrer>{{ .RID }}</a>
|
in reply to: <a href="{{ .RID }}" rel=noreferrer>{{ .RID }}</a>
|
||||||
</span>
|
</span>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
<br>
|
<br>
|
||||||
<span style="margin-left: 3em;" class="clip">
|
<span style="margin-left: 3em;" class="clip">
|
||||||
convoy: <a href="/t?c={{ .Convoy }}">{{ .Convoy }}</a>
|
convoy: <a href="/t?c={{ .Convoy }}">{{ .Convoy }}</a>
|
||||||
|
|
Loading…
Reference in New Issue