add unread count for chatter

This commit is contained in:
Ted Unangst 2021-12-26 23:19:04 -05:00
parent 9752faf404
commit f547153ecc
5 changed files with 51 additions and 7 deletions

View File

@ -596,12 +596,53 @@ func savechonk(ch *Chonk) error {
}
}
err = tx.Commit()
chatplusone(ch.UserID)
} else {
tx.Rollback()
}
return err
}
func chatplusone(userid int64) {
var user *WhatAbout
ok := somenumberedusers.Get(userid, &user)
if !ok {
return
}
options := user.Options
options.Chats += 1
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 plussing chat: %s", err)
}
somenamedusers.Clear(user.Name)
somenumberedusers.Clear(user.ID)
}
func chatnewnone(userid int64) {
var user *WhatAbout
ok := somenumberedusers.Get(userid, &user)
if !ok || user.Options.Chats == 0 {
return
}
options := user.Options
options.Chats = 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 chat: %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)

View File

@ -2,6 +2,8 @@ changelog
=== next
+ Unread count for chatter.
+ More flexible hashtag characters.
+ Fix the memetizer to work in more environments.

View File

@ -55,6 +55,7 @@ type UserOptions struct {
MapLink string `json:",omitempty"`
Reaction string `json:",omitempty"`
MentionAll bool
Chats int
}
type KeyInfo struct {

View File

@ -17,7 +17,7 @@
<header>
{{ if .UserInfo }}
<details id="topmenu">
<summary>menu<span> {{ .UserInfo.Username }}</span></summary>
<summary>menu<span> {{ .UserInfo.Name }}</span></summary>
<ul>
<li><a id="homelink" href="/">home</a>
<li><a id="atmelink" href="/atme">@me</a>
@ -31,7 +31,7 @@
{{ end }}
</ul>
</details>
<li><a href="/chatter">chatter</a>
<li><a href="/chatter">chatter{{ if .UserInfo.Options.Chats }} ({{ .UserInfo.Options.Chats }}){{ end }}</a>
<li><a href="/o">tags</a>
<li><a href="/events">events</a>
<li><a id="longagolink" href="/longago">long ago</a>
@ -43,7 +43,7 @@
<details>
<summary>more stuff</summary>
<ul>
<li><a href="/{{ .UserSep }}/{{ .UserInfo.Username }}">my honks</a>
<li><a href="/{{ .UserSep }}/{{ .UserInfo.Name }}">my honks</a>
<li><a href="/about">about</a>
<li><a href="/front">front</a>
<li><a href="/funzone">funzone</a>

8
web.go
View File

@ -75,17 +75,16 @@ func getmaplink(u *login.UserInfo) string {
}
func getInfo(r *http.Request) map[string]interface{} {
u := login.GetUserInfo(r)
templinfo := make(map[string]interface{})
templinfo["StyleParam"] = getassetparam(viewDir + "/views/style.css")
templinfo["LocalStyleParam"] = getassetparam(dataDir + "/views/local.css")
templinfo["JSParam"] = getassetparam(viewDir + "/views/honkpage.js")
templinfo["UserStyle"] = getuserstyle(u)
templinfo["ServerName"] = serverName
templinfo["IconName"] = iconName
templinfo["UserInfo"] = u
templinfo["UserSep"] = userSep
if u != nil {
if u := login.GetUserInfo(r); u != nil {
templinfo["UserInfo"], _ = butwhatabout(u.Username)
templinfo["UserStyle"] = getuserstyle(u)
var combos []string
combocache.Get(u.UserID, &combos)
templinfo["Combos"] = combos
@ -1763,6 +1762,7 @@ func showhonkers(w http.ResponseWriter, r *http.Request) {
func showchatter(w http.ResponseWriter, r *http.Request) {
u := login.GetUserInfo(r)
chatnewnone(u.UserID)
chatter := loadchatter(u.UserID)
for _, chat := range chatter {
for _, ch := range chat.Chonks {