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

Commit

Permalink
order for all recent discussions
Browse files Browse the repository at this point in the history
order recent discussions by  thread updates
  • Loading branch information
griggsk committed Oct 21, 2012
1 parent 1fbb403 commit 97e54b7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
38 changes: 35 additions & 3 deletions app/models/message_post.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions public/javascripts/app.js
Expand Up @@ -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);
Expand Down

0 comments on commit 97e54b7

Please sign in to comment.