Digest Email
In Mastodon, they occasionally send a digest email ("Here is what you missed...") to the users who are away for some time. There is a scheduled job which runs at 10:00 every Tuesday. The digest includes mentions and new followers count since the last visit.
It looks like it sends the email to all users who:
- are confirmed
- are enabled
- are not suspended
- have not been moved to another account
- have digest_emails enabled
- are away for >8 days
- weren't emailed with the digest in the past >7 days
On every visit (and API call) Mastodon checks if user.current_sign_in_at
is older than 24hrs and if yes then updates it with a current time. So user.current_sign_in_at
always has a user's last visit date.
Implementation Ideas
-
Add new fields to
Pleroma.User.Info
:-
current_sign_in_at
(not sure about the name) last_digest_emailed_at
-
email_notifications
with value{digest: true}
(so the digest would be enabled by default)
-
-
Add a plug to check and update
current_user.info.current_sign_in_at
in the same way Mastodon does. -
Create
Pleroma.NotificationEmail
and setupdigest
email (subject, template, etc.). -
Create a scheduler to run periodic cron-like jobs. I think we can use Quantum library for this.
-
Create a job
Pleroma.DigestEmailWorker
:- filter users where:
-
info.deactivated
isfalse
-
info.email_notifications.digest
istrue
-
info.current_sign_in_at
is older than 8 days -
info.last_digest_emailed_at
is older than 7 days
-
- send digest email and update
info.last_digest_emailed_at
for each user:-
since_date
isinfo.last_digest_emailed_at
orinfo.current_sign_in_at + 1d
, whichever is the most recent date - find all mention activities where
inserted_at
>since_date
- if there is no activities then stop
- if there are >0 activities then find out a count of new followers since
since_date
- send the digest email with new mentions and the follower count
-
- filter users where:
-
Set up the scheduler to run
Pleroma.DigestEmailWorker
weekly on Tuesdays (or maybe daily?) -
Add email notifications settings to the front end