MS IZ start to implement followed tags in the stream

This commit is contained in:
Maxwell Salzberg 2011-09-16 18:19:34 -07:00
parent 3d275868ce
commit bc1aef4999
6 changed files with 93 additions and 3 deletions

View file

@ -1,6 +1,12 @@
require File.join(Rails.root, '/lib/tag_stream')
class TagFollowingsController < ApplicationController
before_filter :authenticate_user!
def index
@stream = TagStream.new(current_user)
render 'aspects/index', :locals => {:posts => @stream.posts}
end
# POST /tag_followings
# POST /tag_followings.xml
def create

View file

@ -10,6 +10,8 @@ module StreamHelper
"/apps/1?#{{:max_time => @posts.last.created_at.to_i}.to_param}"
elsif controller.instance_of?(PeopleController)
person_path(@person, :max_time => @posts.last.created_at.to_i)
elsif controller.instance_of?(TagFollowingsController)
tag_followings_path(:max_time => @stream.posts.last.created_at.to_i)
elsif controller.instance_of?(AspectsController)
aspects_path(:max_time => @stream.posts.last.send(@stream.order.to_sym).to_i, :a_ids => @stream.aspect_ids)
else

View file

@ -26,9 +26,9 @@
.span-13.append-1
#aspect_stream_container.stream_container
= render 'aspect_stream', :stream => @stream
= render 'aspects/aspect_stream', :stream => @stream
.span-5.rightBar.last
= render 'selected_contacts', :stream => @stream
= render 'aspects/selected_contacts', :stream => @stream
= render 'shared/right_sections'

View file

@ -51,6 +51,9 @@ Diaspora::Application.routes.draw do
post "tag_followings" => "tag_followings#create", :as => 'tag_tag_followings'
delete "tag_followings" => "tag_followings#destroy"
end
# get "tag_followings" => "tag_followings#index", :as => 'tag_followings'
get 'tags/:name' => 'tags#show', :as => 'tag'
resources :apps, :only => [:show]

66
lib/tag_stream.rb Normal file
View file

@ -0,0 +1,66 @@
# 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 TagStream
attr_reader :max_time, :order
# @param user [User]
# @param inputted_aspect_ids [Array<Integer>] Ids of aspects for given stream
# @param aspect_ids [Array<Integer>] Aspects this stream is responsible for
# @opt max_time [Integer] Unix timestamp of stream's post ceiling
# @opt order [String] Order of posts (i.e. 'created_at', 'updated_at')
# @return [void]
def initialize(user, opts={})
@tags = user.followed_tags
@tag_string = @tags.join(', '){|tag| tag.name}.to_sym
@user = user
@max_time = opts[:max_time]
@order = opts[:order]
end
# Filters aspects given the stream's aspect ids on initialization and the user.
# Will disclude aspects from inputted aspect ids if user is not associated with their
# target aspects.
#
# @return [ActiveRecord::Association<Aspect>] Filtered aspects given the stream's user
def aspects
[@tag_string]
end
# Maps ids into an array from #aspects
#
# @return [Array<Integer>] Aspect ids
def aspect_ids
[]
end
# @return [ActiveRecord::Association<Post>] AR association of posts
def posts
# NOTE(this should be something like Post.all_for_stream(@user, aspect_ids, {}) that calls visible_posts
@posts ||= StatusMessage.tagged_with([@tag_string], :any => true)
end
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
def people
@people ||= posts.map{|p| p.author}.uniq
end
# The first aspect in #aspects, given the stream is not for all aspects, or #aspects size is 1
# @note aspects.first is used for mobile. NOTE(this is a hack and should be fixed)
# @return [Aspect,Symbol]
def aspect
@tags_string
end
# Determine whether or not the stream is displaying across
# all of the user's aspects.
#
# @return [Boolean]
def for_all_aspects?
true
end
end

View file

@ -15,7 +15,20 @@ describe TagFollowingsController do
sign_in :user, bob
end
describe "POST create" do
describe 'index' do
it 'assings new TagStream' do
get :index
assigns[:stream].should be_a TagStream
end
it 'renders a view' do
get :index
response.body.should_not be_blank
end
end
describe "create" do
describe "with valid params" do
it "creates a new TagFollowing" do
expect {