-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathblock.go
36 lines (32 loc) · 870 Bytes
/
block.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package control
func (manager *Manager[CTX]) initBlock() error {
return manager.D.Create("__block", &BlockStatus{})
}
// DoBlock 封禁
func (manager *Manager[CTX]) DoBlock(uid int64) error {
manager.Lock()
defer manager.Unlock()
manager.blockCache[uid] = true
return manager.D.Insert("__block", &BlockStatus{UserID: uid})
}
// DoUnblock 解封
func (manager *Manager[CTX]) DoUnblock(uid int64) error {
manager.Lock()
defer manager.Unlock()
manager.blockCache[uid] = false
return manager.D.Del("__block", "where uid = ?", uid)
}
// IsBlocked 是否封禁
func (manager *Manager[CTX]) IsBlocked(uid int64) bool {
manager.RLock()
isbl, ok := manager.blockCache[uid]
manager.RUnlock()
if ok {
return isbl
}
manager.Lock()
defer manager.Unlock()
isbl = manager.D.CanFind("__block", "where uid = ?", uid)
manager.blockCache[uid] = isbl
return isbl
}