Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

WOrk for eFrog #22

Merged
merged 4 commits into from

2 participants

@griggsk

Add email updates to forum threads and orders all recent discussions by latest update

griggsk added some commits
@griggsk griggsk order for all recent discussions
order recent discussions by  thread updates
97e54b7
@griggsk griggsk password reset bug
fixing missing route error
d82b984
@griggsk griggsk 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.
8e7a0b9
@griggsk griggsk fixing db column name eed6402
@jlapier jlapier merged commit 0d23c07 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 21, 2012
  1. @griggsk

    order for all recent discussions

    griggsk authored
    order recent discussions by  thread updates
  2. @griggsk

    password reset bug

    griggsk authored
    fixing missing route error
  3. @griggsk

    email updates

    griggsk authored
    adding email update feature to forum threads. User can opt in to
    receive email updates per thread. They can stop following threads too.
  4. @griggsk

    fixing db column name

    griggsk authored
This page is out of date. Refresh to see the latest.
View
24 app/controllers/message_posts_controller.rb
@@ -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(:to_user_id, 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])
View
2  app/controllers/password_resets_controller.rb
@@ -10,7 +10,7 @@ def create
if @user
@user.deliver_password_reset_instructions!
flash[:notice] = "We've sent instructions on how to reset your password to you. Please check your email."
- redirect_to root_url
+ redirect_to ('/')
else
flash[:notice] = "No user was found with that username or email address."
render :action => :new
View
38 app/models/message_post.rb
@@ -33,8 +33,7 @@ def last_page_number_for(conditions=nil)
# only for threads
def most_recent_reply
- @most_recent_reply ||= child_posts.find :first, :order => "message_posts.created_at DESC",
- :include => :user
+ @most_recent_reply ||= child_posts.find :first, :order => "message_posts.created_at DESC", :include => :user
end
def fix_blank_subject
@@ -50,7 +49,7 @@ def fix_blank_subject
def as_json(options = {})
options ||= {}
super(options.merge(
- :methods => [:poster, :forum_name, :post_time]))
+ :methods => [:poster, :forum_name, :post_time, :most_recent_reply_post_time]))
end
def poster
@@ -69,6 +68,39 @@ def post_time
end
end
+
+ def most_recent_reply_post_time
+ recent_reply = self.most_recent_reply
+ if(recent_reply)
+ return recent_reply.created_at.strftime "on %b %d, %Y"
+ else
+ return self.post_time
+ end
+ end
+
+ def posts_with_followers
+ posts = self.child_posts.find :all, :conditions=>'to_user_id = 1', :include => :user
+ if(self.to_user_id)
+ posts << self
+ end
+ return posts
+ end
+
+ def followers
+ posts = self.posts_with_followers
+ unique_followers = []
+ unique_posts = []
+ posts.each do |comment|
+ unless unique_posts.find{|c| c.user_id == comment.user_id}
+ unique_posts << comment
+ unique_followers << comment.user
+ end
+ end
+
+ return unique_followers
+ end
+
+
end
# == Schema Information
View
16 app/models/notifier.rb
@@ -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
View
4 app/models/user.rb
@@ -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=>'to_user_id = 1'
+ end
+
def deliver_password_reset_instructions!
# authlogic provides this:
reset_perishable_token!
View
4 app/views/message_posts/_message_form.html.erb
@@ -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 :to_user_id, :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>
View
11 app/views/message_posts/show.html.erb
@@ -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>
View
12 app/views/notifier/email_follower.erb
@@ -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.
View
1  config/routes.rb
@@ -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
View
6 public/javascripts/app.js
@@ -90,16 +90,14 @@ var CMSApp = {
var items = [];
$.each(data, function(key, val) {
- var m_post = val.message_post
+ var m_post = val.message_post;
var s_div = $('<div/>', { 'class' : 'subject' });
var link = $('<a/>', { html: m_post.subject,
href: '/forums/' + m_post.forum_id + '/message_posts/' + m_post.id } );
s_div.append(link);
s_div.append(' by ' + m_post.poster);
-
d_div = $('<div/>', { 'class' : 'date_and_forum',
- html:'<em>' + m_post.post_time + '</em> on ' + m_post.forum_name});
-
+ html:'<em>' + m_post.most_recent_reply_post_time + '</em> on ' + m_post.forum_name});
var li = $('<li/>');
li.append(s_div);
li.append(d_div);
Something went wrong with that request. Please try again.