feat(alerts): sync read-state from cloud (alert-read / alerts-read-all)#26
Merged
Conversation
React to two new inbound cloud WebSocket events so an alert acknowledged on the web portal or mobile app shows as read on the desktop too. - cloud/ws.rs: handle 'alert-read' and 'alerts-read-all' on the existing socket. Guarded by instanceId (lenient when unknown). Emits the existing 'alerts-updated' event so the badge + Alerts table refresh. - commands/alerts.rs: mark_alert_read / mark_all_alerts_read mark local AlertEvent.acknowledged. Single-alert match is on (ruleName, minerId, timestamp) — the app does not store the cloud alertId (push_alert discards the response and alerts ship via an offline queue), and the local record already carries those three fields (miner_ip == cloud minerId). Timestamp comparison tolerates RFC-3339 format differences. Unit-tested. - Alerts.tsx: listen for 'alerts-updated' to reload the history table. Matching rationale: storing the cloud id would require changing push_alert's contract and writing back into the capped history.json on every push; composite matching reuses fields the cloud echoes specifically for this.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes the desktop react to the new cloud WebSocket broadcasts so an alert acknowledged on the web portal or mobile app shows as read here too.
What
Two new inbound message types on the existing instance WebSocket (same
{ type, data }shape ascommand):alert-read{ alertId, instanceId, ruleName, minerId, timestamp, acknowledgedAt } → marks the matching local alert acknowledged.alerts-read-all{ instanceId, acknowledgedAt } → marks ALL local alerts acknowledged.How
src-tauri/src/cloud/ws.rs—handle_messagegains both cases, guarded byinstanceId(lenient: only rejects when both the payload's and our own instance id are known and differ). On a local change it emits the existingalerts-updatedevent.src-tauri/src/commands/alerts.rs—mark_alert_read/mark_all_alerts_readflip the existingAlertEvent.acknowledgedflag inhistory.json. Read-state already existed (acknowledge_alert), so no new model was needed.src/pages/Alerts.tsx— now listens foralerts-updatedto reload the history table (the badge viaAlertContextalready did).Matching choice (single alert)
Match on (ruleName, minerId, timestamp), not the cloud
alertId. The app does not store the cloud id today —push_alertdiscards the POST /alert response and alerts are delivered through an offline queue, so the id only exists post-push. Threading it back would mean changingpush_alert's contract and writing back into the cappedhistory.jsonon every successful push. The localAlertEventalready carries the three echoed fields (rule_name,miner_ip== the cloud'sminerIdfor both ASIC IP and mobile device_id, andtimestamp), and the cloud includes them in the payload for exactly this purpose. Timestamp comparison tolerates RFC-3339 format differences (Zvs+00:00).Tests / build
alert_matches,timestamps_match) —cargo test✅ (7 passed).npx tsc --noEmit✅ ·npm run build✅.Note
Per request, not merging — opening for review. Runtime confirmation (ack on phone → shows read on desktop) is best verified once the cloud broadcast is live against a logged-in instance.