Step 11 - notifications
1 min czytania
Implement email notifications for card changes using a digest pipeline. Client side: a small NotifyService writes docs to a kanbanTaskEvents collection on meaningful changes (card created, moved to another column, text edited, comment added, assignee added) with { projectId, projectName, taskId, taskTitle, type, actorUid, actorName, actorLanguage, recipientUids: string[] (the assignees except the actor), createdAt, columnTitle?, detail? }. Rules: create-only, actorUid must equal request.auth.uid, recipientUids must be a list; read/update/delete all false.
Cloud Functions: (1) onDocumentCreated on kanbanTaskEvents fans the event out into per-recipient digest docs kanbanTaskDigests/{taskId}_{uid} inside a transaction - the first event sets sendAt = now + 5 minutes and freezes the language, later events arrayUnion into events[] WITHOUT moving sendAt (so a burst coalesces); delete the source event after fan-out. kanbanTaskDigests has NO security rules at all - Admin SDK only, so recipient emails never reach any client. (2) A scheduled function every 1 minute queries digests with sendAt in the past (limit 300), resolves each recipient's email from users/{uid}, sends ONE summary email per digest with a bullet line per change and a deep link to /kanban/{projectId}?task={taskId}, then deletes the digest regardless of send outcome. Use nodemailer with SMTP credentials from function secrets. Never email the actor about their own changes.
Dyskusja
Komentarze: 0Brak komentarzy. Rozpocznij dyskusję.