dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 742c0715cca9c8d80a7d1a4ae433969da7c558e6
parent 7600b57854c84e9a14ad051b2a0b34787cff6178
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Thu, 10 Nov 2022 12:50:02 -0800

prevent new accounts from sending unwanted PMs to users, until they have enough karma

Diffstat:
Mpkg/web/handlers/api/v1/slashInterceptor.go | 14++++++++++++++
1 file changed, 14 insertions(+), 0 deletions(-)

diff --git a/pkg/web/handlers/api/v1/slashInterceptor.go b/pkg/web/handlers/api/v1/slashInterceptor.go @@ -728,6 +728,16 @@ func handlePMCmd(c *Command) (handled bool) { c.err = ErrPMDenied return true } else if user.PmMode == database.PmModeStandard { + + if !c.room.IsOwned() && !c.authUser.CanSendPM() { + // Need at least 1 karma to send PM from a public room + c.err = errors.New("not enough karma") + return true + } else if c.room.IsOwned() && !c.authUser.CanSendPM() { + // In private rooms, can send PM but inboxes will be skipped if not enough karma + c.skipInboxes = true + } + if database.IsUserPmBlacklisted(c.authUser.ID, user.ID) { c.err = ErrPMDenied return true @@ -981,6 +991,10 @@ func handleChessCmd(c *Command) (handled bool) { func handleInboxCmd(c *Command) (handled bool) { if m := inboxRgx.FindStringSubmatch(c.message); len(m) == 4 { + if !c.authUser.CanSendPM() { + c.err = errors.New("not enough karma") + return true + } username := m[1] encryptRaw := m[2] message := m[3]