Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #22 from TACSUO/master

WOrk for eFrog
  • Loading branch information...
commit 0d23c07eb9fc3b7faaccfa17ad8d20b2fe33b0a3 2 parents 26f97b1 + eed6402
Jason LaPier 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(: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])
2  app/controllers/password_resets_controller.rb
View
@@ -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
38 app/models/message_post.rb
View
@@ -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
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=>'to_user_id = 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 :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>
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
6 public/javascripts/app.js
View
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.