in src/ulsp/internal/persistent-notifier/notifier.go [215:264]
func (h *notificationHandlerImpl) captureUpdate(update Notification) string {
h.progressInfoMu.Lock()
defer h.progressInfoMu.Unlock()
if len(update.Message) == 0 {
// Empty update indicates removal, otherwise capture the latest update.
if _, ok := h.notificationsBySender[update.SenderToken]; ok {
delete(h.notificationsBySender[update.SenderToken], update.IdentifierToken)
if len(h.notificationsBySender[update.SenderToken]) == 0 {
delete(h.notificationsBySender, update.SenderToken)
}
}
} else {
if _, ok := h.notificationsBySender[update.SenderToken]; !ok {
h.notificationsBySender[update.SenderToken] = make(map[string]Notification)
}
h.notificationsBySender[update.SenderToken][update.IdentifierToken] = update
}
// Select the message with the lowest priority for each IdentifierToken.
// The notifications channel is buffered to avoid blocking the sender while this logic runs.
condensedByPriority := make(map[string]Notification)
for _, sender := range h.notificationsBySender {
for _, msg := range sender {
existing, ok := condensedByPriority[msg.IdentifierToken]
// Store the lowest priority entry with this key.
if !ok || existing.Priority > msg.Priority {
condensedByPriority[msg.IdentifierToken] = msg
}
}
}
// Condense the de-duplicated results into a final result.
i := 0
combinedMessage := make([]string, len(condensedByPriority))
for _, msg := range condensedByPriority {
combinedMessage[i] = msg.Message
i++
}
if len(combinedMessage) == 1 {
return combinedMessage[0]
}
// Output example: [message1, message2, message3]
slices.Sort(combinedMessage)
return fmt.Sprintf("[%s]", strings.Join(combinedMessage, ", "))
}