Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Send an weekly email digest to users #121

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions applications/user.moon
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,25 @@ class MoonRocksUser extends lapis.Application
@flow("followings")\unfollow_object unfollowed_user, "subscription"

redirect_to: @url_for unfollowed_user

[weekly_digest: "/users/weekly_digest"]: require_login capture_errors_404 =>
import Modules from require "models"

weekly_favorites_followings_query = db.query "select object_id, count(*) from followings
where object_type = 1 and created_at >= current_date - interval '7' day
group by object_id order by count(*) desc limit 5"

@weekly_favorites = {}

for following in *weekly_favorites_followings_query
table.insert @weekly_favorites, Modules\find following.object_id

Users\include_in @weekly_favorites, "user_id"

-- render: true

UserDigest = require "emails.user_digest"
UserDigest\send @, @current_user.email, {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably worth having a record of when the digest email is sent. Maybe a new model.

Additionally, it's probably not going to be sent by someone visiting a URL, so maybe the code to send the digest could be a method on the users model, or a separate flow.

(I'll add a cron job to send this out automatically later)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the endpoint in a controller for testing purposes. I'll create a specific flow to be the mailer.

current_user: @current_user,
weekly_favorites: @weekly_favorites
}
10 changes: 10 additions & 0 deletions emails/user_digest.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
WeeklyFavoriteModules = require "widgets.base"

class UserDigest extends require "emails.base"
subject: => "LuaRocks Digest"
content: =>
h2 "Hello #{@current_user\name_for_display!}, here is your weekly digest from LuaRocks, enjoy!"

p "The more popular modules from this week!"
WeeklyFavoriteModules weekly_favorites: @weekly_favorites

5 changes: 5 additions & 0 deletions widgets/weekly_favorite_modules.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class WeeklyFavoriteModules extends require "widgets.page"
inner_content: =>
p "The more popular modules from this week!"
@render_modules @weekly_favorites