Skip to content

Commit

Permalink
Fix number of args (#5041)
Browse files Browse the repository at this point in the history
* Fix number of args

* Fix instance variables

* Tiny fix

* Fix email deliver frequency

* Fix frequency
  • Loading branch information
siaw23-retired authored and jywarren committed Mar 13, 2019
1 parent e16df59 commit 10538ad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
9 changes: 5 additions & 4 deletions app/mailers/subscription_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ def notify_tag_added(node, tag, tagging_user)
)
end

def send_digest(user_id, nodes, freq)
if freq.zero?
@subject = "Your weekly digest"
elsif freq == 1
def send_digest(user_id, nodes, frequency)
if frequency == User::Frequency::DAILY
@subject = "Your daily digest"
elsif frequency == User::Frequency::WEEKLY
@subject = "Your weekly digest"
end

@user = User.find(user_id)
@nodes = nodes
mail(to: @user.email, subject: @subject)
Expand Down
29 changes: 18 additions & 11 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ module Status
].freeze
end

module Frequency
VALUES = [
DAILY = 0,
WEEKLY = 1
].freeze
end

attr_readonly :username

acts_as_authentic do |c|
Expand Down Expand Up @@ -309,24 +316,24 @@ def liked_notes

def liked_pages
nids = NodeSelection.where(user_id: uid, liking: true)
.collect(&:nid)
.collect(&:nid)

Node.where(nid: nids)
.where(type: 'page')
.order('nid DESC')
.where(type: 'page')
.order('nid DESC')
end

def send_digest_email
nodes = []
freq = 1
if has_tag('digest:daily')
nodes = content_followed_in_period(1.day.ago)
freq = 0
@nodes = content_followed_in_period(1.day.ago, Time.current)
@frequency = Frequency::DAILY
else
nodes = content_followed_in_period(Time.now - 1.week, Time.now)
freq = 1
@nodes = content_followed_in_period(1.week.ago, Time.current)
@frequency = Frequency::WEEKLY
end
if nodes.count > 0
SubscriptionMailer.send_digest(id, nodes, freq).deliver_now

if @nodes.size.positive?
SubscriptionMailer.send_digest(id, @nodes, @frequency).deliver_now
end
end

Expand Down

0 comments on commit 10538ad

Please sign in to comment.