who wants a goat that fetches SOAP?!!

This commit is contained in:
Maxwell Salzberg 2011-10-13 21:29:45 -07:00
parent 213a1af0bc
commit 44b0887e0a
11 changed files with 96 additions and 6 deletions

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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:

View file

@ -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

View file

@ -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

View file

@ -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

50
lib/stream/soup_stream.rb Normal file
View file

@ -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

View file

@ -15,9 +15,7 @@ class TagStream < BaseStream
# @return [ActiveRecord::Association<Post>] 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

View file

@ -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");
});
};

View file

@ -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