···551551}
552552553553// GetPendingEmailDigestRecipients returns DIDs of users who have email
554554-// notifications enabled, have a verified primary email, and have unemaileD
555555-// notifications older than olderThan for email-eligible notification types.
554554+// notifications enabled, have a verified primary email, and have unread,
555555+// unemailed notifications older than olderThan for email-eligible notification
556556+// types.
556557func GetPendingEmailDigestRecipients(e Execer, olderThan time.Time) ([]string, error) {
557558 placeholders := make([]string, len(models.EmailNotificationTypes))
558559 args := []any{olderThan.UTC().Format(time.RFC3339)}
···568569 JOIN notification_preferences np ON np.user_did = n.recipient_did
569570 JOIN emails e ON e.did = n.recipient_did AND e.is_primary = 1 AND e.verified = 1
570571 WHERE n.emailed = 0
572572+ AND n.read = 0
571573 AND n.created < ?
572574 AND np.email_notifications = 1
573575 AND n.type IN (%s)
···590592 return dids, rows.Err()
591593}
592594593593-// GetPendingNotificationsForEmailDigest returns all unemailed notifications
594594-// older than olderThan for email-eligible types for a specific recipient.
595595+// GetPendingNotificationsForEmailDigest returns all unread, unemailed
596596+// notifications older than olderThan for email-eligible types for a specific
597597+// recipient.
595598func GetPendingNotificationsForEmailDigest(e Execer, recipientDid string, olderThan time.Time) ([]*models.NotificationWithEntity, error) {
596599 placeholders := make([]string, len(models.EmailNotificationTypes))
597600 args := []any{recipientDid, olderThan.UTC().Format(time.RFC3339)}
···614617 LEFT JOIN pulls p ON n.pull_id = p.id
615618 WHERE n.recipient_did = ?
616619 AND n.emailed = 0
620620+ AND n.read = 0
617621 AND n.created < ?
618622 AND n.type IN (%s)
619623 ORDER BY n.created DESC