File size: 880 Bytes
1e92f2d |
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 |
package message
import (
"sort"
"github.com/target/goalert/notification"
)
// dedupOnCallNotifications will remove old on-call notifications if a newer one exists for the same schedule & destination.
func dedupOnCallNotifications(messages []Message) ([]Message, []string) {
toProcess, result := splitPendingByType(messages, notification.MessageTypeScheduleOnCallUsers)
sort.Slice(toProcess, func(i, j int) bool { return toProcess[i].CreatedAt.After(toProcess[j].CreatedAt) })
type msgKey struct {
scheduleID string
dest notification.DestID
}
m := make(map[msgKey]struct{})
var toDelete []string
for _, msg := range toProcess {
key := msgKey{scheduleID: msg.ScheduleID, dest: msg.DestID}
if _, ok := m[key]; ok {
toDelete = append(toDelete, msg.ID)
continue
}
m[key] = struct{}{}
result = append(result, msg)
}
return result, toDelete
}
|