Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

email updates

adding email update feature to forum threads. User can opt in to
receive email updates per thread. They can stop following threads too.
  • Loading branch information...
commit 8e7a0b9ef00cf51bb529ee68cc24d78c01fcc08c 1 parent d82b984
griggsk griggsk authored
24 app/controllers/message_posts_controller.rb
View
@@ -17,6 +17,7 @@ def show
redirect_to forum_message_post_url(@forum, @message_post.thread, :anchor => @message_post.id)
else
@child_posts = @message_post.child_posts.paginate :page => params[:page], :order => 'created_at ASC'
+ @followers = @message_post.followers
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @message_post }
@@ -53,7 +54,10 @@ def create
flash[:notice] = "Posted: #{@message_post.subject}"
format.html do
if @message_post.thread
- @message_post.thread.update_attribute(:updated_at, Time.now)
+ @message_post.thread.update_attribute(:updated_at, Time.now)
+ @message_post.thread.followers.each do |poster|
+ Notifier.email_follower( @message_post, poster).deliver
+ end
redirect_to forum_message_post_url(@forum, @message_post.thread, :anchor => @message_post.id,
:page => @message_post.thread.child_posts.last_page_number_for)
else
@@ -99,7 +103,23 @@ def destroy
end
-
+ # DELETE /forums/1/message_posts/1/stop_following
+ # DELETE /forums/1/message_posts/1.xml/stop_following
+ def stop_following
+ @message_post = MessagePost.find(params[:id]) #@forum.message_posts.find(params[:id])
+ posts = @message_post.posts_with_followers
+ posts.each do |post|
+ if post.user == current_user
+ post.update_attribute(:email_forum_activity, 0)
+ end
+ end
+ respond_to do |format|
+ flash[:notice] = "Stopped following Post '#{@message_post.subject}'."
+ format.html { redirect_to forum_message_post_url(@forum, @message_post.thread) }
+ format.xml { head :ok }
+ end
+ end
+
protected
def get_forum
@forum ||= Forum.find(params[:forum_id])
16 app/models/notifier.rb
View
@@ -39,4 +39,20 @@ def published_blog_post_updated(post, updating_user)
@post_link = "Full Post: #{blog_post_url(post)}"
@admin_link = "Blog Admin: #{blog_dashboard_url}"
end
+
+ def email_follower(post, follower)
+ subject "[eFrog - #{post.thread.forum.title.truncate(23)}] #{post.subject.truncate(23)}"
+ recipients follower.email
+ from SiteSetting.read_setting('site email') || 'root'
+ content_type "text/html"
+ sent_on Time.now
+
+ @follower = follower.full_name
+ @thread = post.thread
+ @post_title = ActionController::Base.helpers.sanitize(post.subject)
+ @post_body = ActionController::Base.helpers.sanitize(post.body)
+ @forum = @thread.forum
+ @link = forum_message_post_url(@forum, @thread)
+ end
+
end
4 app/models/user.rb
View
@@ -89,6 +89,10 @@ def forums
@forums ||= Forum.find(user_groups.map { |g| g.forums.keys }.flatten.uniq)
end
+ def following_posts
+ return self.message_posts.find :all, :conditions=>'email_forum_activity = 1'
+ end
+
def deliver_password_reset_instructions!
# authlogic provides this:
reset_perishable_token!
4 app/views/message_posts/_message_form.html.erb
View
@@ -1,3 +1,4 @@
+<% @followers ||= []%>
<% if current_user -%>
<div id="message_box">
<% opts = message_post.new_record? ? { :url => forum_message_posts_path(@forum) } : { :url => forum_message_post_path(@forum, message_post), :method => :put } %>
@@ -5,6 +6,9 @@
<%= f.error_messages %>
<%= f.hidden_field(:forum_id) %>
<%= f.hidden_field(:thread_id) %>
+ <%if( !message_post.new_record? || !@followers.include?(current_user) )%>
+ <p>Email updates to me: <%= f.check_box :email_forum_activity, :value => 1 %></p>
+ <%end%>
<p>Subject: <%= f.text_field :subject %></p>
<p><%= f.text_area :body, :cols => 60, :rows => 10 %></p>
<p><%= submit_tag "Post it!" %></p>
11 app/views/message_posts/show.html.erb
View
@@ -31,7 +31,8 @@
<h3>Reply to this thread:</h3>
<%= render :partial => "message_form",
- :locals => { :message_post => MessagePost.new(:thread => @message_post, :subject => "RE: #{@message_post.subject}") } %>
+ :locals => { :message_post => MessagePost.new(:thread => @message_post, :subject => "RE: #{@message_post.subject}"), :followers => [@followers] }
+%>
<p class="small_text">
@@ -44,4 +45,12 @@
<%= link_to 'delete this message thread', forum_message_post_path(@forum, @message_post), :method => :delete,
:confirm => 'Are you sure you want to delete this thread and all the messages in it?' %>
<% end %>
+<br />
+
+<h3>Following this Thread</h3>
+<ul>
+ <% for user in @followers -%>
+ <li><%= user.full_name%> <%if user == current_user%>(<%= link_to 'stop following', stop_following_forum_message_post_path(@forum, @message_post), :method => :post %>)<%end%></li>
+ <% end -%>
+</ul>
12 app/views/notifier/email_follower.erb
View
@@ -0,0 +1,12 @@
+A new post by <%= @follower%>
+<br><br>
+Full Thread: <%= @link %>
+<br><br>
+--------
+<%= @post_body %>
+--------
+<br><br>
+This message was sent to you because you signed up to receive email updates for new comments to <%=@thread.subject%> from the eFrog Forum <%=@forum.title%>.
+To stop receiving emails go to the <%= link_to('post', @link) %> and click on the 'stop following' link next to your name in the 'Following this Thread' section of the page.
+<br><br>
+This is an automated email. Do not respond.
1  config/routes.rb
View
@@ -88,6 +88,7 @@
resources :message_posts do
member do
get "/:user_credentials/feed" => "message_posts#show", :as => :feed
+ post :stop_following
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.