From f5977581d3b25912b8bc32380a717a16f9c85a66 Mon Sep 17 00:00:00 2001 From: JustSong Date: Wed, 19 Apr 2023 15:22:57 +0800 Subject: [PATCH] feat: show new message count & new user count in home page --- common/constants.go | 2 ++ controller/message.go | 1 + controller/misc.go | 2 ++ model/user.go | 3 +++ web/src/pages/Home/index.js | 16 +++++++++++++++- 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/common/constants.go b/common/constants.go index c80f23361..f763bf1ef 100644 --- a/common/constants.go +++ b/common/constants.go @@ -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 diff --git a/controller/message.go b/controller/message.go index 6b2e5fe97..088d7536e 100644 --- a/controller/message.go +++ b/controller/message.go @@ -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 } diff --git a/controller/misc.go b/controller/misc.go index 83b082e81..1b0278fe4 100644 --- a/controller/misc.go +++ b/controller/misc.go @@ -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 diff --git a/model/user.go b/model/user.go index 0a3f3d933..57311115f 100644 --- a/model/user.go +++ b/model/user.go @@ -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 } diff --git a/web/src/pages/Home/index.js b/web/src/pages/Home/index.js index bcea564ee..cef94537a 100644 --- a/web/src/pages/Home/index.js +++ b/web/src/pages/Home/index.js @@ -47,10 +47,12 @@ const Home = () => { href='https://github.com/songquanpeng/message-pusher' target='_blank' > - GitHub 仓库地址 + https://github.com/songquanpeng/message-pusher

启动时间:{getStartTimeString()}

+

自从上次启动已发送消息数目:{statusState?.status?.message_count}

+

自从上次启动新注册用户数目:{statusState?.status?.user_count}

@@ -85,6 +87,18 @@ const Home = () => { ? '已启用' : '未启用'}

+

+ 全局消息持久化: + {statusState?.status?.message_persistence === true + ? '已启用' + : '未启用'} +

+

+ 全局消息渲染: + {statusState?.status?.message_render === true + ? '已启用' + : '未启用'} +