Merge branch 'public_stream'

This commit is contained in:
Your Name 2011-10-06 17:13:17 -07:00
commit eed0db177d
21 changed files with 112 additions and 49 deletions

View file

@ -147,6 +147,18 @@ class ApplicationController < ActionController::Base
end
end
def default_stream_action(stream_klass)
authenticate_user!
save_sort_order
@stream = stream_klass.new(current_user, :max_time => params[:max_time], :order => sort_order)
if params[:only_posts]
render :partial => 'shared/stream', :locals => {:posts => @stream.posts}
else
render 'aspects/index'
end
end
def sort_order
is_mobile_device? ? 'created_at' : session[:sort_order]
end

View file

@ -1,15 +1,7 @@
require File.join(Rails.root, 'lib', 'stream', 'featured_users_stream')
class FeaturedUsersController < ApplicationController
before_filter :authenticate_user!
before_filter :save_sort_order, :only => :index
def index
@stream = FeaturedUsersStream.new(current_user, :max_time => params[:max_time], :order => sort_order)
if params[:only_posts]
render :partial => 'shared/stream', :locals => {:posts => @stream.posts}
else
render 'aspects/index'
end
default_stream_action(FeaturedUsersStream)
end
end

View file

@ -5,16 +5,7 @@
require File.join(Rails.root, 'lib','stream', 'mention_stream')
class MentionsController < ApplicationController
before_filter :authenticate_user!
before_filter :save_sort_order, :only => :index
def index
@stream = MentionStream.new(current_user, :max_time => params[:max_time], :order => sort_order)
if params[:only_posts]
render :partial => 'shared/stream', :locals => {:posts => @stream.posts}
else
render 'aspects/index'
end
default_stream_action(MentionStream)
end
end

View file

@ -2,9 +2,12 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require File.join(Rails.root, 'lib', 'stream', 'public_stream')
class PostsController < ApplicationController
before_filter :authenticate_user!, :except => :show
before_filter :set_format_if_malformed_from_status_net, :only => :show
before_filter :redirect_unless_admin, :only => :index
respond_to :html,
:mobile,
@ -59,6 +62,10 @@ class PostsController < ApplicationController
end
end
def index
default_stream_action(PublicStream)
end
def set_format_if_malformed_from_status_net
request.format = :html if request.format == 'application/html+xml'
end

View file

@ -1,6 +1,7 @@
# 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', 'public_stream')
class PublicsController < ApplicationController
require File.join(Rails.root, '/lib/diaspora/parser')
@ -13,6 +14,7 @@ class PublicsController < ApplicationController
skip_before_filter :set_grammatical_gender
before_filter :allow_cross_origin, :only => [:hcard, :host_meta, :webfinger]
before_filter :check_for_xml, :only => [:receive, :receive_public]
before_filter :authenticate_user!, :only => [:index]
respond_to :html
respond_to :xml, :only => :post

View file

@ -6,15 +6,9 @@ require File.join(Rails.root, 'lib', 'stream', 'tag_stream')
class TagFollowingsController < ApplicationController
before_filter :authenticate_user!
before_filter :save_sort_order, :only => :index
def index
@stream = TagStream.new(current_user, :max_time => params[:max_time], :order => sort_order)
if params[:only_posts]
render :partial => 'shared/stream', :locals => {:posts => @stream.posts}
else
render 'aspects/index'
end
default_stream_action(TagStream)
end
# POST /tag_followings

View file

@ -4,7 +4,7 @@
module PublisherHelper
def public_value
params[:controller] == "tags"
params[:controller] == "tags" || params[:controller] == "posts"
end
def remote?

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?(PostsController)
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])
else

View file

@ -41,6 +41,7 @@ class Post < ActiveRecord::Base
def self.for_a_stream(max_time, order)
by_max_time(max_time, order).
includes_for_a_stream.
where(:type => BaseStream::TYPES_OF_POST_IN_STREAM).
limit(15)
end

View file

@ -839,7 +839,9 @@ en:
tags:
title: "Posts tagged: %{tags}"
contacts_title: "People who dig these tags"
public:
title: "Public Activity"
contacts_title: "Recent Posters"
users:
logged_out:

View file

@ -20,7 +20,7 @@ Diaspora::Application.routes.draw do
resources :comments, :only => [:new, :create, :destroy, :index]
end
get 'p/:id' => 'posts#show', :as => 'short_post'
get 'public_stream' => 'posts#index', :as => 'public_stream'
# roll up likes into a nested resource above
resources :comments, :only => [:create, :destroy] do
resources :likes, :only => [:create, :destroy, :index]
@ -137,6 +137,7 @@ Diaspora::Application.routes.draw do
end
# External
resources :authorizations, :only => [:index, :destroy]

