-
Notifications
You must be signed in to change notification settings - Fork 34
/
level_config.go
46 lines (41 loc) · 1.07 KB
/
level_config.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
37
38
39
40
41
42
43
44
45
46
package notices
// 级别配置
type NoticeLevelConfig struct {
ShouldNotify bool `yaml:"shouldNotify" json:"shouldNotify"`
Receivers []*NoticeReceiver `yaml:"receivers" json:"receivers"`
}
// 添加接收人
func (this *NoticeLevelConfig) AddReceiver(receiver *NoticeReceiver) {
this.Receivers = append(this.Receivers, receiver)
}
// 移除接收人
func (this *NoticeLevelConfig) RemoveReceiver(receiverId string) {
result := []*NoticeReceiver{}
for _, r := range this.Receivers {
if r.Id == receiverId {
continue
}
result = append(result, r)
}
this.Receivers = result
}
// 移除某个媒介的所有接收人
func (this *NoticeLevelConfig) RemoveMediaReceivers(mediaId string) {
result := []*NoticeReceiver{}
for _, r := range this.Receivers {
if r.MediaId == mediaId {
continue
}
result = append(result, r)
}
this.Receivers = result
}
// 查找单个接收人
func (this *NoticeLevelConfig) FindReceiver(receiverId string) *NoticeReceiver {
for _, r := range this.Receivers {
if r.Id == receiverId {
return r
}
}
return nil
}