Skip to content
This repository has been archived by the owner on Jun 26, 2022. It is now read-only.

Commit

Permalink
Send notifications on new posts to repo owners.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Sep 28, 2012
1 parent 0dc9022 commit aa3631a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions app/controllers/v1/posts_controller.rb
Expand Up @@ -56,12 +56,14 @@ def create
)

if @post.save
user_email = @post.user.email
subscribers = @topic.poster_emails.select do |email|
email != user_email
end
subscribers.each do |subscriber|
TopicMailer.delay.new_post_email(@post, subscriber)
# Send emails to:
# * Folk(s) who own current repo.
# * Folks who posted in current thread.
is_org = (@user.type == 'Organization')
owners = is_org ? @user.owners.pluck(:email).compact : [@user.email]
subscribers = @topic.poster_emails - [@post.user.email]
(owners + subscribers).uniq.each do |email_address|
TopicMailer.delay.new_post_email(@post, email_address)
end

render json: to_json(@post), status: :created
Expand Down

0 comments on commit aa3631a

Please sign in to comment.