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 Sep 8, 2017
1 parent 698c975 commit f911a24
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
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, {
current_user: @current_user,
weekly_favorites: @weekly_favorites
}
6 changes: 5 additions & 1 deletion emails/user_digest.moon
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
WeeklyFavoriteModules = require "widgets.base"

class UserDigest extends require "emails.base"
subject: => "LuaRocks Digest"
content: =>
h2 "Hello #{@user\name_for_display!}, here is your weekly digest from LuaRocks, enjoy!"
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

0 comments on commit f911a24

Please sign in to comment.