diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 137590998..adf460372 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -137,4 +137,17 @@ class ApplicationController < ActionController::Base @tags ||= current_user.followed_tags end + def save_sort_order + if params[:sort_order].present? + session[:sort_order] = (params[:sort_order] == 'created_at') ? 'created_at' : 'updated_at' + elsif session[:sort_order].blank? + session[:sort_order] = 'updated_at' + else + session[:sort_order] = (session[:sort_order] == 'created_at') ? 'created_at' : 'updated_at' + end + end + + def sort_order + is_mobile_device? ? 'created_at' : session[:sort_order] + end end diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 66ebf6940..b19671e2a 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -138,18 +138,4 @@ class AspectsController < ApplicationController end private - def save_sort_order - if params[:sort_order].present? - session[:sort_order] = (params[:sort_order] == 'created_at') ? 'created_at' : 'updated_at' - elsif session[:sort_order].blank? - session[:sort_order] = 'created_at' - else - session[:sort_order] = (session[:sort_order] == 'created_at') ? 'created_at' : 'updated_at' - end - end - - def sort_order - is_mobile_device? ? 'created_at' : session[:sort_order] - end - end diff --git a/app/controllers/mentions_controller.rb b/app/controllers/mentions_controller.rb index ac4d7efd0..862b90174 100644 --- a/app/controllers/mentions_controller.rb +++ b/app/controllers/mentions_controller.rb @@ -1,9 +1,10 @@ require File.join(Rails.root, '/lib/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]) + @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} diff --git a/app/controllers/tag_followings_controller.rb b/app/controllers/tag_followings_controller.rb index 2fb93398a..7a0865312 100644 --- a/app/controllers/tag_followings_controller.rb +++ b/app/controllers/tag_followings_controller.rb @@ -1,9 +1,10 @@ require File.join(Rails.root, '/lib/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]) + @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} diff --git a/app/helpers/stream_helper.rb b/app/helpers/stream_helper.rb index 1d259cf1a..33228ac2d 100644 --- a/app/helpers/stream_helper.rb +++ b/app/helpers/stream_helper.rb @@ -22,7 +22,7 @@ module StreamHelper end def time_for_scroll(ajax_stream, stream) - if ajax_stream + if ajax_stream || stream.posts.empty? (Time.now() + 1).to_i else stream.posts.last.send(stream.order.to_sym).to_i diff --git a/app/models/post.rb b/app/models/post.rb index 09b3380ef..546412020 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -35,7 +35,9 @@ class Post < ActiveRecord::Base scope :all_public, where(:public => true, :pending => false) def self.for_a_stream(max_time, order) - where("#{order} < ?", max_time).order("#{order} desc").includes({:author => :profile}, :mentions).limit(15) + where("posts.#{order} < ?", max_time).order("posts.#{order} desc"). + includes({:author => :profile}, :mentions => {:person => :profile}). + limit(15) end def diaspora_handle diff --git a/app/models/status_message.rb b/app/models/status_message.rb index 284cb517f..c580f5733 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -26,6 +26,8 @@ class StatusMessage < Post after_create :create_mentions + scope :where_person_is_mentioned, lambda{|person| joins(:mentions).where(:mentions => {:person_id => person.id})} + def text(opts = {}) self.formatted_message(opts) end diff --git a/app/views/aspects/_aspect_stream.haml b/app/views/aspects/_aspect_stream.haml index b63c0b1d8..08954106b 100644 --- a/app/views/aspects/_aspect_stream.haml +++ b/app/views/aspects/_aspect_stream.haml @@ -20,8 +20,7 @@ = render 'aspects/no_contacts_message' #main_stream.stream{:data => {:guids => stream.aspect_ids.join(',')}} - - if stream.ajax_stream? - - elsif stream.posts.length > 0 + - if !stream.ajax_stream? && stream.posts.length > 0 = render 'shared/stream', :posts => stream.posts #pagination - =link_to(t('more'), next_page_path(:ajax_stream => stream.ajax_stream?, :class => 'paginate') + =link_to(t('more'), next_page_path(:ajax_stream => stream.ajax_stream?), :class => 'paginate') diff --git a/app/views/aspects/index.html.haml b/app/views/aspects/index.html.haml index 59611a003..005764d9a 100644 --- a/app/views/aspects/index.html.haml +++ b/app/views/aspects/index.html.haml @@ -22,7 +22,9 @@ = render 'aspects/aspect_listings' .section - = link_to "Mentions", mentions_path + %ul.left_nav + .li + %b= link_to t('.mentions'), mentions_path, :class => 'home_selector' .section#followed_tags_listing = render 'tags/followed_tags_listings' diff --git a/app/views/tags/_followed_tags_listings.haml b/app/views/tags/_followed_tags_listings.haml index 8270cb9dc..7bd2e56e9 100644 --- a/app/views/tags/_followed_tags_listings.haml +++ b/app/views/tags/_followed_tags_listings.haml @@ -5,8 +5,7 @@ - if user_signed_in? %ul.left_nav %li - %div.root_element - =link_to t('aspects.index.tags_following'), tag_followings_path + %b=link_to t('aspects.index.tags_following'), tag_followings_path, :class => 'home_selector' %ul.sub_nav - if tags.size > 0 diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index fbe2ed6b7..c5a01e04f 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -106,6 +106,7 @@ en: done_editing: "done editing" aspect_stream: stream: "Stream" + mentions: "Mentions" recently: "recently:" commented_on: "commented on" posted: "posted" @@ -155,6 +156,7 @@ en: acquaintances: "Acquaintances" friends: "Friends" index: + mentions: "Mentions" donate: "Donate" keep_us_running: "Keep %{pod} running fast and buy servers their coffee fix with a monthly donation!" your_aspects: "Your Aspects" @@ -824,7 +826,15 @@ en: index: revoke_access: "Revoke Access" no_applications: "You haven't registered any applications yet." - + + streams: + mentions: + title: "Your Mentions" + contacts_title: "People who mentioned you" + tags: + title: "Posts tagged: %{tags}" + contacts_title: "People who dig these tags" + users: logged_out: diff --git a/lib/aspect_stream.rb b/lib/aspect_stream.rb index 06ee3993c..371d0658c 100644 --- a/lib/aspect_stream.rb +++ b/lib/aspect_stream.rb @@ -2,9 +2,8 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -class AspectStream - - attr_reader :max_time, :order +class AspectStream < BaseStream + TYPES_OF_POST_IN_STREAM = ['StatusMessage', 'Reshare', 'ActivityStreams::Photo'] # @param user [User] # @param inputted_aspect_ids [Array] Ids of aspects for given stream @@ -13,10 +12,8 @@ class AspectStream # @opt order [String] Order of posts (i.e. 'created_at', 'updated_at') # @return [void] def initialize(user, inputted_aspect_ids, opts={}) - @user = user + super(user, opts) @inputted_aspect_ids = inputted_aspect_ids - @max_time = opts[:max_time] - @order = opts[:order] end # Filters aspects given the stream's aspect ids on initialization and the user. @@ -43,10 +40,10 @@ class AspectStream def posts # NOTE(this should be something like Post.all_for_stream(@user, aspect_ids, {}) that calls visible_posts @posts ||= @user.visible_posts(:by_members_of => aspect_ids, - :type => ['StatusMessage', 'Reshare', 'ActivityStreams::Photo'], + :type => TYPES_OF_POST_IN_STREAM, :order => "#{@order} DESC", :max_time => @max_time - ).includes(:mentions => {:person => :profile}, :author => :profile) + ).for_a_stream(max_time, order) end # @return [ActiveRecord::Association] AR association of people within stream's given aspects @@ -73,7 +70,7 @@ class AspectStream def title if self.for_all_aspects? - I18n.t('.stream') + I18n.t('aspects.aspect_stream.stream') else self.aspects.to_sentence end diff --git a/lib/base_stream.rb b/lib/base_stream.rb new file mode 100644 index 000000000..c2eb82118 --- /dev/null +++ b/lib/base_stream.rb @@ -0,0 +1,72 @@ +class BaseStream + + + attr_accessor :max_time, :order, :user + + def initialize(user, opts={}) + self.user = user + self.max_time = opts[:max_time] + self.order = opts[:order] + end + + + + #requied to implement said stream + def link(opts={}) + Rails.application.routes.url_helpers.mentions_path(opts) + end + + def title + 'a title' + end + + def posts + [] + end + + def people + [] + end + + def contacts_title + "title for a stream" + end + + def contacts_link + '#' + end + + #helpers + def ajax_stream? + false + end + + def for_all_aspects? + true + end + + + #NOTE: MBS bad bad methods the fact we need these means our views are foobared. please kill them and make them + #private methods on the streams that need them + def aspects + @user.aspects + end + + def aspect + aspects.first + end + + def aspect_ids + aspects.map{|x| x.id} + end + + def max_time=(time_string) + @max_time = Time.at(time_string.to_i) unless time_string.blank? + @max_time ||= (Time.now + 1) + end + + def order=(order_string) + @order = order_string + @order ||= 'created_at' + end +end diff --git a/lib/mention_stream.rb b/lib/mention_stream.rb index 5957a1ad6..c182d8549 100644 --- a/lib/mention_stream.rb +++ b/lib/mention_stream.rb @@ -2,9 +2,8 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -class MentionStream +class MentionStream< BaseStream - attr_reader :max_time, :order # @param user [User] # @param inputted_aspect_ids [Array] Ids of aspects for given stream @@ -12,29 +11,19 @@ class MentionStream # @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={}) - @user = user - set_max_time(opts[:max_time]) - - @order = opts[:order] || 'created_at' - end - - def set_max_time(time_string) - @max_time = Time.at(time_string.to_i) unless time_string.blank? - @max_time ||= (Time.now + 1) - end def link(opts={}) Rails.application.routes.url_helpers.mentions_path(opts) end def title - "Your Mentions" + I18n.translate("streams.mentions.title") end + # @return [ActiveRecord::Association] AR association of posts def posts - @posts ||= Post.joins(:mentions).where(:mentions => {:person_id => @user.person.id}).for_a_stream(@max_time, @order) + @posts ||= StatusMessage.where_person_is_mentioned(self.user.person).for_a_stream(max_time, order) end # @return [ActiveRecord::Association] AR association of people within stream's given aspects @@ -42,31 +31,7 @@ class MentionStream @people ||= posts.map{|p| p.author}.uniq end - def for_all_aspects? - false - end - - def ajax_posts? - false - end - - def aspects - [] - end - - def aspect - nil - end - def contacts_title - "People who mentioned you" - end - - def contacts_link - '#' - end - - def aspect_ids - [] + I18n.translate('streams.mentions.contacts_title') end end diff --git a/lib/tag_stream.rb b/lib/tag_stream.rb index 375c82043..594be8a1f 100644 --- a/lib/tag_stream.rb +++ b/lib/tag_stream.rb @@ -2,41 +2,23 @@ # 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] Ids of aspects for given stream - # @param aspect_ids [Array] 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_s - @user = user - set_max_time(opts[:max_time]) - - @order = opts[:order] || 'created_at' - end - - def set_max_time(time_string) - @max_time = Time.at(time_string.to_i) unless time_string.blank? - @max_time ||= (Time.now + 1) - end +class TagStream < BaseStream def link(opts={}) Rails.application.routes.url_helpers.tag_followings_path(opts) end def title - @tag_string.titleize.split(',').to_sentence + tags_titleized end # @return [ActiveRecord::Association] AR association of posts def posts - @posts ||= StatusMessage.tagged_with([@tag_string], :any => true).for_a_stream(@max_time, @order) + if tag_string.empty? + [] + else + @posts ||= StatusMessage.tagged_with([@tag_string], :any => true).where(:public => true).for_a_stream(@max_time, @order) + end end # @return [ActiveRecord::Association] AR association of people within stream's given aspects @@ -44,31 +26,21 @@ class TagStream @people ||= posts.map{|p| p.author}.uniq end - def for_all_aspects? - false - end - - def ajax_posts? - false - end - - def aspects - [] - end - - def aspect - nil - end - def contacts_title - "People who like #{@tag_string}" + I18n.translate('streams.tags.contacts_title') end - - def contacts_link - '#' + + private + + def tag_string + @tag_string ||= tags.join(', '){|tag| tag.name}.to_s end - - def aspect_ids - [] + + def tags + @tags = user.followed_tags + end + + def tags_titleized + tag_string.split(',').map{|x| "##{x.strip}"}.to_sentence end end