all repos — honk @ 0c27f3dfb4b17c77f8395cbf55cb75f4e58b7f96

my fork of honk

restructure chatter so target is always available to view
Ted Unangst tedu@tedunangst.com
Sat, 23 May 2020 19:17:30 -0400
commit

0c27f3dfb4b17c77f8395cbf55cb75f4e58b7f96

parent

76d8e301e74b46da13000eb4d775b3dd76c0e3c5

4 files changed, 38 insertions(+), 22 deletions(-)

jump to
M database.godatabase.go

@@ -538,7 +538,7 @@ }

return err } -func loadchatter(userid int64) map[string][]*Chonk { +func loadchatter(userid int64) []*Chatter { duedt := time.Now().Add(-3 * 24 * time.Hour).UTC().Format(dbtimeformat) rows, err := stmtLoadChonks.Query(userid, duedt) if err != nil {

@@ -561,7 +561,32 @@ chonks[ch.Target] = append(chonks[ch.Target], ch)

allchonks = append(allchonks, ch) } donksforchonks(allchonks) - return chonks + rows.Close() + rows, err = stmtGetChatters.Query(userid) + if err != nil { + log.Printf("error getting chatters: %s", err) + return nil + } + for rows.Next() { + var target string + err = rows.Scan(&target) + if err != nil { + log.Printf("error scanning chatter: %s", target) + continue + } + if _, ok := chonks[target]; !ok { + chonks[target] = []*Chonk{} + + } + } + var chatter []*Chatter + for target, chonks := range chonks { + chatter = append(chatter, &Chatter{ + Target: target, + Chonks: chonks, + }) + } + return chatter } func savehonk(h *Honk) error {

@@ -821,7 +846,7 @@ var stmtHonksForUserFirstClass *sql.Stmt

var stmtSaveMeta, stmtDeleteAllMeta, stmtDeleteSomeMeta, stmtUpdateHonk *sql.Stmt var stmtHonksISaved, stmtGetFilters, stmtSaveFilter, stmtDeleteFilter *sql.Stmt var stmtGetTracks *sql.Stmt -var stmtSaveChonk, stmtLoadChonks *sql.Stmt +var stmtSaveChonk, stmtLoadChonks, stmtGetChatters *sql.Stmt func preparetodie(db *sql.DB, s string) *sql.Stmt { stmt, err := db.Prepare(s)

@@ -901,4 +926,5 @@ stmtDeleteFilter = preparetodie(db, "delete from hfcs where userid = ? and hfcsid = ?")

stmtGetTracks = preparetodie(db, "select fetches from tracks where xid = ?") stmtSaveChonk = preparetodie(db, "insert into chonks (userid, xid, who, target, dt, noise, format) values (?, ?, ?, ?, ?, ?, ?)") stmtLoadChonks = preparetodie(db, "select chonkid, userid, xid, who, target, dt, noise, format from chonks where userid = ? and dt > ? order by chonkid asc") + stmtGetChatters = preparetodie(db, "select distinct(target) from chonks where userid = ?") }
M honk.gohonk.go

@@ -108,6 +108,11 @@ Handle string

HTML template.HTML } +type Chatter struct { + Target string + Chonks []*Chonk +} + type Mention struct { Who string Where string

@@ -337,18 +342,6 @@ serve()

case "backend": backendServer() case "test": - xid := args[1] - chatter := loadchatter(1) - for _, chonks := range chatter { - for _, ch := range chonks { - if ch.XID == xid { - var user *WhatAbout - somenumberedusers.Get(ch.UserID, &user) - msg := chonkifymsg(user, ch) - fmt.Println(string(msg)) - } - } - } ElaborateUnitTests() default: log.Fatal("unknown command")
M views/chatter.htmlviews/chatter.html

@@ -21,13 +21,10 @@ </div>

{{ $chonkcsrf := .ChonkCSRF }} {{ range .Chatter }} <section class="honk"> -{{ $target := "" }} -{{ range . }} -{{ if eq $target "" }} -{{ $target = .Target }} <p class="chattarget"> chatter: {{ .Target }} -{{ end }} +{{ $target := .Target }} +{{ range .Chonks }} <div class="chat"> <p> <span class="chatstamp">{{ .Date.Local.Format "15:04" }} {{ .Handle }}:</span>
M web.goweb.go

@@ -1773,8 +1773,8 @@

func showchatter(w http.ResponseWriter, r *http.Request) { u := login.GetUserInfo(r) chatter := loadchatter(u.UserID) - for _, chonks := range chatter { - for _, ch := range chonks { + for _, chat := range chatter { + for _, ch := range chat.Chonks { filterchonk(ch) } }