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
This commit is contained in:
parent
b5c3f2c615
commit
429ac42502
13 changed files with 151 additions and 16 deletions
14
app/controllers/mentions_controller.rb
Normal file
14
app/controllers/mentions_controller.rb
Normal file
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@
|
|||
.section
|
||||
= render 'aspects/aspect_listings'
|
||||
|
||||
.section
|
||||
= link_to "Mentions", mentions_path
|
||||
|
||||
.section#followed_tags_listing
|
||||
= render 'tags/followed_tags_listings'
|
||||
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
72
lib/mention_stream.rb
Normal file
72
lib/mention_stream.rb
Normal file
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
8
public/javascripts/pages/mentions-index.js
Normal file
8
public/javascripts/pages/mentions-index.js
Normal file
|
|
@ -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");
|
||||
});
|
||||
};
|
||||
8
public/javascripts/pages/tag-followings-index.js
Normal file
8
public/javascripts/pages/tag-followings-index.js
Normal file
|
|
@ -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");
|
||||
});
|
||||
};
|
||||
Loading…
Reference in a new issue