diff --git a/database.go b/database.go index 946d2db..a78d36f 100644 --- a/database.go +++ b/database.go @@ -595,26 +595,25 @@ func savechonk(ch *Chonk) error { break } } + chatplusone(tx, ch.UserID) err = tx.Commit() - chatplusone(ch.UserID) } else { tx.Rollback() } return err } -func chatplusone(userid int64) { +func chatplusone(tx *sql.Tx, userid int64) { var user *WhatAbout ok := somenumberedusers.Get(userid, &user) if !ok { return } options := user.Options - options.Chats += 1 + options.ChatCount += 1 j, err := jsonify(options) if err == nil { - db := opendatabase() - _, err = db.Exec("update users set options = ? where username = ?", j, user.Name) + _, err = tx.Exec("update users set options = ? where username = ?", j, user.Name) } if err != nil { log.Printf("error plussing chat: %s", err) @@ -626,11 +625,11 @@ func chatplusone(userid int64) { func chatnewnone(userid int64) { var user *WhatAbout ok := somenumberedusers.Get(userid, &user) - if !ok || user.Options.Chats == 0 { + if !ok || user.Options.ChatCount == 0 { return } options := user.Options - options.Chats = 0 + options.ChatCount = 0 j, err := jsonify(options) if err == nil { db := opendatabase() @@ -643,6 +642,45 @@ func chatnewnone(userid int64) { somenumberedusers.Clear(user.ID) } +func meplusone(tx *sql.Tx, userid int64) { + var user *WhatAbout + ok := somenumberedusers.Get(userid, &user) + if !ok { + return + } + options := user.Options + options.MeCount += 1 + j, err := jsonify(options) + if err == nil { + _, err = tx.Exec("update users set options = ? where username = ?", j, user.Name) + } + if err != nil { + log.Printf("error plussing me: %s", err) + } + somenamedusers.Clear(user.Name) + somenumberedusers.Clear(user.ID) +} + +func menewnone(userid int64) { + var user *WhatAbout + ok := somenumberedusers.Get(userid, &user) + if !ok || user.Options.MeCount == 0 { + return + } + options := user.Options + options.MeCount = 0 + j, err := jsonify(options) + if err == nil { + db := opendatabase() + _, err = db.Exec("update users set options = ? where username = ?", j, user.Name) + } + if err != nil { + log.Printf("error noneing me: %s", err) + } + somenamedusers.Clear(user.Name) + somenumberedusers.Clear(user.ID) +} + func loadchatter(userid int64) []*Chatter { duedt := time.Now().Add(-3 * 24 * time.Hour).UTC().Format(dbtimeformat) rows, err := stmtLoadChonks.Query(userid, duedt) @@ -724,6 +762,9 @@ func savehonk(h *Honk) error { err = saveextras(tx, h) } if err == nil { + if h.Whofore == 1 { + meplusone(tx, h.UserID) + } err = tx.Commit() } else { tx.Rollback() diff --git a/docs/changelog.txt b/docs/changelog.txt index bb15a7d..22cf27d 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -2,9 +2,9 @@ changelog === next -+ Images in the hooter. ++ Low key unread counters. -+ Unread count for chatter. ++ Images in the hooter. + More flexible hashtag characters. diff --git a/honk.go b/honk.go index 929be9b..d2e4140 100644 --- a/honk.go +++ b/honk.go @@ -56,7 +56,8 @@ type UserOptions struct { Avatar string `json:",omitempty"` MapLink string `json:",omitempty"` Reaction string `json:",omitempty"` - Chats int + MeCount int64 + ChatCount int64 } type KeyInfo struct { diff --git a/views/header.html b/views/header.html index 4a85753..d88fc57 100644 --- a/views/header.html +++ b/views/header.html @@ -20,7 +20,7 @@ menu {{ .UserInfo.Name }} -
  • chatter{{ if .UserInfo.Options.Chats }} ({{ .UserInfo.Options.Chats }}){{ end }} +
  • chatter{{ if .UserInfo.Options.ChatCount }}({{ .UserInfo.Options.ChatCount }}){{ end }}
  • tags
  • events
  • long ago diff --git a/views/honkpage.js b/views/honkpage.js index 2d215ab..f4a5a29 100644 --- a/views/honkpage.js +++ b/views/honkpage.js @@ -92,6 +92,19 @@ function fillinhonks(xhr, glowit) { doc.innerHTML = resp.Honks var honks = doc.children + var mecount = document.getElementById("mecount") + if (resp.MeCount) { + mecount.innerHTML = "(" + resp.MeCount + ")" + } else { + mecount.innerHTML = "" + } + var chatcount = document.getElementById("chatcount") + if (resp.ChatCount) { + chatcount.innerHTML = "(" + resp.ChatCount + ")" + } else { + chatcount.innerHTML = "" + } + var srvel = document.getElementById("srvmsg") while (srvel.children[0]) { srvel.children[0].remove() diff --git a/web.go b/web.go index 28007e7..3daa038 100644 --- a/web.go +++ b/web.go @@ -116,6 +116,7 @@ func homepage(w http.ResponseWriter, r *http.Request) { templinfo["PageName"] = "atme" honks = gethonksforme(userid, 0) honks = osmosis(honks, userid, false) + menewnone(userid) case "/longago": templinfo["ServerMessage"] = "long ago and far away!" templinfo["PageName"] = "longago" @@ -2195,9 +2196,11 @@ func nomoroboto(w http.ResponseWriter, r *http.Request) { } type Hydration struct { - Tophid int64 - Srvmsg template.HTML - Honks string + Tophid int64 + Srvmsg template.HTML + Honks string + MeCount int64 + ChatCount int64 } func webhydra(w http.ResponseWriter, r *http.Request) { @@ -2216,6 +2219,7 @@ func webhydra(w http.ResponseWriter, r *http.Request) { case "atme": honks = gethonksforme(userid, wanted) honks = osmosis(honks, userid, false) + menewnone(userid) hydra.Srvmsg = "at me!" case "longago": honks = gethonksfromlongago(userid, wanted) @@ -2264,6 +2268,8 @@ func webhydra(w http.ResponseWriter, r *http.Request) { } reverbolate(userid, honks) + user, _ := butwhatabout(u.Username) + var buf strings.Builder templinfo["Honks"] = honks templinfo["MapLink"] = getmaplink(u) @@ -2274,6 +2280,8 @@ func webhydra(w http.ResponseWriter, r *http.Request) { return } hydra.Honks = buf.String() + hydra.MeCount = user.Options.MeCount + hydra.ChatCount = user.Options.ChatCount w.Header().Set("Content-Type", "application/json") j, _ := jsonify(&hydra) io.WriteString(w, j) @@ -2328,6 +2336,7 @@ func apihandler(w http.ResponseWriter, r *http.Request) { case "atme": honks = gethonksforme(userid, wanted) honks = osmosis(honks, userid, false) + menewnone(userid) case "longago": honks = gethonksfromlongago(userid, wanted) honks = osmosis(honks, userid, false)