save honks in markdown, convert on the fly

This commit is contained in:
Ted Unangst 2019-09-18 13:46:42 -04:00
parent 210597dd68
commit 2584f31e17
4 changed files with 44 additions and 24 deletions

View File

@ -843,6 +843,7 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) {
if !h.Public { if !h.Public {
jo["directMessage"] = true jo["directMessage"] = true
} }
translate(h)
jo["summary"] = h.Precis jo["summary"] = h.Precis
jo["content"] = ontologize(mentionize(h.Noise)) jo["content"] = ontologize(mentionize(h.Noise))
if strings.HasPrefix(h.Precis, "DZ:") { if strings.HasPrefix(h.Precis, "DZ:") {

View File

@ -183,7 +183,7 @@ func scanhonk(row RowLike) *Honk {
h := new(Honk) h := new(Honk)
var dt, aud, onts string var dt, aud, onts string
err := row.Scan(&h.ID, &h.UserID, &h.Username, &h.What, &h.Honker, &h.Oonker, &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.Precis, &h.Convoy, &h.Whofore, &h.Flags, &onts) &dt, &h.URL, &aud, &h.Noise, &h.Precis, &h.Format, &h.Convoy, &h.Whofore, &h.Flags, &onts)
if err != nil { if err != nil {
if err != sql.ErrNoRows { if err != sql.ErrNoRows {
log.Printf("error scanning honk: %s", err) log.Printf("error scanning honk: %s", err)
@ -290,7 +290,7 @@ func updatehonk(h *Honk) {
deleteextras(h.ID) deleteextras(h.ID)
dt := h.Date.UTC().Format(dbtimeformat) dt := h.Date.UTC().Format(dbtimeformat)
stmtUpdateHonk.Exec(h.Precis, h.Noise, dt, h.ID) stmtUpdateHonk.Exec(h.Precis, h.Noise, h.Format, dt, h.ID)
saveextras(h) saveextras(h)
} }
@ -341,7 +341,7 @@ func prepareStatements(db *sql.DB) {
stmtOneHonker = preparetodie(db, "select xid from honkers where name = ? and userid = ?") stmtOneHonker = preparetodie(db, "select xid from honkers where name = ? 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 honks.honkid, honks.userid, username, what, honker, oonker, honks.xid, rid, dt, url, audience, noise, precis, convoy, whofore, flags, onts from honks join users on honks.userid = users.userid " selecthonks := "select honks.honkid, honks.userid, username, what, honker, oonker, honks.xid, rid, dt, url, audience, noise, precis, format, convoy, whofore, flags, onts from honks join users on honks.userid = users.userid "
limit := " order by honks.honkid desc limit 250" limit := " order by honks.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 = ?")
@ -360,7 +360,7 @@ func prepareStatements(db *sql.DB) {
stmtSaveOld = preparetodie(db, "insert into forsaken (honkid, precis, noise) values (?, ?, ?)") 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") 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 = ?") stmtDeleteHonk = preparetodie(db, "delete from honks where honkid = ?")
stmtUpdateHonk = preparetodie(db, "update honks set precis = ?, noise = ?, dt = ? where honkid = ?") stmtUpdateHonk = preparetodie(db, "update honks set precis = ?, noise = ?, format = ?, dt = ? where honkid = ?")
stmtSaveOnt = preparetodie(db, "insert into onts (ontology, honkid) values (?, ?)") stmtSaveOnt = preparetodie(db, "insert into onts (ontology, honkid) values (?, ?)")
stmtDeleteOnts = preparetodie(db, "delete from onts where honkid = ?") stmtDeleteOnts = preparetodie(db, "delete from onts where honkid = ?")
stmtSaveDonk = preparetodie(db, "insert into donks (honkid, fileid) values (?, ?)") stmtSaveDonk = preparetodie(db, "insert into donks (honkid, fileid) values (?, ?)")

27
fun.go
View File

@ -44,6 +44,7 @@ func reverbolate(userid int64, honks []*Honk) {
if !h.Public { if !h.Public {
h.Style += " limited" h.Style += " limited"
} }
translate(h)
if h.Whofore == 2 || h.Whofore == 3 { if h.Whofore == 2 || h.Whofore == 3 {
h.URL = h.XID h.URL = h.XID
if h.What != "bonked" { if h.What != "bonked" {
@ -100,6 +101,32 @@ func reverbolate(userid int64, honks []*Honk) {
} }
} }
func translate(honk *Honk) {
if honk.Format == "html" {
return
}
noise := honk.Noise
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:]
}
}
honk.Precis = strings.TrimSpace(honk.Precis)
noise = strings.TrimSpace(noise)
noise = quickrename(noise, honk.UserID)
noise = obfusbreak(noise)
noise = re_memes.ReplaceAllString(noise, "")
honk.Noise = noise
honk.Onts = oneofakind(ontologies(honk.Noise))
}
func unsee(zilences []*regexp.Regexp, precis string, noise string) string { func unsee(zilences []*regexp.Regexp, precis string, noise string) string {
for _, z := range zilences { for _, z := range zilences {
if z.MatchString(precis) || z.MatchString(noise) { if z.MatchString(precis) || z.MatchString(noise) {

32
web.go
View File

@ -883,6 +883,7 @@ func submithonk(w http.ResponseWriter, r *http.Request) {
} }
honk.Date = dt honk.Date = dt
honk.What = "update" honk.What = "update"
honk.Format = "markdown"
} else { } else {
xid := fmt.Sprintf("%s/%s/%s", user.URL, honkSep, xfiltrate()) xid := fmt.Sprintf("%s/%s/%s", user.URL, honkSep, xfiltrate())
what := "honk" what := "honk"
@ -896,22 +897,13 @@ func submithonk(w http.ResponseWriter, r *http.Request) {
Honker: user.URL, Honker: user.URL,
XID: xid, XID: xid,
Date: dt, Date: dt,
Format: "markdown",
} }
} }
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 = quickrename(noise, userinfo.UserID)
noise = hooterize(noise) noise = hooterize(noise)
noise = strings.TrimSpace(noise) honk.Noise = noise
honk.Precis = strings.TrimSpace(honk.Precis) translate(honk)
var convoy string var convoy string
if rid != "" { if rid != "" {
@ -936,11 +928,12 @@ func submithonk(w http.ResponseWriter, r *http.Request) {
} else { } else {
honk.Audience = []string{thewholeworld} honk.Audience = []string{thewholeworld}
} }
if noise != "" && noise[0] == '@' { if honk.Noise != "" && honk.Noise[0] == '@' {
honk.Audience = append(grapevine(noise), honk.Audience...) honk.Audience = append(grapevine(honk.Noise), honk.Audience...)
} else { } else {
honk.Audience = append(honk.Audience, grapevine(noise)...) honk.Audience = append(honk.Audience, grapevine(honk.Noise)...)
} }
if convoy == "" { if convoy == "" {
convoy = "data:,electrichonkytonk-" + xfiltrate() convoy = "data:,electrichonkytonk-" + xfiltrate()
} }
@ -952,8 +945,6 @@ func submithonk(w http.ResponseWriter, r *http.Request) {
return return
} }
honk.Public = !keepitquiet(honk.Audience) honk.Public = !keepitquiet(honk.Audience)
noise = obfusbreak(noise)
honk.Noise = noise
honk.Convoy = convoy honk.Convoy = convoy
donkxid := r.FormValue("donkxid") donkxid := r.FormValue("donkxid")
@ -1055,12 +1046,13 @@ func submithonk(w http.ResponseWriter, r *http.Request) {
} }
return return
} }
honk.Onts = oneofakind(ontologies(honk.Noise))
honk.UserID = userinfo.UserID honk.UserID = userinfo.UserID
honk.RID = rid honk.RID = rid
honk.Date = dt honk.Date = dt
honk.Convoy = convoy honk.Convoy = convoy
honk.Format = "html"
// back to markdown
honk.Noise = noise
if updatexid != "" { if updatexid != "" {
updatehonk(honk) updatehonk(honk)