update mecount and chatcount in hydration
This commit is contained in:
parent
28a061a03f
commit
1af5998b20
55
database.go
55
database.go
|
@ -595,26 +595,25 @@ func savechonk(ch *Chonk) error {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
chatplusone(tx, ch.UserID)
|
||||||
err = tx.Commit()
|
err = tx.Commit()
|
||||||
chatplusone(ch.UserID)
|
|
||||||
} else {
|
} else {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func chatplusone(userid int64) {
|
func chatplusone(tx *sql.Tx, userid int64) {
|
||||||
var user *WhatAbout
|
var user *WhatAbout
|
||||||
ok := somenumberedusers.Get(userid, &user)
|
ok := somenumberedusers.Get(userid, &user)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
options := user.Options
|
options := user.Options
|
||||||
options.Chats += 1
|
options.ChatCount += 1
|
||||||
j, err := jsonify(options)
|
j, err := jsonify(options)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
db := opendatabase()
|
_, err = tx.Exec("update users set options = ? where username = ?", j, user.Name)
|
||||||
_, err = db.Exec("update users set options = ? where username = ?", j, user.Name)
|
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error plussing chat: %s", err)
|
log.Printf("error plussing chat: %s", err)
|
||||||
|
@ -626,11 +625,11 @@ func chatplusone(userid int64) {
|
||||||
func chatnewnone(userid int64) {
|
func chatnewnone(userid int64) {
|
||||||
var user *WhatAbout
|
var user *WhatAbout
|
||||||
ok := somenumberedusers.Get(userid, &user)
|
ok := somenumberedusers.Get(userid, &user)
|
||||||
if !ok || user.Options.Chats == 0 {
|
if !ok || user.Options.ChatCount == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
options := user.Options
|
options := user.Options
|
||||||
options.Chats = 0
|
options.ChatCount = 0
|
||||||
j, err := jsonify(options)
|
j, err := jsonify(options)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
db := opendatabase()
|
db := opendatabase()
|
||||||
|
@ -643,6 +642,45 @@ func chatnewnone(userid int64) {
|
||||||
somenumberedusers.Clear(user.ID)
|
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 {
|
func loadchatter(userid int64) []*Chatter {
|
||||||
duedt := time.Now().Add(-3 * 24 * time.Hour).UTC().Format(dbtimeformat)
|
duedt := time.Now().Add(-3 * 24 * time.Hour).UTC().Format(dbtimeformat)
|
||||||
rows, err := stmtLoadChonks.Query(userid, duedt)
|
rows, err := stmtLoadChonks.Query(userid, duedt)
|
||||||
|
@ -724,6 +762,9 @@ func savehonk(h *Honk) error {
|
||||||
err = saveextras(tx, h)
|
err = saveextras(tx, h)
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
if h.Whofore == 1 {
|
||||||
|
meplusone(tx, h.UserID)
|
||||||
|
}
|
||||||
err = tx.Commit()
|
err = tx.Commit()
|
||||||
} else {
|
} else {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
|
|
|
@ -2,9 +2,9 @@ changelog
|
||||||
|
|
||||||
=== next
|
=== next
|
||||||
|
|
||||||
+ Images in the hooter.
|
+ Low key unread counters.
|
||||||
|
|
||||||
+ Unread count for chatter.
|
+ Images in the hooter.
|
||||||
|
|
||||||
+ More flexible hashtag characters.
|
+ More flexible hashtag characters.
|
||||||
|
|
||||||
|
|
3
honk.go
3
honk.go
|
@ -56,7 +56,8 @@ type UserOptions struct {
|
||||||
Avatar string `json:",omitempty"`
|
Avatar string `json:",omitempty"`
|
||||||
MapLink string `json:",omitempty"`
|
MapLink string `json:",omitempty"`
|
||||||
Reaction string `json:",omitempty"`
|
Reaction string `json:",omitempty"`
|
||||||
Chats int
|
MeCount int64
|
||||||
|
ChatCount int64
|
||||||
}
|
}
|
||||||
|
|
||||||
type KeyInfo struct {
|
type KeyInfo struct {
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
<summary>menu<span> {{ .UserInfo.Name }}</span></summary>
|
<summary>menu<span> {{ .UserInfo.Name }}</span></summary>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a id="homelink" href="/">home</a>
|
<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><a id="firstlink" href="/first">first</a>
|
||||||
<li style="list-style-type:none; margin-left:-1em">
|
<li style="list-style-type:none; margin-left:-1em">
|
||||||
<details>
|
<details>
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</ul>
|
</ul>
|
||||||
</details>
|
</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="/o">tags</a>
|
||||||
<li><a href="/events">events</a>
|
<li><a href="/events">events</a>
|
||||||
<li><a id="longagolink" href="/longago">long ago</a>
|
<li><a id="longagolink" href="/longago">long ago</a>
|
||||||
|
|
|
@ -92,6 +92,19 @@ function fillinhonks(xhr, glowit) {
|
||||||
doc.innerHTML = resp.Honks
|
doc.innerHTML = resp.Honks
|
||||||
var honks = doc.children
|
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")
|
var srvel = document.getElementById("srvmsg")
|
||||||
while (srvel.children[0]) {
|
while (srvel.children[0]) {
|
||||||
srvel.children[0].remove()
|
srvel.children[0].remove()
|
||||||
|
|
9
web.go
9
web.go
|
@ -116,6 +116,7 @@ func homepage(w http.ResponseWriter, r *http.Request) {
|
||||||
templinfo["PageName"] = "atme"
|
templinfo["PageName"] = "atme"
|
||||||
honks = gethonksforme(userid, 0)
|
honks = gethonksforme(userid, 0)
|
||||||
honks = osmosis(honks, userid, false)
|
honks = osmosis(honks, userid, false)
|
||||||
|
menewnone(userid)
|
||||||
case "/longago":
|
case "/longago":
|
||||||
templinfo["ServerMessage"] = "long ago and far away!"
|
templinfo["ServerMessage"] = "long ago and far away!"
|
||||||
templinfo["PageName"] = "longago"
|
templinfo["PageName"] = "longago"
|
||||||
|
@ -2198,6 +2199,8 @@ type Hydration struct {
|
||||||
Tophid int64
|
Tophid int64
|
||||||
Srvmsg template.HTML
|
Srvmsg template.HTML
|
||||||
Honks string
|
Honks string
|
||||||
|
MeCount int64
|
||||||
|
ChatCount int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func webhydra(w http.ResponseWriter, r *http.Request) {
|
func webhydra(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -2216,6 +2219,7 @@ func webhydra(w http.ResponseWriter, r *http.Request) {
|
||||||
case "atme":
|
case "atme":
|
||||||
honks = gethonksforme(userid, wanted)
|
honks = gethonksforme(userid, wanted)
|
||||||
honks = osmosis(honks, userid, false)
|
honks = osmosis(honks, userid, false)
|
||||||
|
menewnone(userid)
|
||||||
hydra.Srvmsg = "at me!"
|
hydra.Srvmsg = "at me!"
|
||||||
case "longago":
|
case "longago":
|
||||||
honks = gethonksfromlongago(userid, wanted)
|
honks = gethonksfromlongago(userid, wanted)
|
||||||
|
@ -2264,6 +2268,8 @@ func webhydra(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
reverbolate(userid, honks)
|
reverbolate(userid, honks)
|
||||||
|
|
||||||
|
user, _ := butwhatabout(u.Username)
|
||||||
|
|
||||||
var buf strings.Builder
|
var buf strings.Builder
|
||||||
templinfo["Honks"] = honks
|
templinfo["Honks"] = honks
|
||||||
templinfo["MapLink"] = getmaplink(u)
|
templinfo["MapLink"] = getmaplink(u)
|
||||||
|
@ -2274,6 +2280,8 @@ func webhydra(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
hydra.Honks = buf.String()
|
hydra.Honks = buf.String()
|
||||||
|
hydra.MeCount = user.Options.MeCount
|
||||||
|
hydra.ChatCount = user.Options.ChatCount
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
j, _ := jsonify(&hydra)
|
j, _ := jsonify(&hydra)
|
||||||
io.WriteString(w, j)
|
io.WriteString(w, j)
|
||||||
|
@ -2328,6 +2336,7 @@ func apihandler(w http.ResponseWriter, r *http.Request) {
|
||||||
case "atme":
|
case "atme":
|
||||||
honks = gethonksforme(userid, wanted)
|
honks = gethonksforme(userid, wanted)
|
||||||
honks = osmosis(honks, userid, false)
|
honks = osmosis(honks, userid, false)
|
||||||
|
menewnone(userid)
|
||||||
case "longago":
|
case "longago":
|
||||||
honks = gethonksfromlongago(userid, wanted)
|
honks = gethonksfromlongago(userid, wanted)
|
||||||
honks = osmosis(honks, userid, false)
|
honks = osmosis(honks, userid, false)
|
||||||
|
|
Loading…
Reference in New Issue