diff --git a/activity.go b/activity.go index 93919d8..03fa292 100644 --- a/activity.go +++ b/activity.go @@ -123,7 +123,7 @@ func GetJunkTimeout(url string, timeout time.Duration) (junk.Junk, error) { }) } -func savedonk(url string, name, media string, localize bool) *Donk { +func savedonk(url string, name, desc, media string, localize bool) *Donk { if url == "" { return nil } @@ -173,7 +173,7 @@ func savedonk(url string, name, media string, localize bool) *Donk { } } saveit: - res, err := stmtSaveFile.Exec(xid, name, url, media, localize, data) + res, err := stmtSaveFile.Exec(xid, name, desc, url, media, localize, data) if err != nil { log.Printf("error saving file %s: %s", url, err) return nil @@ -641,6 +641,11 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk { mt, _ := att.GetString("mediaType") u, _ := att.GetString("url") name, _ := att.GetString("name") + desc, _ := att.GetString("summary") + log.Printf("att: %s %s %s", name, desc, u) + if desc == "" { + desc = name + } localize := false if i > 4 { log.Printf("excessive attachment: %s", at) @@ -653,7 +658,8 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk { } else { log.Printf("unknown attachment: %s", at) } - donk := savedonk(u, name, mt, localize) + log.Printf("saving a donk: %s is %s", name, desc) + donk := savedonk(u, name, desc, mt, localize) if donk != nil { xonk.Donks = append(xonk.Donks, donk) } @@ -666,6 +672,10 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk { } tt, _ := tag.GetString("type") name, _ := tag.GetString("name") + desc, _ := tag.GetString("summary") + if desc == "" { + desc = name + } if tt == "Emoji" { icon, _ := tag.GetMap("icon") mt, _ := icon.GetString("mediaType") @@ -673,7 +683,7 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk { mt = "image/png" } u, _ := icon.GetString("url") - donk := savedonk(u, name, mt, true) + donk := savedonk(u, name, desc, mt, true) if donk != nil { xonk.Donks = append(xonk.Donks, donk) } @@ -890,6 +900,7 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) { jd := junk.New() jd["mediaType"] = d.Media jd["name"] = d.Name + jd["summary"] = d.Desc jd["type"] = "Document" jd["url"] = d.URL atts = append(atts, jd) diff --git a/docs/changelog.txt b/docs/changelog.txt index 69e87db..1b86480 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -2,6 +2,8 @@ changelog -- next ++ Image descriptions. + ++ Search. I hate it already. + Unbonking. diff --git a/honk.go b/honk.go index 3e9250d..dbeafbe 100644 --- a/honk.go +++ b/honk.go @@ -99,6 +99,7 @@ type Donk struct { FileID int64 XID string Name string + Desc string URL string Media string Local bool @@ -979,7 +980,7 @@ func donksforhonks(honks []*Honk) { ids = append(ids, fmt.Sprintf("%d", h.ID)) hmap[h.ID] = h } - q := fmt.Sprintf("select honkid, donks.fileid, xid, name, url, media, local from donks join files on donks.fileid = files.fileid where honkid in (%s)", strings.Join(ids, ",")) + q := fmt.Sprintf("select honkid, donks.fileid, xid, name, description, url, media, local from donks join files on donks.fileid = files.fileid where honkid in (%s)", strings.Join(ids, ",")) rows, err := db.Query(q) if err != nil { log.Printf("error querying donks: %s", err) @@ -989,7 +990,7 @@ func donksforhonks(honks []*Honk) { for rows.Next() { var hid int64 var d Donk - err = rows.Scan(&hid, &d.FileID, &d.XID, &d.Name, &d.URL, &d.Media, &d.Local) + err = rows.Scan(&hid, &d.FileID, &d.XID, &d.Name, &d.Desc, &d.URL, &d.Media, &d.Local) if err != nil { log.Printf("error scanning donk: %s", err) continue @@ -1273,19 +1274,15 @@ func savehonk(w http.ResponseWriter, r *http.Request) { } xid += ".txt" } + desc := r.FormValue("donkdesc") url := fmt.Sprintf("https://%s/d/%s", serverName, xid) - res, err := stmtSaveFile.Exec(xid, name, url, media, 1, data) + res, err := stmtSaveFile.Exec(xid, name, desc, url, media, 1, data) if err != nil { log.Printf("unable to save image: %s", err) return } var d Donk d.FileID, _ = res.LastInsertId() - d.XID = name - d.Name = name - d.Media = media - d.URL = url - d.Local = true honk.Donks = append(honk.Donks, &d) donkxid = d.XID } @@ -1296,9 +1293,6 @@ func savehonk(w http.ResponseWriter, r *http.Request) { row := stmtFindFile.QueryRow(url) err := row.Scan(&donk.FileID) if err == nil { - donk.XID = xid - donk.Local = true - donk.URL = url honk.Donks = append(honk.Donks, &donk) } else { log.Printf("can't find file: %s", xid) @@ -1306,7 +1300,7 @@ func savehonk(w http.ResponseWriter, r *http.Request) { } herd := herdofemus(honk.Noise) for _, e := range herd { - donk := savedonk(e.ID, e.Name, "image/png", true) + donk := savedonk(e.ID, e.Name, e.Name, "image/png", true) if donk != nil { donk.Name = e.Name honk.Donks = append(honk.Donks, donk) @@ -1359,6 +1353,8 @@ func savehonk(w http.ResponseWriter, r *http.Request) { log.Printf("error saving ont: %s", err) } } + honk.Donks = nil + donksforhonks([]*Honk{&honk}) go honkworldwide(user, &honk) @@ -1847,7 +1843,7 @@ func prepareStatements(db *sql.DB) { stmtZonkIt = preparetodie(db, "delete from honks where honkid = ?") stmtZonkDonks = preparetodie(db, "delete from donks where honkid = ?") stmtFindFile = preparetodie(db, "select fileid from files where url = ? and local = 1") - stmtSaveFile = preparetodie(db, "insert into files (xid, name, url, media, local, content) values (?, ?, ?, ?, ?, ?)") + stmtSaveFile = preparetodie(db, "insert into files (xid, name, description, url, media, local, content) values (?, ?, ?, ?, ?, ?, ?)") stmtWhatAbout = preparetodie(db, "select userid, username, displayname, about, pubkey, options from users where username = ?") stmtSaveDub = preparetodie(db, "insert into honkers (userid, name, xid, flavor) values (?, ?, ?, ?)") stmtAddDoover = preparetodie(db, "insert into doovers (dt, tries, username, rcpt, msg) values (?, ?, ?, ?, ?)") diff --git a/schema.sql b/schema.sql index 8c9f249..c444c9b 100644 --- a/schema.sql +++ b/schema.sql @@ -1,7 +1,7 @@ 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, flags integer, onts text); create table donks (honkid integer, fileid integer); -create table files(fileid integer primary key, xid text, name text, url text, media text, local integer, content blob); +create table files(fileid integer primary key, xid text, name text, description text, url text, media text, local integer, content blob); create table honkers (honkerid integer primary key, userid integer, name text, xid text, flavor text, combos text); 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); diff --git a/upgradedb.go b/upgradedb.go index 0b9e3fd..0f4e9d2 100644 --- a/upgradedb.go +++ b/upgradedb.go @@ -184,6 +184,11 @@ func upgradedb() { doordie(db, "update config set value = 16 where key = 'dbversion'") fallthrough case 16: + doordie(db, "alter table files add column description text") + doordie(db, "update files set description = name") + doordie(db, "update config set value = 17 where key = 'dbversion'") + fallthrough + case 17: default: log.Fatalf("can't upgrade unknown version %d", dbversion) } diff --git a/util.go b/util.go index 9c71f0b..e4c0fec 100644 --- a/util.go +++ b/util.go @@ -72,7 +72,7 @@ var dbtimeformat = "2006-01-02 15:04:05" var alreadyopendb *sql.DB var dbname = "honk.db" var stmtConfig *sql.Stmt -var myVersion = 16 +var myVersion = 17 func initdb() { schema, err := ioutil.ReadFile("schema.sql") diff --git a/views/honk.html b/views/honk.html index a3f386d..2d0cac9 100644 --- a/views/honk.html +++ b/views/honk.html @@ -47,7 +47,7 @@ in reply to: {{ .RID }} {{ if eq .Media "text/plain" }}

Attachment: {{ .Name }} {{ else }} -

+

{{ end }} {{ else }} {{ if .XID }} @@ -56,7 +56,7 @@ in reply to: {{ .RID }} {{ if eq .Media "video/mp4" }}

{{ else }} -

+

{{ end }} {{ end }} {{ end }} diff --git a/views/honkform.html b/views/honkform.html index fc675f5..cbe6172 100644 --- a/views/honkform.html +++ b/views/honkform.html @@ -7,6 +7,8 @@ in reply to: attach: {{ if .SavedFile }} {{ .SavedFile }} {{ else }} {{ end }} +

+description:

@@ -14,6 +16,10 @@ in reply to: