diff --git a/app/controllers/comment_stream_controller.rb b/app/controllers/comment_stream_controller.rb new file mode 100644 index 000000000..e35579087 --- /dev/null +++ b/app/controllers/comment_stream_controller.rb @@ -0,0 +1,11 @@ +# Copyright (c) 2010-2011, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require File.join(Rails.root, 'lib','stream', 'comments') + +class CommentStreamController < ApplicationController + def index + default_stream_action(Stream::Comments) + end +end diff --git a/app/helpers/stream_helper.rb b/app/helpers/stream_helper.rb index bfd573616..c05db21b2 100644 --- a/app/helpers/stream_helper.rb +++ b/app/helpers/stream_helper.rb @@ -22,6 +22,8 @@ module StreamHelper public_stream_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order]) elsif controller.instance_of?(AspectsController) aspects_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :a_ids => @stream.aspect_ids, :sort_order => session[:sort_order]) + elsif controller.instance_of?(CommentStreamController) + comment_stream_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order]) else raise 'in order to use pagination for this new controller, update next_page_path in stream helper' end diff --git a/app/models/status_message.rb b/app/models/status_message.rb index 50fd79ea7..4e13524a4 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -37,6 +37,10 @@ class StatusMessage < Post joins(:mentions).where(:mentions => {:person_id => person.id}) } + scope :commented_by, lambda { |person| + joins(:comments).where(:comments => {:author_id => person.id}).group("posts.id") + } + def self.user_tag_stream(user, tag_ids) owned_or_visible_by_user(user). tag_stream(tag_ids) diff --git a/app/views/aspects/index.html.haml b/app/views/aspects/index.html.haml index 425a53d81..cbe9b0b4c 100644 --- a/app/views/aspects/index.html.haml +++ b/app/views/aspects/index.html.haml @@ -43,6 +43,12 @@ %b = link_to t('streams.mentions.title'), mentions_path, :class => 'home_selector' + .section + %ul.left_nav + %li + %b + = link_to t('streams.comment_stream.title'), comment_stream_path, :class => 'home_selector' + .section#followed_tags_listing = render 'tags/followed_tags_listings' diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index da70f333e..e30553236 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -887,6 +887,10 @@ en: title: "@Mentions" contacts_title: "People who mentioned you" + comment_stream: + title: "Commented Posts" + contacts_title: "People who posts you commented" + followed_tag: title: "#Followed Tags" contacts_title: "People who dig these tags" diff --git a/config/routes.rb b/config/routes.rb index 1be9714a8..224e03a3e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -59,6 +59,8 @@ Diaspora::Application.routes.draw do resources :mentions, :only => [:index] resources "tag_followings", :only => [:create] + get 'comment_stream' => 'comment_stream#index', :as => 'comment_stream' + get 'tags/:name' => 'tags#show', :as => 'tag' resources :apps, :only => [:show] diff --git a/lib/stream/comments.rb b/lib/stream/comments.rb new file mode 100644 index 000000000..68bd4e5e7 --- /dev/null +++ b/lib/stream/comments.rb @@ -0,0 +1,22 @@ +# Copyright (c) 2010-2011, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +class Stream::Comments < Stream::Base + def link(opts={}) + Rails.application.routes.url_helpers.comment_stream_path(opts) + end + + def title + I18n.translate("streams.comment_stream.title") + end + + # @return [ActiveRecord::Association] AR association of posts + def posts + @posts ||= StatusMessage.commented_by(self.user.person) + end + + def contacts_title + I18n.translate('streams.comment_stream.contacts_title') + end +end diff --git a/public/javascripts/pages/comment-stream-index.js b/public/javascripts/pages/comment-stream-index.js new file mode 100644 index 000000000..f79f52365 --- /dev/null +++ b/public/javascripts/pages/comment-stream-index.js @@ -0,0 +1,10 @@ +Diaspora.Pages.CommentStreamIndex = function() { + var self = this; + + this.subscribe("page/ready", function(evt, document) { + + self.aspectNavigation = self.instantiate("AspectNavigation", document.find("ul#aspect_nav")); + self.stream = self.instantiate("Stream", document.find("#aspect_stream_container")); + self.infiniteScroll = self.instantiate("InfiniteScroll"); + }); +}; diff --git a/spec/lib/stream/comments_spec.rb b/spec/lib/stream/comments_spec.rb new file mode 100644 index 000000000..0974de271 --- /dev/null +++ b/spec/lib/stream/comments_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' +require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream') + +describe Stream::Commments do + before do + @stream = Stream::Comments.new(alice, :max_time => Time.now, :order => 'updated_at') + end + + describe 'shared behaviors' do + it_should_behave_like 'it is a stream' + end +end