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
@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
......@@ -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
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}
......
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}
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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')
......@@ -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'
......
......@@ -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
......
......@@ -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:
......
......@@ -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<Integer>] 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<Person>] 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
......
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 @@
# 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<Integer>] 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<Post>] 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<Person>] 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
......@@ -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<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
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<Post>] 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<Person>] 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
[]
def contacts_title
I18n.translate('streams.tags.contacts_title')
end
def aspect
nil
end
private
def contacts_title
"People who like #{@tag_string}"
def tag_string
@tag_string ||= tags.join(', '){|tag| tag.name}.to_s
end
def contacts_link
'#'
def tags
@tags = user.followed_tags
end
def aspect_ids
[]
def tags_titleized
tag_string.split(',').map{|x| "##{x.strip}"}.to_sentence
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