From 23fa7a0a3e5d58e5ff49cd952e0e9e109d2e2ad1 Mon Sep 17 00:00:00 2001 From: Johannes Hackel Date: Tue, 29 Nov 2011 16:47:57 +0100 Subject: [PATCH] like stream new --- app/controllers/like_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 | 4 ++++ config/routes.rb | 2 ++ lib/stream/likes.rb | 22 +++++++++++++++++++ public/javascripts/pages/like-stream-index.js | 10 +++++++++ .../like_stream_controller_spec.rb | 19 ++++++++++++++++ spec/lib/stream/likes_spec.rb | 14 ++++++++++++ 10 files changed, 94 insertions(+) create mode 100644 app/controllers/like_stream_controller.rb create mode 100644 lib/stream/likes.rb create mode 100644 public/javascripts/pages/like-stream-index.js create mode 100644 spec/controllers/like_stream_controller_spec.rb create mode 100644 spec/lib/stream/likes_spec.rb diff --git a/app/controllers/like_stream_controller.rb b/app/controllers/like_stream_controller.rb new file mode 100644 index 000000000..f0434a74e --- /dev/null +++ b/app/controllers/like_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', 'likes') + +class LikeStreamController < ApplicationController + def index + default_stream_action(Stream::Likes) + end +end diff --git a/app/helpers/stream_helper.rb b/app/helpers/stream_helper.rb index c05db21b2..da00c5f0c 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?(CommentStreamController) comment_stream_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :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]) 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 4e13524a4..8524d78d4 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -36,6 +36,10 @@ class StatusMessage < Post scope :where_person_is_mentioned, lambda { |person| joins(:mentions).where(:mentions => {:person_id => person.id}) } + + scope :liked_by, lambda { |person| + joins(:likes).where(:likes => {:author_id => person.id}) + } scope :commented_by, lambda { |person| joins(:comments).where(:comments => {:author_id => person.id}).group("posts.id") diff --git a/app/views/aspects/index.html.haml b/app/views/aspects/index.html.haml index cbe9b0b4c..61cf89b7b 100644 --- a/app/views/aspects/index.html.haml +++ b/app/views/aspects/index.html.haml @@ -49,6 +49,12 @@ %b = link_to t('streams.comment_stream.title'), comment_stream_path, :class => 'home_selector' + .section + %ul.left_nav + %li + %b + = link_to t('streams.like_stream.title'), like_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 e30553236..a7877c55d 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -891,6 +891,10 @@ en: title: "Commented Posts" contacts_title: "People who posts you commented" + like_stream: + title: "Like Stream" + contacts_title: "People who Posts you like" + followed_tag: title: "#Followed Tags" contacts_title: "People who dig these tags" diff --git a/config/routes.rb b/config/routes.rb index 224e03a3e..fe6185b52 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -61,6 +61,8 @@ Diaspora::Application.routes.draw do 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' resources :apps, :only => [:show] diff --git a/lib/stream/likes.rb b/lib/stream/likes.rb new file mode 100644 index 000000000..9760ab38d --- /dev/null +++ b/lib/stream/likes.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::Likes < Stream::Base + def link(opts={}) + Rails.application.routes.url_helpers.like_stream_path(opts) + end + + def title + I18n.translate("streams.like_stream.title") + end + + # @return [ActiveRecord::Association] AR association of posts + def posts + @posts ||= StatusMessage.liked_by(self.user.person) + end + + def contacts_title + I18n.translate('streams.like_stream.contacts_title') + end +end diff --git a/public/javascripts/pages/like-stream-index.js b/public/javascripts/pages/like-stream-index.js new file mode 100644 index 000000000..6c63b58f5 --- /dev/null +++ b/public/javascripts/pages/like-stream-index.js @@ -0,0 +1,10 @@ +Diaspora.Pages.LikeStreamIndex = 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/controllers/like_stream_controller_spec.rb b/spec/controllers/like_stream_controller_spec.rb new file mode 100644 index 000000000..f013487be --- /dev/null +++ b/spec/controllers/like_stream_controller_spec.rb @@ -0,0 +1,19 @@ +# 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 'spec_helper' + +describe LikeStreamController do + describe 'index' do + it 'succeeds' do + get :index + response.should be_success + end + + it 'assigns a stream' do + get :index + assigns[:stream].should be_a Stream::Likes + end + end +end diff --git a/spec/lib/stream/likes_spec.rb b/spec/lib/stream/likes_spec.rb new file mode 100644 index 000000000..4a9dd8a5e --- /dev/null +++ b/spec/lib/stream/likes_spec.rb @@ -0,0 +1,14 @@ +require 'spec_helper' +require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream') + +describe Stream::Likes do + before do + @stream = Stream::Likes.new(alice, :max_time => Time.now, :order => 'updated_at') + end + + describe 'shared behaviors' do + it_should_behave_like 'it is a stream' + end +end + +