-
Notifications
You must be signed in to change notification settings - Fork 34
/
addReceiver.go
93 lines (82 loc) · 2.09 KB
/
addReceiver.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package notices
import (
"github.com/TeaWeb/code/teaconfigs/notices"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type AddReceiverAction actions.Action
// 添加接收者
func (this *AddReceiverAction) Run(params struct {
Level notices.NoticeLevel
From string
}) {
level := notices.FindNoticeLevel(params.Level)
if level == nil {
this.Fail("找不到Level信息")
}
this.Data["level"] = level
this.Data["from"] = params.From
setting := notices.SharedNoticeSetting()
mediaMaps := []maps.Map{}
for _, media := range setting.Medias {
if !media.On {
continue
}
mediaType := notices.FindNoticeMediaType(media.Type)
if mediaType == nil {
continue
}
mediaMaps = append(mediaMaps, maps.Map{
"id": media.Id,
"name": media.Name,
"typeName": mediaType["name"],
"type": media.Type,
"mediaDescription": mediaType["description"],
"userDescription": mediaType["user"],
})
}
this.Data["medias"] = mediaMaps
this.Show()
}
// 提交保存
func (this *AddReceiverAction) RunPost(params struct {
Level notices.NoticeLevel
On bool
Name string
MediaId string
User string
Must actions.Must
}) {
params.Must.
Field("name", params.Name).
Require("请输入接收人名称").
Field("mediaId", params.MediaId).
Require("请选择使用的媒介")
// 是否校验接收人
media := notices.SharedNoticeSetting().FindMedia(params.MediaId)
if media == nil {
this.Fail("找不到媒介")
}
rawMedia, err := media.Raw()
if err != nil {
this.Fail("找不到媒介:" + err.Error())
}
if rawMedia.RequireUser() {
params.Must.
Field("name", params.Name).
Require("请输入接收人名称")
}
receiver := notices.NewNoticeReceiver()
receiver.On = params.On
receiver.Name = params.Name
receiver.MediaId = params.MediaId
receiver.User = params.User
setting := notices.SharedNoticeSetting()
levelConfig := setting.LevelConfig(params.Level)
levelConfig.AddReceiver(receiver)
err = setting.Save()
if err != nil {
this.Fail("保存失败:" + err.Error())
}
this.Success()
}