mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
6f01c1492f
Apply the four Greptile P1 fixes to the Notifications worker and extend it for C3 email read tracking and ST4's stripped SMTP plumbing. P1 #1: alreadyDelivered() now queries the indexed messageId attribute instead of getDocument($messageId). The action loop and Console adapter both write compound `$id`s (messageId + recipient hash), so the previous direct-id lookup always missed. P1 #3: action() no longer calls persistAlert after dispatchConsole; ConsoleAdapter persists internally. Email persists inside dispatchEmail BEFORE the adapter send so the alertId is available for the tracking pixel; webhook persists in the action loop after a successful HTTP send. P1 #4: dispatchConsole now throws when the adapter reports `deliveredTo === 0`, surfacing the per-recipient error. Recipient threading: dispatch() now takes the full recipient map and returns the alertId (or null when persistence is the caller's responsibility). persistAlert() reads userId/teamId from the recipient and grants per-user / per-team-owner CRUD permissions, falling back to payload permissions only when neither is set. The returned alertId lets dispatchEmail splice a 1x1 tracking pixel before the last `</body>` tag, signed with a 30-day HS256 JWT (_APP_OPENSSL_KEY_V1) carrying {alertId, userId}. SMTP resolution: ST4 stripped `smtp` and `customMailOptions` from the Notification event payload, so the worker now resolves SMTP from the injected project Document (mirroring Mails.php / Memberships/Create.php), falling back to the env-driven cloud SMTP adapter when the project has no enabled override. Tests updated: SpyNotifications.dispatch() matches the new signature and emulates per-channel persistence so existing routing assertions keep their semantics. Memory `alerts` collection adds the `read` boolean attribute to mirror platform.php. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>