View file

@ -1,4 +1,5 @@
class BaseStream
TYPES_OF_POST_IN_STREAM = ['StatusMessage', 'Reshare', 'ActivityStreams::Photo']
attr_accessor :max_time, :order, :user
def initialize(user, opts={})
@ -7,18 +8,17 @@ class BaseStream
self.order = opts[:order]
end
def random_featured_user
Person.find_by_diaspora_handle(featured_diaspora_id)
@random_featured_user ||= Person.find_by_diaspora_handle(featured_diaspora_id)
end
def has_featured_users?
featured_diaspora_id.present?
random_featured_user.present?
end
#requied to implement said stream
def link(opts={})
Rails.application.routes.url_helpers.mentions_path(opts)
'change me in lib/base_stream.rb!'
end
def can_comment?(post)
@ -26,15 +26,17 @@ class BaseStream
end
def title
'a title'
'change me in lib/base_stream.rb!'
end
def posts
[]
end
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
def people
[]
people_ids = posts.map{|x| x.author_id}
Person.where(:id => people_ids).includes(:profile)
end
def contacts_link_title
@ -42,11 +44,11 @@ class BaseStream
end
def contacts_title
"title for a stream"
'change me in lib/base_stream.rb!'
end
def contacts_link
'#'
'change me in lib/base_stream.rb!'
end
#helpers

View file

@ -78,7 +78,7 @@ class RedisCache
# exposing the need to tie cache to a stream
# @return [Array<String>] Acceptable Post types for the given cache
def self.acceptable_types
::AspectStream::TYPES_OF_POST_IN_STREAM
BaseStream::TYPES_OF_POST_IN_STREAM
end
# Instantiate a redis connection

View file

@ -3,7 +3,6 @@
# the COPYRIGHT file.
class AspectStream < BaseStream
TYPES_OF_POST_IN_STREAM = ['StatusMessage', 'Reshare', 'ActivityStreams::Photo']
# @param user [User]
# @param inputted_aspect_ids [Array<Integer>] Ids of aspects for given stream

View file

@ -20,7 +20,7 @@ class FeaturedUsersStream < BaseStream
end
def posts
Post.all_public.where(:author_id => people.map{|x| x.id}, :type => AspectStream::TYPES_OF_POST_IN_STREAM).for_a_stream(max_time, order)
Post.all_public.where(:author_id => people.map{|x| x.id}).for_a_stream(max_time, order)
end
def people

View file

@ -17,11 +17,6 @@ class MentionStream< BaseStream
@posts ||= StatusMessage.where_person_is_mentioned(self.user.person).for_a_stream(max_time, order)
end
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
def people
@people ||= posts.map{|p| p.author}.uniq
end
def contacts_title
I18n.translate('streams.mentions.contacts_title')
end

View file

@ -0,0 +1,27 @@
# 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 PublicStream < BaseStream
def link(opts={})
Rails.application.routes.url_helpers.public_stream_path(opts)
end
def title
I18n.translate("streams.public.title")
end
# @return [ActiveRecord::Association<Post>] AR association of posts
def posts
@posts ||= Post.all_public.for_a_stream(max_time, order)
end
def contacts_title
I18n.translate("streams.public.contacts_title")
end
def can_comment?(post)
post.author.local?
end
end

View file

@ -20,10 +20,6 @@ class TagStream < BaseStream
for_a_stream(@max_time, @order)
end
def people
@people ||= posts.map{|p| p.author}.uniq
end
def contacts_title
I18n.translate('streams.tags.contacts_title')
end

View file

@ -0,0 +1,10 @@
Diaspora.Pages.PostsIndex = 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

@ -146,4 +146,23 @@ describe PostsController do
StatusMessage.exists?(message.id).should be_true
end
end
describe '#index' do
before do
sign_in alice
end
it 'will succeed if admin' do
AppConfig[:admins] = [alice.username]
get :index
response.should be_success
end
it 'will redirect if not' do
AppConfig[:admins] = []
get :index
response.should be_redirect
end
end
end

View file

@ -0,0 +1,11 @@
require 'spec_helper'
require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream')
describe PublicStream do
before do
@stream = PublicStream.new(stub)
end
describe 'shared behaviors' do
it_should_behave_like 'it is a stream'
end
end