Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

order for all recent discussions

order recent discussions by  thread updates
  • Loading branch information...
commit 97e54b7a6b569ace064a22b0a0cbfe17ff1aafd4 1 parent 1fbb403
@griggsk griggsk authored
Showing with 37 additions and 7 deletions.
  1. +35 −3 app/models/message_post.rb
  2. +2 −4 public/javascripts/app.js
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=>'email_forum_activity = 1', :include => :user
+ if(self.email_forum_activity)
+ 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
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);
Please sign in to comment.
Something went wrong with that request. Please try again.