Merge branch 'public_stream'
This commit is contained in:
commit
eed0db177d
21 changed files with 112 additions and 49 deletions
|
|
@ -147,6 +147,18 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
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
|
def sort_order
|
||||||
is_mobile_device? ? 'created_at' : session[:sort_order]
|
is_mobile_device? ? 'created_at' : session[:sort_order]
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,7 @@
|
||||||
require File.join(Rails.root, 'lib', 'stream', 'featured_users_stream')
|
require File.join(Rails.root, 'lib', 'stream', 'featured_users_stream')
|
||||||
|
|
||||||
class FeaturedUsersController < ApplicationController
|
class FeaturedUsersController < ApplicationController
|
||||||
before_filter :authenticate_user!
|
|
||||||
before_filter :save_sort_order, :only => :index
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@stream = FeaturedUsersStream.new(current_user, :max_time => params[:max_time], :order => sort_order)
|
default_stream_action(FeaturedUsersStream)
|
||||||
if params[:only_posts]
|
|
||||||
render :partial => 'shared/stream', :locals => {:posts => @stream.posts}
|
|
||||||
else
|
|
||||||
render 'aspects/index'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,7 @@
|
||||||
require File.join(Rails.root, 'lib','stream', 'mention_stream')
|
require File.join(Rails.root, 'lib','stream', 'mention_stream')
|
||||||
|
|
||||||
class MentionsController < ApplicationController
|
class MentionsController < ApplicationController
|
||||||
before_filter :authenticate_user!
|
|
||||||
before_filter :save_sort_order, :only => :index
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@stream = MentionStream.new(current_user, :max_time => params[:max_time], :order => sort_order)
|
default_stream_action(MentionStream)
|
||||||
|
|
||||||
if params[:only_posts]
|
|
||||||
render :partial => 'shared/stream', :locals => {:posts => @stream.posts}
|
|
||||||
else
|
|
||||||
render 'aspects/index'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,12 @@
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
require File.join(Rails.root, 'lib', 'stream', 'public_stream')
|
||||||
|
|
||||||
class PostsController < ApplicationController
|
class PostsController < ApplicationController
|
||||||
before_filter :authenticate_user!, :except => :show
|
before_filter :authenticate_user!, :except => :show
|
||||||
before_filter :set_format_if_malformed_from_status_net, :only => :show
|
before_filter :set_format_if_malformed_from_status_net, :only => :show
|
||||||
|
before_filter :redirect_unless_admin, :only => :index
|
||||||
|
|
||||||
respond_to :html,
|
respond_to :html,
|
||||||
:mobile,
|
:mobile,
|
||||||
|
|
@ -59,6 +62,10 @@ class PostsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def index
|
||||||
|
default_stream_action(PublicStream)
|
||||||
|
end
|
||||||
|
|
||||||
def set_format_if_malformed_from_status_net
|
def set_format_if_malformed_from_status_net
|
||||||
request.format = :html if request.format == 'application/html+xml'
|
request.format = :html if request.format == 'application/html+xml'
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
require File.join(Rails.root, 'lib', 'stream', 'public_stream')
|
||||||
|
|
||||||
class PublicsController < ApplicationController
|
class PublicsController < ApplicationController
|
||||||
require File.join(Rails.root, '/lib/diaspora/parser')
|
require File.join(Rails.root, '/lib/diaspora/parser')
|
||||||
|
|
@ -13,6 +14,7 @@ class PublicsController < ApplicationController
|
||||||
skip_before_filter :set_grammatical_gender
|
skip_before_filter :set_grammatical_gender
|
||||||
before_filter :allow_cross_origin, :only => [:hcard, :host_meta, :webfinger]
|
before_filter :allow_cross_origin, :only => [:hcard, :host_meta, :webfinger]
|
||||||
before_filter :check_for_xml, :only => [:receive, :receive_public]
|
before_filter :check_for_xml, :only => [:receive, :receive_public]
|
||||||
|
before_filter :authenticate_user!, :only => [:index]
|
||||||
|
|
||||||
respond_to :html
|
respond_to :html
|
||||||
respond_to :xml, :only => :post
|
respond_to :xml, :only => :post
|
||||||
|
|
|
||||||
|
|
@ -6,15 +6,9 @@ require File.join(Rails.root, 'lib', 'stream', 'tag_stream')
|
||||||
|
|
||||||
class TagFollowingsController < ApplicationController
|
class TagFollowingsController < ApplicationController
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!
|
||||||
before_filter :save_sort_order, :only => :index
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@stream = TagStream.new(current_user, :max_time => params[:max_time], :order => sort_order)
|
default_stream_action(TagStream)
|
||||||
if params[:only_posts]
|
|
||||||
render :partial => 'shared/stream', :locals => {:posts => @stream.posts}
|
|
||||||
else
|
|
||||||
render 'aspects/index'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# POST /tag_followings
|
# POST /tag_followings
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
module PublisherHelper
|
module PublisherHelper
|
||||||
def public_value
|
def public_value
|
||||||
params[:controller] == "tags"
|
params[:controller] == "tags" || params[:controller] == "posts"
|
||||||
end
|
end
|
||||||
|
|
||||||
def remote?
|
def remote?
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ module StreamHelper
|
||||||
featured_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order])
|
featured_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order])
|
||||||
elsif controller.instance_of?(MentionsController)
|
elsif controller.instance_of?(MentionsController)
|
||||||
mentions_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order])
|
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)
|
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])
|
aspects_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :a_ids => @stream.aspect_ids, :sort_order => session[:sort_order])
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ class Post < ActiveRecord::Base
|
||||||
def self.for_a_stream(max_time, order)
|
def self.for_a_stream(max_time, order)
|
||||||
by_max_time(max_time, order).
|
by_max_time(max_time, order).
|
||||||
includes_for_a_stream.
|
includes_for_a_stream.
|
||||||
|
where(:type => BaseStream::TYPES_OF_POST_IN_STREAM).
|
||||||
limit(15)
|
limit(15)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -839,7 +839,9 @@ en:
|
||||||
tags:
|
tags:
|
||||||
title: "Posts tagged: %{tags}"
|
title: "Posts tagged: %{tags}"
|
||||||
contacts_title: "People who dig these tags"
|
contacts_title: "People who dig these tags"
|
||||||
|
public:
|
||||||
|
title: "Public Activity"
|
||||||
|
contacts_title: "Recent Posters"
|
||||||
|
|
||||||
users:
|
users:
|
||||||
logged_out:
|
logged_out:
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ Diaspora::Application.routes.draw do
|
||||||
resources :comments, :only => [:new, :create, :destroy, :index]
|
resources :comments, :only => [:new, :create, :destroy, :index]
|
||||||
end
|
end
|
||||||
get 'p/:id' => 'posts#show', :as => 'short_post'
|
get 'p/:id' => 'posts#show', :as => 'short_post'
|
||||||
|
get 'public_stream' => 'posts#index', :as => 'public_stream'
|
||||||
# roll up likes into a nested resource above
|
# roll up likes into a nested resource above
|
||||||
resources :comments, :only => [:create, :destroy] do
|
resources :comments, :only => [:create, :destroy] do
|
||||||
resources :likes, :only => [:create, :destroy, :index]
|
resources :likes, :only => [:create, :destroy, :index]
|
||||||
|
|
@ -137,6 +137,7 @@ Diaspora::Application.routes.draw do
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# External
|
# External
|
||||||
|
|
||||||
resources :authorizations, :only => [:index, :destroy]
|
resources :authorizations, :only => [:index, :destroy]
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
class BaseStream
|
class BaseStream
|
||||||
|
TYPES_OF_POST_IN_STREAM = ['StatusMessage', 'Reshare', 'ActivityStreams::Photo']
|
||||||
attr_accessor :max_time, :order, :user
|
attr_accessor :max_time, :order, :user
|
||||||
|
|
||||||
def initialize(user, opts={})
|
def initialize(user, opts={})
|
||||||
|
|
@ -7,18 +8,17 @@ class BaseStream
|
||||||
self.order = opts[:order]
|
self.order = opts[:order]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def random_featured_user
|
def random_featured_user
|
||||||
Person.find_by_diaspora_handle(featured_diaspora_id)
|
@random_featured_user ||= Person.find_by_diaspora_handle(featured_diaspora_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_featured_users?
|
def has_featured_users?
|
||||||
featured_diaspora_id.present?
|
random_featured_user.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
#requied to implement said stream
|
#requied to implement said stream
|
||||||
def link(opts={})
|
def link(opts={})
|
||||||
Rails.application.routes.url_helpers.mentions_path(opts)
|
'change me in lib/base_stream.rb!'
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_comment?(post)
|
def can_comment?(post)
|
||||||
|
|
@ -26,15 +26,17 @@ class BaseStream
|
||||||
end
|
end
|
||||||
|
|
||||||
def title
|
def title
|
||||||
'a title'
|
'change me in lib/base_stream.rb!'
|
||||||
end
|
end
|
||||||
|
|
||||||
def posts
|
def posts
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
|
||||||
def people
|
def people
|
||||||
[]
|
people_ids = posts.map{|x| x.author_id}
|
||||||
|
Person.where(:id => people_ids).includes(:profile)
|
||||||
end
|
end
|
||||||
|
|
||||||
def contacts_link_title
|
def contacts_link_title
|
||||||
|
|
@ -42,11 +44,11 @@ class BaseStream
|
||||||
end
|
end
|
||||||
|
|
||||||
def contacts_title
|
def contacts_title
|
||||||
"title for a stream"
|
'change me in lib/base_stream.rb!'
|
||||||
end
|
end
|
||||||
|
|
||||||
def contacts_link
|
def contacts_link
|
||||||
'#'
|
'change me in lib/base_stream.rb!'
|
||||||
end
|
end
|
||||||
|
|
||||||
#helpers
|
#helpers
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ class RedisCache
|
||||||
# exposing the need to tie cache to a stream
|
# exposing the need to tie cache to a stream
|
||||||
# @return [Array<String>] Acceptable Post types for the given cache
|
# @return [Array<String>] Acceptable Post types for the given cache
|
||||||
def self.acceptable_types
|
def self.acceptable_types
|
||||||
::AspectStream::TYPES_OF_POST_IN_STREAM
|
BaseStream::TYPES_OF_POST_IN_STREAM
|
||||||
end
|
end
|
||||||
|
|
||||||
# Instantiate a redis connection
|
# Instantiate a redis connection
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
class AspectStream < BaseStream
|
class AspectStream < BaseStream
|
||||||
TYPES_OF_POST_IN_STREAM = ['StatusMessage', 'Reshare', 'ActivityStreams::Photo']
|
|
||||||
|
|
||||||
# @param user [User]
|
# @param user [User]
|
||||||
# @param inputted_aspect_ids [Array<Integer>] Ids of aspects for given stream
|
# @param inputted_aspect_ids [Array<Integer>] Ids of aspects for given stream
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ class FeaturedUsersStream < BaseStream
|
||||||
end
|
end
|
||||||
|
|
||||||
def posts
|
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
|
end
|
||||||
|
|
||||||
def people
|
def people
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,6 @@ class MentionStream< BaseStream
|
||||||
@posts ||= StatusMessage.where_person_is_mentioned(self.user.person).for_a_stream(max_time, order)
|
@posts ||= StatusMessage.where_person_is_mentioned(self.user.person).for_a_stream(max_time, order)
|
||||||
end
|
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
|
def contacts_title
|
||||||
I18n.translate('streams.mentions.contacts_title')
|
I18n.translate('streams.mentions.contacts_title')
|
||||||
end
|
end
|
||||||
|
|
|
||||||
27
lib/stream/public_stream.rb
Normal file
27
lib/stream/public_stream.rb
Normal 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
|
||||||
|
|
@ -20,10 +20,6 @@ class TagStream < BaseStream
|
||||||
for_a_stream(@max_time, @order)
|
for_a_stream(@max_time, @order)
|
||||||
end
|
end
|
||||||
|
|
||||||
def people
|
|
||||||
@people ||= posts.map{|p| p.author}.uniq
|
|
||||||
end
|
|
||||||
|
|
||||||
def contacts_title
|
def contacts_title
|
||||||
I18n.translate('streams.tags.contacts_title')
|
I18n.translate('streams.tags.contacts_title')
|
||||||
end
|
end
|
||||||
|
|
|
||||||
10
public/javascripts/pages/posts-index.js
Normal file
10
public/javascripts/pages/posts-index.js
Normal 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");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
@ -146,4 +146,23 @@ describe PostsController do
|
||||||
StatusMessage.exists?(message.id).should be_true
|
StatusMessage.exists?(message.id).should be_true
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
||||||
11
spec/lib/stream/public_stream_spec.rb
Normal file
11
spec/lib/stream/public_stream_spec.rb
Normal 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
|
||||||
Loading…
Reference in a new issue