Skip to content

Commit

Permalink
feat: show new message count & new user count in home page
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed Apr 19, 2023
1 parent 28f064e commit f597758
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ var Version = "v0.0.0"
var SystemName = "消息推送服务"
var ServerAddress = "http://localhost:3000"
var Footer = ""
var MessageCount = 0 // Non critical value, no need to use atomic
var UserCount = 0 // Non critical value, no need to use atomic

// Any options with "Secret", "Token" in its key won't be return by GetOptions

Expand Down
1 change: 1 addition & 0 deletions controller/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func saveAndSendMessage(user *model.User, message *model.Message) error {
message.Link = "unsaved" // This is for user to identify whether the message is saved
}
err := channel.SendMessage(message, user)
common.MessageCount += 1 // We don't need to use atomic here because it's not a critical value
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions controller/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func GetStatus(c *gin.Context) {
"turnstile_site_key": common.TurnstileSiteKey,
"message_persistence": common.MessagePersistenceEnabled,
"message_render": common.MessageRenderEnabled,
"message_count": common.MessageCount,
"user_count": common.UserCount,
},
})
return
Expand Down
3 changes: 3 additions & 0 deletions model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ func (user *User) Insert() error {
}
}
err = DB.Create(user).Error
if err == nil {
common.UserCount += 1 // We don't need to use atomic here, because it's not a critical value
}
return err
}

Expand Down
16 changes: 15 additions & 1 deletion web/src/pages/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ const Home = () => {
href='https://github.com/songquanpeng/message-pusher'
target='_blank'
>
GitHub 仓库地址
https://github.com/songquanpeng/message-pusher
</a>
</p>
<p>启动时间:{getStartTimeString()}</p>
<p>自从上次启动已发送消息数目:{statusState?.status?.message_count}</p>
<p>自从上次启动新注册用户数目:{statusState?.status?.user_count}</p>
</Card.Description>
</Card.Content>
</Card>
Expand Down Expand Up @@ -85,6 +87,18 @@ const Home = () => {
? '已启用'
: '未启用'}
</p>
<p>
全局消息持久化:
{statusState?.status?.message_persistence === true
? '已启用'
: '未启用'}
</p>
<p>
全局消息渲染:
{statusState?.status?.message_render === true
? '已启用'
: '未启用'}
</p>
</Card.Description>
</Card.Content>
</Card>
Expand Down

0 comments on commit f597758

Please sign in to comment.