fix: add user to blacklist when it's banned or deleted, and make deletion soft (close #473, close #791)

This commit is contained in:
JustSong
2024-03-10 15:56:19 +08:00
parent 27ad8bfb98
commit 6ebc99460e
4 changed files with 47 additions and 4 deletions

29
common/blacklist/main.go Normal file
View File

@@ -0,0 +1,29 @@
package blacklist
import (
"fmt"
"sync"
)
var blackList sync.Map
func init() {
blackList = sync.Map{}
}
func userId2Key(id int) string {
return fmt.Sprintf("userid_%d", id)
}
func BanUser(id int) {
blackList.Store(userId2Key(id), true)
}
func UnbanUser(id int) {
blackList.Delete(userId2Key(id))
}
func IsUserBanned(id int) bool {
_, ok := blackList.Load(userId2Key(id))
return ok
}