diff --git a/app/controllers/mentions_controller.rb b/app/controllers/mentions_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..ac4d7efd0622d0f8c2c9e4a8e39ab41ffc6e0368 --- /dev/null +++ b/app/controllers/mentions_controller.rb @@ -0,0 +1,14 @@ +require File.join(Rails.root, '/lib/mention_stream') +class MentionsController < ApplicationController + before_filter :authenticate_user! + + def index + @stream = MentionStream.new(current_user, :max_time => params[:max_time]) + + if params[:only_posts] + render :partial => 'shared/stream', :locals => {:posts => @stream.posts} + else + render 'aspects/index' + end + end +end diff --git a/app/controllers/tag_followings_controller.rb b/app/controllers/tag_followings_controller.rb index 327c7c54159477a3686605b6be88a5b899d31148..2fb93398af4e1dc675334733e6cbd772be97f22e 100644 --- a/app/controllers/tag_followings_controller.rb +++ b/app/controllers/tag_followings_controller.rb @@ -3,10 +3,15 @@ class TagFollowingsController < ApplicationController before_filter :authenticate_user! def index - @stream = TagStream.new(current_user) + @stream = TagStream.new(current_user, :max_time => params[:max_time]) - render 'aspects/index', :locals => {:posts => @stream.posts} + if params[:only_posts] + render :partial => 'shared/stream', :locals => {:posts => @stream.posts} + else + render 'aspects/index' + end end + # POST /tag_followings # POST /tag_followings.xml def create diff --git a/app/helpers/stream_helper.rb b/app/helpers/stream_helper.rb index abc2af7168f81981921629f5e4fa445a08bc7863..1d259cf1a83b8cb005f4fe9b04ee7853d6c84be9 100644 --- a/app/helpers/stream_helper.rb +++ b/app/helpers/stream_helper.rb @@ -12,6 +12,8 @@ module StreamHelper person_path(@person, :max_time => @posts.last.created_at.to_i) elsif controller.instance_of?(TagFollowingsController) tag_followings_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream)) + elsif controller.instance_of?(MentionsController) + mentions_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream)) elsif controller.instance_of?(AspectsController) aspects_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :a_ids => @stream.aspect_ids) else diff --git a/app/models/post.rb b/app/models/post.rb index 4743ff48ed02ad72334bbbac4adb9db7ced929cc..09b3380ef47755933ff295271eea4898b8df8baa 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -34,6 +34,10 @@ 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) + end + def diaspora_handle read_attribute(:diaspora_handle) || self.author.diaspora_handle end diff --git a/app/views/aspects/_aspect_stream.haml b/app/views/aspects/_aspect_stream.haml index 5ac7a9a4f49f0cba53201fbb5636ad0ec1df3368..04a0c48976787ddb1c94018399c094b92ac60d2e 100644 --- a/app/views/aspects/_aspect_stream.haml +++ b/app/views/aspects/_aspect_stream.haml @@ -20,7 +20,11 @@ = render 'aspects/no_contacts_message' #main_stream.stream{:data => {:guids => stream.aspect_ids.join(',')}} +<<<<<<< HEAD - if stream.ajax_stream? +======= + - if stream.ajax_posts? +>>>>>>> added tag follow feature, mention page feature. is now pretty easy to add new types of streams, but some more refactoring could make it even nicer #pagination =link_to(t('more'), next_page_path(:ajax_stream => true), :class => 'paginate') diff --git a/app/views/aspects/_selected_contacts.html.haml b/app/views/aspects/_selected_contacts.html.haml index 7b07186055b9d55884bd4c1e1a21ec8364638fc3..04291e3a2fb3c3fae796412bfdf3bb7a9baf14b7 100644 --- a/app/views/aspects/_selected_contacts.html.haml +++ b/app/views/aspects/_selected_contacts.html.haml @@ -7,12 +7,7 @@ - if @stream.people.size > 0 - for person in @stream.people.sample(15) = person_image_link(person) - - - if @stream.for_all_aspects? || @stream.aspect_ids.size > 1 - = link_to t('.view_all_contacts'), contacts_link, :id => "view_all_contacts_link" - - else - = link_to t('.view_all_contacts'), contacts_path(:a_id => @stream.aspect.id), :id => "view_all_contacts_link" - + = link_to t('.view_all_contacts'), @stream.contacts_link, :id => "view_all_contacts_link" - else = t('.no_contacts') = link_to t('.manage_your_aspects'), contacts_link diff --git a/app/views/aspects/index.html.haml b/app/views/aspects/index.html.haml index d2b59a43f57e43bcb214c7a0e782181b375fa09b..59611a003a13101ec73d4ae20ceff32d0f3f5bb1 100644 --- a/app/views/aspects/index.html.haml +++ b/app/views/aspects/index.html.haml @@ -21,6 +21,9 @@ .section = render 'aspects/aspect_listings' + .section + = link_to "Mentions", mentions_path + .section#followed_tags_listing = render 'tags/followed_tags_listings' diff --git a/config/routes.rb b/config/routes.rb index 80c19d1667f8e749ebd751cf204658959932d6a4..ed13387288e7b06213a58c0d24db6abed5c87277 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -54,6 +54,7 @@ Diaspora::Application.routes.draw do get "tag_followings" => "tag_followings#index", :as => 'tag_followings' + resources :mentions, :only => [:index] get 'tags/:name' => 'tags#show', :as => 'tag' diff --git a/lib/aspect_stream.rb b/lib/aspect_stream.rb index b71cd82d2db7e2633b046d6eee21d3d0c38c6a69..06ee3993c27248578c64de40b797fd0740839f66 100644 --- a/lib/aspect_stream.rb +++ b/lib/aspect_stream.rb @@ -94,4 +94,12 @@ class AspectStream "#{self.aspect.name}(#{self.people.size})" end end + + def contacts_link + if for_all_aspects? || aspect_ids.size > 1 + Rails.application.routes.url_helpers.contacts_path + else + Rails.application.routes.url_helpers.contacts_path(:a_id => @stream.aspect.id) + end + end end diff --git a/lib/mention_stream.rb b/lib/mention_stream.rb new file mode 100644 index 0000000000000000000000000000000000000000..5957a1ad618b8da3fbe10995d970b90ad118045b --- /dev/null +++ b/lib/mention_stream.rb @@ -0,0 +1,72 @@ +# 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 MentionStream + + 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={}) + @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" + end + + # @return [ActiveRecord::Association<Post>] AR association of posts + def posts + @posts ||= Post.joins(:mentions).where(:mentions => {:person_id => @user.person.id}).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 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 + [] + end +end diff --git a/lib/tag_stream.rb b/lib/tag_stream.rb index 2c421b2a9a2d6254a3733328d13dbdd50b6cf579..375c82043dbefe61b9f560841014ab088f31499f 100644 --- a/lib/tag_stream.rb +++ b/lib/tag_stream.rb @@ -14,10 +14,16 @@ class TagStream # @return [void] def initialize(user, opts={}) @tags = user.followed_tags - @tag_string = @tags.join(', '){|tag| tag.name} + @tag_string = @tags.join(', '){|tag| tag.name}.to_s @user = user - @max_time = opts[:max_time] - @order = opts[:order] + 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={}) @@ -25,14 +31,12 @@ class TagStream end def title - "Tag Stream" + @tag_string.titleize.split(',').to_sentence end # @return [ActiveRecord::Association<Post>] AR association of posts def posts - @posts ||= StatusMessage.tagged_with([@tag_string], :any => true) - - + @posts ||= StatusMessage.tagged_with([@tag_string], :any => true).for_a_stream(@max_time, @order) end # @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects @@ -44,6 +48,10 @@ class TagStream false end + def ajax_posts? + false + end + def aspects [] end @@ -56,8 +64,11 @@ class TagStream "People who like #{@tag_string}" end + def contacts_link + '#' + end + def aspect_ids [] end - end diff --git a/public/javascripts/pages/mentions-index.js b/public/javascripts/pages/mentions-index.js new file mode 100644 index 0000000000000000000000000000000000000000..41fb16713c3d299ed938115264b6352028a2af25 --- /dev/null +++ b/public/javascripts/pages/mentions-index.js @@ -0,0 +1,8 @@ +Diaspora.Pages.MentionsIndex = function() { + var self = this; + + this.subscribe("page/ready", function(evt, document) { + self.stream = self.instantiate("Stream", document.find("#aspect_stream_container")); + self.infiniteScroll = self.instantiate("InfiniteScroll"); + }); +}; diff --git a/public/javascripts/pages/tag-followings-index.js b/public/javascripts/pages/tag-followings-index.js new file mode 100644 index 0000000000000000000000000000000000000000..0dad173df5eafd2f4db7462e06005fedcc4b2bf6 --- /dev/null +++ b/public/javascripts/pages/tag-followings-index.js @@ -0,0 +1,8 @@ +Diaspora.Pages.TagFollowingsIndex = function() { + var self = this; + + this.subscribe("page/ready", function(evt, document) { + self.stream = self.instantiate("Stream", document.find("#aspect_stream_container")); + self.infiniteScroll = self.instantiate("InfiniteScroll"); + }); +};