Skip to content
Extraits de code Groupes Projets
Valider ad9dcd85 rédigé par Maxwell Salzberg's avatar Maxwell Salzberg
Parcourir les fichiers

holy guacamole. mentions page and tag following pages, plus a huge stream refactor

parent 412fe1b0
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de avec 141 ajouts et 120 suppressions
...@@ -137,4 +137,17 @@ class ApplicationController < ActionController::Base ...@@ -137,4 +137,17 @@ class ApplicationController < ActionController::Base
@tags ||= current_user.followed_tags @tags ||= current_user.followed_tags
end 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 end
...@@ -138,18 +138,4 @@ class AspectsController < ApplicationController ...@@ -138,18 +138,4 @@ class AspectsController < ApplicationController
end end
private 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 end
require File.join(Rails.root, '/lib/mention_stream') require File.join(Rails.root, '/lib/mention_stream')
class MentionsController < ApplicationController class MentionsController < ApplicationController
before_filter :authenticate_user! 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]) @stream = MentionStream.new(current_user, :max_time => params[:max_time], :order => sort_order)
if params[:only_posts] if params[:only_posts]
render :partial => 'shared/stream', :locals => {:posts => @stream.posts} render :partial => 'shared/stream', :locals => {:posts => @stream.posts}
......
require File.join(Rails.root, '/lib/tag_stream') require File.join(Rails.root, '/lib/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]) @stream = TagStream.new(current_user, :max_time => params[:max_time], :order => sort_order)
if params[:only_posts] if params[:only_posts]
render :partial => 'shared/stream', :locals => {:posts => @stream.posts} render :partial => 'shared/stream', :locals => {:posts => @stream.posts}
......
...@@ -22,7 +22,7 @@ module StreamHelper ...@@ -22,7 +22,7 @@ module StreamHelper
end end
def time_for_scroll(ajax_stream, stream) def time_for_scroll(ajax_stream, stream)
if ajax_stream if ajax_stream || stream.posts.empty?
(Time.now() + 1).to_i (Time.now() + 1).to_i
else else
stream.posts.last.send(stream.order.to_sym).to_i stream.posts.last.send(stream.order.to_sym).to_i
......
...@@ -35,7 +35,9 @@ class Post < ActiveRecord::Base ...@@ -35,7 +35,9 @@ class Post < ActiveRecord::Base
scope :all_public, where(:public => true, :pending => false) scope :all_public, where(:public => true, :pending => false)
def self.for_a_stream(max_time, order) 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 end
def diaspora_handle def diaspora_handle
......
...@@ -26,6 +26,8 @@ class StatusMessage < Post ...@@ -26,6 +26,8 @@ class StatusMessage < Post
after_create :create_mentions after_create :create_mentions
scope :where_person_is_mentioned, lambda{|person| joins(:mentions).where(:mentions => {:person_id => person.id})}
def text(opts = {}) def text(opts = {})
self.formatted_message(opts) self.formatted_message(opts)
end end
......
...@@ -20,8 +20,7 @@ ...@@ -20,8 +20,7 @@
= render 'aspects/no_contacts_message' = render 'aspects/no_contacts_message'
#main_stream.stream{:data => {:guids => stream.aspect_ids.join(',')}} #main_stream.stream{:data => {:guids => stream.aspect_ids.join(',')}}
- if stream.ajax_stream? - if !stream.ajax_stream? && stream.posts.length > 0
- elsif stream.posts.length > 0
= render 'shared/stream', :posts => stream.posts = render 'shared/stream', :posts => stream.posts
#pagination #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')
...@@ -22,7 +22,9 @@ ...@@ -22,7 +22,9 @@
= render 'aspects/aspect_listings' = render 'aspects/aspect_listings'
.section .section
= link_to "Mentions", mentions_path %ul.left_nav
.li
%b= link_to t('.mentions'), mentions_path, :class => 'home_selector'
.section#followed_tags_listing .section#followed_tags_listing
= render 'tags/followed_tags_listings' = render 'tags/followed_tags_listings'
......
...@@ -5,8 +5,7 @@ ...@@ -5,8 +5,7 @@
- if user_signed_in? - if user_signed_in?
%ul.left_nav %ul.left_nav
%li %li
%div.root_element %b=link_to t('aspects.index.tags_following'), tag_followings_path, :class => 'home_selector'
=link_to t('aspects.index.tags_following'), tag_followings_path
%ul.sub_nav %ul.sub_nav
- if tags.size > 0 - if tags.size > 0
......
...@@ -106,6 +106,7 @@ en: ...@@ -106,6 +106,7 @@ en:
done_editing: "done editing" done_editing: "done editing"
aspect_stream: aspect_stream:
stream: "Stream" stream: "Stream"
mentions: "Mentions"
recently: "recently:" recently: "recently:"
commented_on: "commented on" commented_on: "commented on"
posted: "posted" posted: "posted"
...@@ -155,6 +156,7 @@ en: ...@@ -155,6 +156,7 @@ en:
acquaintances: "Acquaintances" acquaintances: "Acquaintances"
friends: "Friends" friends: "Friends"
index: index:
mentions: "Mentions"
donate: "Donate" donate: "Donate"
keep_us_running: "Keep %{pod} running fast and buy servers their coffee fix with a monthly donation!" keep_us_running: "Keep %{pod} running fast and buy servers their coffee fix with a monthly donation!"
your_aspects: "Your Aspects" your_aspects: "Your Aspects"
...@@ -824,7 +826,15 @@ en: ...@@ -824,7 +826,15 @@ en:
index: index:
revoke_access: "Revoke Access" revoke_access: "Revoke Access"
no_applications: "You haven't registered any applications yet." 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: users:
logged_out: logged_out:
......
...@@ -2,9 +2,8 @@ ...@@ -2,9 +2,8 @@
# 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.
class AspectStream class AspectStream < BaseStream
TYPES_OF_POST_IN_STREAM = ['StatusMessage', 'Reshare', 'ActivityStreams::Photo']
attr_reader :max_time, :order
# @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
...@@ -13,10 +12,8 @@ class AspectStream ...@@ -13,10 +12,8 @@ class AspectStream
# @opt order [String] Order of posts (i.e. 'created_at', 'updated_at') # @opt order [String] Order of posts (i.e. 'created_at', 'updated_at')
# @return [void] # @return [void]
def initialize(user, inputted_aspect_ids, opts={}) def initialize(user, inputted_aspect_ids, opts={})
@user = user super(user, opts)
@inputted_aspect_ids = inputted_aspect_ids @inputted_aspect_ids = inputted_aspect_ids
@max_time = opts[:max_time]
@order = opts[:order]
end end
# Filters aspects given the stream's aspect ids on initialization and the user. # Filters aspects given the stream's aspect ids on initialization and the user.
...@@ -43,10 +40,10 @@ class AspectStream ...@@ -43,10 +40,10 @@ class AspectStream
def posts def posts
# NOTE(this should be something like Post.all_for_stream(@user, aspect_ids, {}) that calls visible_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, @posts ||= @user.visible_posts(:by_members_of => aspect_ids,
:type => ['StatusMessage', 'Reshare', 'ActivityStreams::Photo'], :type => TYPES_OF_POST_IN_STREAM,
:order => "#{@order} DESC", :order => "#{@order} DESC",
:max_time => @max_time :max_time => @max_time
).includes(:mentions => {:person => :profile}, :author => :profile) ).for_a_stream(max_time, order)
end end
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects # @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
...@@ -73,7 +70,7 @@ class AspectStream ...@@ -73,7 +70,7 @@ class AspectStream
def title def title
if self.for_all_aspects? if self.for_all_aspects?
I18n.t('.stream') I18n.t('aspects.aspect_stream.stream')
else else
self.aspects.to_sentence self.aspects.to_sentence
end end
......
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
...@@ -2,9 +2,8 @@ ...@@ -2,9 +2,8 @@
# 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.
class MentionStream class MentionStream< BaseStream
attr_reader :max_time, :order
# @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
...@@ -12,29 +11,19 @@ class MentionStream ...@@ -12,29 +11,19 @@ class MentionStream
# @opt max_time [Integer] Unix timestamp of stream's post ceiling # @opt max_time [Integer] Unix timestamp of stream's post ceiling
# @opt order [String] Order of posts (i.e. 'created_at', 'updated_at') # @opt order [String] Order of posts (i.e. 'created_at', 'updated_at')
# @return [void] # @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={}) def link(opts={})
Rails.application.routes.url_helpers.mentions_path(opts) Rails.application.routes.url_helpers.mentions_path(opts)
end end
def title def title
"Your Mentions" I18n.translate("streams.mentions.title")
end end
# @return [ActiveRecord::Association<Post>] AR association of posts # @return [ActiveRecord::Association<Post>] AR association of posts
def 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 end
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects # @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
...@@ -42,31 +31,7 @@ class MentionStream ...@@ -42,31 +31,7 @@ class MentionStream
@people ||= posts.map{|p| p.author}.uniq @people ||= posts.map{|p| p.author}.uniq
end end
def for_all_aspects?
false
end
def ajax_posts?
false
end
def aspects
[]
end
def aspect
nil
end
def contacts_title def contacts_title
"People who mentioned you" I18n.translate('streams.mentions.contacts_title')
end
def contacts_link
'#'
end
def aspect_ids
[]
end end
end end
...@@ -2,41 +2,23 @@ ...@@ -2,41 +2,23 @@
# 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.
class TagStream class TagStream < BaseStream
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_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
def link(opts={}) def link(opts={})
Rails.application.routes.url_helpers.tag_followings_path(opts) Rails.application.routes.url_helpers.tag_followings_path(opts)
end end
def title def title
@tag_string.titleize.split(',').to_sentence tags_titleized
end end
# @return [ActiveRecord::Association<Post>] AR association of posts # @return [ActiveRecord::Association<Post>] AR association of posts
def 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 end
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects # @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
...@@ -44,31 +26,21 @@ class TagStream ...@@ -44,31 +26,21 @@ class TagStream
@people ||= posts.map{|p| p.author}.uniq @people ||= posts.map{|p| p.author}.uniq
end end
def for_all_aspects? def contacts_title
false I18n.translate('streams.tags.contacts_title')
end
def ajax_posts?
false
end
def aspects
[]
end end
def aspect private
nil
end
def contacts_title def tag_string
"People who like #{@tag_string}" @tag_string ||= tags.join(', '){|tag| tag.name}.to_s
end end
def contacts_link def tags
'#' @tags = user.followed_tags
end end
def aspect_ids def tags_titleized
[] tag_string.split(',').map{|x| "##{x.strip}"}.to_sentence
end end
end end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter