-
Notifications
You must be signed in to change notification settings - Fork 34
/
deleteMedia.go
63 lines (55 loc) · 1.26 KB
/
deleteMedia.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
package notices
import (
"github.com/TeaWeb/code/teaconfigs/agents"
"github.com/TeaWeb/code/teaconfigs/notices"
"github.com/iwind/TeaGo/actions"
)
type DeleteMediaAction actions.Action
// 删除媒介
func (this *DeleteMediaAction) Run(params struct {
MediaId string
}) {
// 删除agent group中的相关接收人
groupConfig := agents.SharedGroupList()
isChanged := false // 有变化才会保存
for _, group := range groupConfig.FindAllGroups() {
found := group.RemoveMedia(params.MediaId)
if found {
isChanged = true
}
}
if isChanged {
err := groupConfig.Save()
if err != nil {
this.Fail("删除失败:" + err.Error())
}
}
// 删除agent中的相关接收人
for _, agent := range agents.AllSharedAgents() {
isChanged := false
found := agent.RemoveMedia(params.MediaId)
if found {
isChanged = true
}
// app
for _, app := range agent.Apps {
found := app.RemoveMedia(params.MediaId)
if found {
isChanged = true
}
}
if isChanged {
err := agent.Save()
if err != nil {
this.Fail("删除失败:" + err.Error())
}
}
}
setting := notices.SharedNoticeSetting()
setting.RemoveMedia(params.MediaId)
err := setting.Save()
if err != nil {
this.Fail("删除失败:" + err.Error())
}
this.Success()
}