all repos — honk @ 7f850efb78a80ddf1eb8f4939b64d070328871b4

my fork of honk

update mecount and chatcount in hydration
Ted Unangst tedu@tedunangst.com
Sat, 05 Feb 2022 16:53:19 -0500
commit

7f850efb78a80ddf1eb8f4939b64d070328871b4

parent

5aa91b020bb92fe076570e2a0b3fb1ae1b74b741

6 files changed, 79 insertions(+), 15 deletions(-)

jump to
M database.godatabase.go

@@ -595,26 +595,25 @@ log.Printf("error saving donk: %s", err)

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 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()

@@ -638,6 +637,45 @@ _, err = db.Exec("update users set options = ? where username = ?", j, user.Name)

} if err != nil { log.Printf("error noneing chat: %s", err) + } + somenamedusers.Clear(user.Name) + 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)

@@ -724,6 +762,9 @@ h.ID, _ = res.LastInsertId()

err = saveextras(tx, h) } if err == nil { + if h.Whofore == 1 { + meplusone(tx, h.UserID) + } err = tx.Commit() } else { tx.Rollback()
M docs/changelog.txtdocs/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.
M honk.gohonk.go

@@ -56,7 +56,8 @@ MentionAll bool `json:",omitempty"`

Avatar string `json:",omitempty"` MapLink string `json:",omitempty"` Reaction string `json:",omitempty"` - Chats int + MeCount int64 + ChatCount int64 } type KeyInfo struct {
M views/header.htmlviews/header.html

@@ -20,7 +20,7 @@ <details id="topmenu">

<summary>menu<span> {{ .UserInfo.Name }}</span></summary> <ul> <li><a id="homelink" href="/">home</a> -<li><a id="atmelink" href="/atme">@me</a> +<li><a id="atmelink" href="/atme">@me<span id=mecount>{{ if .UserInfo.Options.MeCount }}({{ .UserInfo.Options.MeCount }}){{ end }}</span></a> <li><a id="firstlink" href="/first">first</a> <li style="list-style-type:none; margin-left:-1em"> <details>

@@ -31,7 +31,7 @@ <li><a class="combolink" href="/c/{{ . }}">{{ . }}</a>

{{ end }} </ul> </details> -<li><a href="/chatter">chatter{{ if .UserInfo.Options.Chats }} ({{ .UserInfo.Options.Chats }}){{ end }}</a> +<li><a href="/chatter">chatter<span id=chatcount>{{ if .UserInfo.Options.ChatCount }}({{ .UserInfo.Options.ChatCount }}){{ end }}</span></a> <li><a href="/o">tags</a> <li><a href="/events">events</a> <li><a id="longagolink" href="/longago">long ago</a>
M views/honkpage.jsviews/honkpage.js

@@ -92,6 +92,19 @@ doc = document.createElement( 'div' );

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()
M web.goweb.go

@@ -116,6 +116,7 @@ templinfo["ServerMessage"] = "at me!"

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 @@ }

} 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 @@ switch page {

case "atme": honks = gethonksforme(userid, wanted) honks = osmosis(honks, userid, false) + menewnone(userid) hydra.Srvmsg = "at me!" case "longago": honks = gethonksfromlongago(userid, wanted)

@@ -2263,6 +2267,8 @@ } else {

hydra.Tophid = wanted } reverbolate(userid, honks) + + user, _ := butwhatabout(u.Username) var buf strings.Builder templinfo["Honks"] = honks

@@ -2274,6 +2280,8 @@ log.Printf("frag error: %s", err)

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 @@ switch page {

case "atme": honks = gethonksforme(userid, wanted) honks = osmosis(honks, userid, false) + menewnone(userid) case "longago": honks = gethonksfromlongago(userid, wanted) honks = osmosis(honks, userid, false)