commit 0f4fc3f1ca956f4450396ce78ea3e007d1127935
parent c731477ca87c9f32e74f075790b2d76bb4ab833d
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Thu, 10 Nov 2022 12:45:49 -0800
count messages sent, and minimal karma system
Diffstat:
1 file changed, 21 insertions(+), 0 deletions(-)
diff --git a/pkg/web/handlers/api/v1/msgInterceptor.go b/pkg/web/handlers/api/v1/msgInterceptor.go
@@ -1,6 +1,7 @@
package v1
import (
+ "dkforest/pkg/config"
"dkforest/pkg/database"
"dkforest/pkg/managers"
"dkforest/pkg/utils"
@@ -31,6 +32,12 @@ func (i MsgInterceptor) InterceptMsg(cmd *Command) {
sendInboxes(cmd.room, cmd.authUser, cmd.toUser, msgID, cmd.groupID, html, cmd.modMsg, taggedUsersIDsMap)
}
+ if cmd.room.ID == config.GeneralRoomID {
+ cmd.authUser.GeneralMessagesCount++
+ generalRoomKarma(cmd.authUser)
+ cmd.authUser.DoSave()
+ }
+
// Update chat read marker
database.UpdateChatReadMarker(cmd.authUser.ID, cmd.room.ID)
@@ -39,6 +46,20 @@ func (i MsgInterceptor) InterceptMsg(cmd *Command) {
updateUserActivity(isPM, cmd.room, cmd.authUser)
}
+func generalRoomKarma(authUser *database.User) {
+ // Hellban users ain't getting karma
+ if authUser.IsHellbanned {
+ return
+ }
+ messagesCount := authUser.GeneralMessagesCount
+ if messagesCount%100 == 0 {
+ description := fmt.Sprintf("sent %d messages", messagesCount)
+ authUser.IncrKarma(1, description)
+ } else if messagesCount == 20 {
+ authUser.IncrKarma(1, "first 20 messages sent")
+ }
+}
+
// ProcessRawMessage return the new html, and a map of tagged users used for notifications
// This function takes an "unsafe" user input "in", and return html which will be safe to render.
func ProcessRawMessage(in, roomKey string, authUserID, roomID int64, upload *database.Upload) (string, map[int64]database.User) {