Skip to content
Extraits de code Groupes Projets
Valider d0ce2571 rédigé par Raphael Sofaer's avatar Raphael Sofaer
Parcourir les fichiers

Revert "Revert "Merge branch 'hashtags-in-comments'""

This reverts commit d2e26f69.
parent d2e26f69
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -56,11 +56,18 @@ class TagsController < ApplicationController ...@@ -56,11 +56,18 @@ class TagsController < ApplicationController
@posts = StatusMessage.where(:public => true, :pending => false) @posts = StatusMessage.where(:public => true, :pending => false)
end end
@posts = @posts.tagged_with(params[:name]) @tag = ActsAsTaggableOn::Tag.where(:name => params[:name]).first
if @tag
@posts = @posts.joins("LEFT OUTER JOIN comments ON comments.post_id = posts.id").
joins("INNER JOIN taggings ON (taggings.tag_id = #{@tag.id} AND
((taggable_id = posts.id AND taggable_type = 'Post') OR (taggings.taggable_type = 'Comment' AND taggings.taggable_id = comments.id)))")
max_time = params[:max_time] ? Time.at(params[:max_time].to_i) : Time.now max_time = params[:max_time] ? Time.at(params[:max_time].to_i) : Time.now
@posts = @posts.where(StatusMessage.arel_table[:created_at].lt(max_time)) @posts = @posts.where(StatusMessage.arel_table[:created_at].lt(max_time))
@posts = @posts.includes({:comments => {:author => :profile}}, :photos).order('posts.created_at DESC').limit(15) @posts = @posts.includes({:comments => {:author => :profile}}, :photos).order('posts.created_at DESC').limit(15)
else
@posts = []
end
@posts = PostsFake.new(@posts) @posts = PostsFake.new(@posts)
@commenting_disabled = true @commenting_disabled = true
......
...@@ -13,6 +13,11 @@ class Comment < ActiveRecord::Base ...@@ -13,6 +13,11 @@ class Comment < ActiveRecord::Base
include Diaspora::Relayable include Diaspora::Relayable
include Diaspora::Socketable include Diaspora::Socketable
include Diaspora::Taggable
acts_as_taggable_on :tags
extract_tags_from :text
before_create :build_tags
xml_attr :text xml_attr :text
xml_attr :diaspora_handle xml_attr :diaspora_handle
......
...@@ -43,7 +43,7 @@ class StatusMessage < Post ...@@ -43,7 +43,7 @@ class StatusMessage < Post
escaped_message = opts[:plain_text] ? self.raw_message: ERB::Util.h(self.raw_message) escaped_message = opts[:plain_text] ? self.raw_message: ERB::Util.h(self.raw_message)
mentioned_message = self.format_mentions(escaped_message, opts) mentioned_message = self.format_mentions(escaped_message, opts)
self.format_tags(mentioned_message, opts) Diaspora::Taggable.format_tags(mentioned_message, opts)
end end
def format_mentions(text, opts = {}) def format_mentions(text, opts = {})
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
= person_link(comment.author, :class => "hovercardable") = person_link(comment.author, :class => "hovercardable")
%span{:class => direction_for(comment.text)} %span{:class => direction_for(comment.text)}
= markdownify(comment.text, :youtube_maps => comment.youtube_titles) = markdownify(Diaspora::Taggable.format_tags(comment.text), :youtube_maps => comment.youtube_titles)
%br %br
%time.timeago{:datetime => comment.created_at} %time.timeago{:datetime => comment.created_at}
......
...@@ -15,5 +15,5 @@ ...@@ -15,5 +15,5 @@
=person_link(person) =person_link(person)
.info .info
= person.profile.format_tags(person.profile.tag_string) = Diaspora::Taggable.format_tags(person.profile.tag_string)
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
= @person.diaspora_handle = @person.diaspora_handle
.description .description
- if !@person.profile.tag_string.blank? - if !@person.profile.tag_string.blank?
= @person.profile.format_tags(@person.profile.tag_string) = Diapsora::Taggable.format_tags(@person.profile.tag_string)
- if user_signed_in? && @person == current_user.person - if user_signed_in? && @person == current_user.person
%span.hover_edit %span.hover_edit
= link_to t('people.show.edit'), edit_profile_path = link_to t('people.show.edit'), edit_profile_path
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
.description .description
- if !@person.profile.tag_string.blank? && user_signed_in? && (@contact.persisted? || @person == current_user.person || @incoming_request) - if !@person.profile.tag_string.blank? && user_signed_in? && (@contact.persisted? || @person == current_user.person || @incoming_request)
= @person.profile.format_tags(@person.profile.tag_string) = Diaspora::Taggable.format_tags(@person.profile.tag_string)
- if user_signed_in? && @person == current_user.person - if user_signed_in? && @person == current_user.person
%span.hover_edit %span.hover_edit
= link_to t('.edit'), edit_profile_path = link_to t('.edit'), edit_profile_path
......
...@@ -36,7 +36,7 @@ module Diaspora ...@@ -36,7 +36,7 @@ module Diaspora
unique_matches.values unique_matches.values
end end
def format_tags(text, opts={}) def self.format_tags(text, opts={})
return text if opts[:plain_text] return text if opts[:plain_text]
regex = /(^|\s)#(#{VALID_TAG_BODY})/ regex = /(^|\s)#(#{VALID_TAG_BODY})/
form_message = text.gsub(regex) do |matched_string| form_message = text.gsub(regex) do |matched_string|
......
...@@ -69,6 +69,20 @@ describe TagsController do ...@@ -69,6 +69,20 @@ describe TagsController do
get :show, :name => 'hello' get :show, :name => 'hello'
assigns(:posts).models.should == [stranger_post] assigns(:posts).models.should == [stranger_post]
end end
it 'displays a post with a comment containing the tag search' do
bob.post(:status_message, :text => "other post y'all", :to => 'all')
other_post = bob.post(:status_message, :text => "sup y'all", :to => 'all')
Factory(:comment, :text => "#hello", :post => other_post)
get :show, :name => 'hello'
assigns(:posts).models.should == [other_post]
response.status.should == 200
end
it 'succeeds without posts' do
get :show, :name => 'hellyes'
response.status.should == 200
end
end end
context "not signed in" do context "not signed in" do
......
...@@ -126,4 +126,11 @@ describe Comment do ...@@ -126,4 +126,11 @@ describe Comment do
it_should_behave_like 'it is relayable' it_should_behave_like 'it is relayable'
end end
describe 'tags' do
before do
@object = Factory.build(:comment)
end
it_should_behave_like 'it is taggable'
end
end end
...@@ -12,7 +12,7 @@ describe Diaspora::Taggable do ...@@ -12,7 +12,7 @@ describe Diaspora::Taggable do
def controller def controller
end end
describe '#format_tags' do describe '.format_tags' do
before do before do
@str = '#what #hey #vöglein' @str = '#what #hey #vöglein'
@object.send(@object.class.field_with_tags_setter, @str) @object.send(@object.class.field_with_tags_setter, @str)
...@@ -21,10 +21,10 @@ describe Diaspora::Taggable do ...@@ -21,10 +21,10 @@ describe Diaspora::Taggable do
end end
it 'links the tag to /p' do it 'links the tag to /p' do
link = link_to('#vöglein', '/tags/vöglein', :class => 'tag') link = link_to('#vöglein', '/tags/vöglein', :class => 'tag')
@object.format_tags(@str).should include(link) Diaspora::Taggable.format_tags(@str).should include(link)
end end
it 'responds to plain_text' do it 'responds to plain_text' do
@object.format_tags(@str, :plain_text => true).should == @str Diaspora::Taggable.format_tags(@str, :plain_text => true).should == @str
end end
end end
describe '#build_tags' do describe '#build_tags' do
......
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