From 4b25545e828eb82c2eba8a83917ec839765dc80f Mon Sep 17 00:00:00 2001 From: Johannes Hackel Date: Fri, 2 Dec 2011 15:03:15 +0100 Subject: [PATCH] fix sql error --- app/controllers/comment_stream_controller.rb | 11 ++++++++++ app/helpers/stream_helper.rb | 2 ++ app/models/status_message.rb | 4 ++++ app/views/aspects/index.html.haml | 6 +++++ config/locales/diaspora/en.yml | 6 ++++- config/routes.rb | 2 ++ lib/stream/comments.rb | 22 +++++++++++++++++++ .../javascripts/pages/comment-stream-index.js | 11 ++++++++++ spec/lib/stream/comments_spec.rb | 12 ++++++++++ 9 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 app/controllers/comment_stream_controller.rb create mode 100644 lib/stream/comments.rb create mode 100644 public/javascripts/pages/comment-stream-index.js create mode 100644 spec/lib/stream/comments_spec.rb 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 70d83c733..5ed677a7a 100644 --- a/app/helpers/stream_helper.rb +++ b/app/helpers/stream_helper.rb @@ -24,6 +24,8 @@ module StreamHelper 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?(LikeStreamController) like_stream_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :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 6f8e756ae..9f00ab46e 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| + select('DISTINCT "posts".*').joins(:comments).where(:comments => {:author_id => person.id}) + } + scope :liked_by, lambda { |person| joins(:likes).where(:likes => {:author_id => person.id}) } diff --git a/app/views/aspects/index.html.haml b/app/views/aspects/index.html.haml index 240bd3b10..61cf89b7b 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 %ul.left_nav %li diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 2da4f4e77..b4e3558a6 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -889,9 +889,13 @@ en: title: "@Mentions" contacts_title: "People who mentioned you" + comment_stream: + title: "Commented Posts" + contacts_title: "People who posts you commented" + like_stream: title: "Like Stream" - contacts_title: "People who Posts you like" + contacts_title: "People who posts you like" followed_tag: title: "#Followed Tags" diff --git a/config/routes.rb b/config/routes.rb index a25f05ada..99cce0ee3 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 'like_stream' => 'like_stream#index', :as => 'like_stream' get 'tags/:name' => 'tags#show', :as => 'tag' 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..b637f0bf5 --- /dev/null +++ b/public/javascripts/pages/comment-stream-index.js @@ -0,0 +1,11 @@ +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..e18655a9a --- /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::Comments 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