mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 12:40:07 +00:00
WIP: 补全各模块的通知分组设置
This commit is contained in:
@@ -35,12 +35,12 @@ func LoadNotifications() {
|
||||
if err := DB.Find(¬ifications).Error; err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, n := range notifications {
|
||||
for i := range notifications {
|
||||
// 旧版本的Tag可能不存在 自动设置为默认值
|
||||
if n.Tag == "" {
|
||||
SetDefaultNotificationTagInDB(&n)
|
||||
if notifications[i].Tag == "" {
|
||||
SetDefaultNotificationTagInDB(¬ifications[i])
|
||||
}
|
||||
AddNotificationToList(&n)
|
||||
AddNotificationToList(¬ifications[i])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,23 +70,16 @@ func OnRefreshOrAddNotification(n *model.Notification) {
|
||||
|
||||
// AddNotificationToList 添加通知方式到map中
|
||||
func AddNotificationToList(n *model.Notification) {
|
||||
notificationsLock.Lock()
|
||||
defer notificationsLock.Unlock()
|
||||
|
||||
// 当前 Tag 不存在,创建对应该 Tag 的 子 map 后再添加
|
||||
if _, ok := NotificationList[n.Tag]; !ok {
|
||||
NotificationList[n.Tag] = make(map[uint64]*model.Notification)
|
||||
}
|
||||
NotificationList[n.Tag][n.ID] = n
|
||||
NotificationIDToTag[n.ID] = n.Tag
|
||||
|
||||
}
|
||||
|
||||
// UpdateNotificationInList 在 map 中更新通知方式
|
||||
func UpdateNotificationInList(n *model.Notification) {
|
||||
notificationsLock.Lock()
|
||||
defer notificationsLock.Unlock()
|
||||
|
||||
NotificationList[n.Tag][n.ID] = n
|
||||
}
|
||||
|
||||
@@ -137,10 +130,14 @@ func SendNotification(notificationTag string, desc string, mutable bool) {
|
||||
// 向该通知方式组的所有通知方式发出通知
|
||||
notificationsLock.RLock()
|
||||
defer notificationsLock.RUnlock()
|
||||
|
||||
for _, n := range NotificationList[notificationTag] {
|
||||
log.Println("尝试通知", n.Name)
|
||||
}
|
||||
for _, n := range NotificationList[notificationTag] {
|
||||
if err := n.Send(desc); err != nil {
|
||||
log.Println("NEZHA>> 发送通知失败:", err)
|
||||
log.Println("NEZHA>> 向 ", n.Name, " 发送通知失败:", err)
|
||||
} else {
|
||||
log.Println("NEZHA>> 向 ", n.Name, " 发送通知成功:")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user