Skip to content

Commit

Permalink
adds the most followed/starred modules in the past week to the weekly…
Browse files Browse the repository at this point in the history
… digest
  • Loading branch information
aajjbb committed Aug 21, 2017
1 parent 698c975 commit 7b144b4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions applications/user.moon
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,18 @@ 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 =>
weekly_favorites_followings_query = db.query "select object_id, count(*) from followings
where object_type = module_type and created_at >= '7 days ago'
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"

UserDigest = require "emails.user_digest"
UserDigest\send @, @current_user.email, { current_user: @current_user, :weekly_favorites }
6 changes: 6 additions & 0 deletions emails/user_digest.moon
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import WidgetBase from require "widgets.base"

class UserDigest extends require "emails.base"
widgetToolkit = WidgetBase!

subject: => "LuaRocks Digest"
content: =>
h2 "Hello #{@user\name_for_display!}, here is your weekly digest from LuaRocks, enjoy!"

p "The more popular modules from this week!"
widgetToolkit\render_modules @weeklyPopular

0 comments on commit 7b144b4

Please sign in to comment.