diff --git a/app/controllers/soups_controller.rb b/app/controllers/soups_controller.rb new file mode 100644 index 000000000..7de56d850 --- /dev/null +++ b/app/controllers/soups_controller.rb @@ -0,0 +1,9 @@ +require File.join(Rails.root, 'lib', 'stream', 'soup_stream') + +class SoupsController < ApplicationController + before_filter :redirect_unless_admin + + def index + default_stream_action(SoupStream) + end +end diff --git a/app/helpers/stream_helper.rb b/app/helpers/stream_helper.rb index d4d7a2f35..06bdf29ce 100644 --- a/app/helpers/stream_helper.rb +++ b/app/helpers/stream_helper.rb @@ -16,6 +16,8 @@ module StreamHelper featured_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order]) elsif controller.instance_of?(MentionsController) mentions_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order]) + elsif controller.instance_of?(SoupsController) + soup_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order]) elsif controller.instance_of?(PostsController) public_stream_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order]) elsif controller.instance_of?(AspectsController) diff --git a/app/models/status_message.rb b/app/models/status_message.rb index 9054eaf61..9cc74a711 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -42,6 +42,12 @@ class StatusMessage < Post )).select('DISTINCT posts.*') end + def self.tag_stream(user, tag_array, max_time, order) + owned_or_visible_by_user(user). + joins(:tags).where(:tags => {:name => tag_array}). + for_a_stream(max_time, order) + end + def text(opts = {}) self.formatted_message(opts) end diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 9d08201a8..1818910b7 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -844,6 +844,9 @@ en: public: title: "Public Activity" contacts_title: "Recent Posters" + soup: + titile: "The Soup" + contacts_title: "People in your Soup" users: logged_out: diff --git a/config/routes.rb b/config/routes.rb index ed28dd963..25881a366 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -113,6 +113,7 @@ Diaspora::Application.routes.draw do get 'featured_users' => "contacts#featured", :as => 'featured_users' + get 'soup' => "soups#index", :as => 'soup' resources :people, :except => [:edit, :update] do resources :status_messages diff --git a/lib/base_stream.rb b/lib/base_stream.rb index 620dfd3cb..038e14698 100644 --- a/lib/base_stream.rb +++ b/lib/base_stream.rb @@ -26,7 +26,7 @@ class BaseStream end def title - 'change me in lib/base_stream.rb!' + 'a title' end def posts @@ -48,7 +48,7 @@ class BaseStream end def contacts_link - 'change me in lib/base_stream.rb!' + '#' end #helpers diff --git a/lib/stream/aspect_stream.rb b/lib/stream/aspect_stream.rb index a0bbf90f9..d7338174f 100644 --- a/lib/stream/aspect_stream.rb +++ b/lib/stream/aspect_stream.rb @@ -23,7 +23,7 @@ class AspectStream < BaseStream def aspects @aspects ||= lambda do a = user.aspects - a = a.where(:id => @inputted_aspect_ids) if @inputted_aspect_ids.length > 0 + a = a.where(:id => @inputted_aspect_ids) if @inputted_aspect_ids.any? a end.call end diff --git a/lib/stream/soup_stream.rb b/lib/stream/soup_stream.rb new file mode 100644 index 000000000..5098b5726 --- /dev/null +++ b/lib/stream/soup_stream.rb @@ -0,0 +1,50 @@ +class SoupStream < BaseStream + def link(opts) + Rails.application.routes.url_helpers.soup_path + end + + def title + I18n.t('streams.soup.title') + end + + def contacts_title + I18n.t('streams.soup.contacts_title') + end + + def posts + post_ids = aspect_posts_ids + followed_tag_ids + mentioned_post_ids + post_ids += featured_user_post_ids + Post.where(:id => post_ids).for_a_stream(max_time, order) + end + + private + + def aspect_posts_ids + user.visible_post_ids(:limit => 15, :order => order, :max_time => max_time) + end + + def followed_tag_ids + StatusMessage.tag_stream(user, tag_array, max_time, order).map{|x| x.id} + end + + def mentioned_post_ids + ids(StatusMessage.where_person_is_mentioned(user.person).for_a_stream(max_time, order)) + end + + def featured_user_post_ids + ids(Post.all_public.where(:author_id => featured_user_ids).for_a_stream(max_time, order)) + end + + #worthless helpers + def featured_user_ids + ids(Person.featured_users) + end + + def tag_array + user.followed_tags.map{|x| x.name} + end + + def ids(enumerable) + enumerable.map{|x| x.id} + end +end diff --git a/lib/stream/tag_stream.rb b/lib/stream/tag_stream.rb index c84ea9a83..2a2e73f76 100644 --- a/lib/stream/tag_stream.rb +++ b/lib/stream/tag_stream.rb @@ -15,9 +15,7 @@ class TagStream < BaseStream # @return [ActiveRecord::Association] AR association of posts def posts return [] if tag_string.empty? - @posts ||= StatusMessage.owned_or_visible_by_user(user). - joins(:tags).where(:tags => {:name => tag_array}). - for_a_stream(@max_time, @order) + @posts ||= StatusMessage.tag_stream(user, tag_array, max_time, order) end def contacts_title diff --git a/public/javascripts/pages/soups-index.js b/public/javascripts/pages/soups-index.js new file mode 100644 index 000000000..989d1e95b --- /dev/null +++ b/public/javascripts/pages/soups-index.js @@ -0,0 +1,9 @@ +Diaspora.Pages.SoupsIndex = 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/soups_stream_spec.rb b/spec/lib/stream/soups_stream_spec.rb new file mode 100644 index 000000000..4f7153332 --- /dev/null +++ b/spec/lib/stream/soups_stream_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' +require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream') + +describe SoupStream do + before do + @stream = SoupStream.new(Factory(:user), :max_time => Time.now, :order => 'updated_at') + end + + describe 'shared behaviors' do + it_should_behave_like 'it is a stream' + end +end