drainUnread sends notifications for all unread messages. Notifications are best-effort; messages are marked read only when fetched via the REST API.
(agent *identity.AgentIdentity)
| 142 | // drainUnread sends notifications for all unread messages. Notifications are |
| 143 | // best-effort; messages are marked read only when fetched via the REST API. |
| 144 | func (h *Handler) drainUnread(agent *identity.AgentIdentity) { |
| 145 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
| 146 | defer cancel() |
| 147 | |
| 148 | messages, err := h.store.GetMessagesByAgent(ctx, identity.MessageListFilter{ |
| 149 | AgentID: agent.ID, |
| 150 | Status: "unread", |
| 151 | Direction: "inbound", |
| 152 | Limit: 100, |
| 153 | }) |
| 154 | if err != nil { |
| 155 | log.Printf("[ws] drain error for %s: %v", agent.ID, err) |
| 156 | return |
| 157 | } |
| 158 | |
| 159 | for _, msg := range messages { |
| 160 | notification := BuildNotification(&msg) |
| 161 | h.hub.Send(agent.ID, notification) |
| 162 | } |
| 163 | |
| 164 | if len(messages) > 0 { |
| 165 | log.Printf("[ws] drained %d unread messages for %s", len(messages), agent.ID) |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | // Notification is the lightweight JSON payload sent over WebSocket when a new |
| 170 | // message arrives. It contains only metadata — the full message (including |
no test coverage detected