MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / drainUnread

Method drainUnread

internal/ws/handler.go:144–167  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

142// drainUnread sends notifications for all unread messages. Notifications are
143// best-effort; messages are marked read only when fetched via the REST API.
144func (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

Callers 1

serveMethod · 0.95

Calls 3

BuildNotificationFunction · 0.85
GetMessagesByAgentMethod · 0.65
SendMethod · 0.45

Tested by

no test coverage detected