Merge branch 'hashtags-in-comments'
This commit is contained in:
commit
f85d5ad6d4
11 changed files with 46 additions and 13 deletions
|
|
@ -56,11 +56,18 @@ class TagsController < ApplicationController
|
|||
@posts = StatusMessage.where(:public => true, :pending => false)
|
||||
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
|
||||
@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)
|
||||
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.includes({:comments => {:author => :profile}}, :photos).order('posts.created_at DESC').limit(15)
|
||||
else
|
||||
@posts = []
|
||||
end
|
||||
|
||||
@posts = PostsFake.new(@posts)
|
||||
@commenting_disabled = true
|
||||
|
|
|
|||
|
|
@ -13,6 +13,11 @@ class Comment < ActiveRecord::Base
|
|||
include Diaspora::Relayable
|
||||
|
||||
include Diaspora::Socketable
|
||||
include Diaspora::Taggable
|
||||
|
||||
acts_as_taggable_on :tags
|
||||
extract_tags_from :text
|
||||
before_create :build_tags
|
||||
|
||||
xml_attr :text
|
||||
xml_attr :diaspora_handle
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class StatusMessage < Post
|
|||
|
||||
escaped_message = opts[:plain_text] ? self.raw_message: ERB::Util.h(self.raw_message)
|
||||
mentioned_message = self.format_mentions(escaped_message, opts)
|
||||
self.format_tags(mentioned_message, opts)
|
||||
Diaspora::Taggable.format_tags(mentioned_message, opts)
|
||||
end
|
||||
|
||||
def format_mentions(text, opts = {})
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
= person_link(comment.author, :class => "hovercardable")
|
||||
|
||||
%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
|
||||
%time.timeago{:datetime => comment.created_at}
|
||||
|
|
|
|||
|
|
@ -15,5 +15,5 @@
|
|||
=person_link(person)
|
||||
|
||||
.info
|
||||
= person.profile.format_tags(person.profile.tag_string)
|
||||
= Diaspora::Taggable.format_tags(person.profile.tag_string)
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@
|
|||
= @person.diaspora_handle
|
||||
.description
|
||||
- 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
|
||||
%span.hover_edit
|
||||
= link_to t('people.show.edit'), edit_profile_path
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
|
||||
.description
|
||||
- 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
|
||||
%span.hover_edit
|
||||
= link_to t('.edit'), edit_profile_path
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ module Diaspora
|
|||
unique_matches.values
|
||||
end
|
||||
|
||||
def format_tags(text, opts={})
|
||||
def self.format_tags(text, opts={})
|
||||
return text if opts[:plain_text]
|
||||
regex = /(^|\s)#(#{VALID_TAG_BODY})/
|
||||
form_message = text.gsub(regex) do |matched_string|
|
||||
|
|
|
|||
|
|
@ -69,6 +69,20 @@ describe TagsController do
|
|||
get :show, :name => 'hello'
|
||||
assigns(:posts).models.should == [stranger_post]
|
||||
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
|
||||
|
||||
context "not signed in" do
|
||||
|
|
|
|||
|
|
@ -126,4 +126,11 @@ describe Comment do
|
|||
it_should_behave_like 'it is relayable'
|
||||
end
|
||||
|
||||
describe 'tags' do
|
||||
before do
|
||||
@object = Factory.build(:comment)
|
||||
end
|
||||
it_should_behave_like 'it is taggable'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ describe Diaspora::Taggable do
|
|||
def controller
|
||||
end
|
||||
|
||||
describe '#format_tags' do
|
||||
describe '.format_tags' do
|
||||
before do
|
||||
@str = '#what #hey #vöglein'
|
||||
@object.send(@object.class.field_with_tags_setter, @str)
|
||||
|
|
@ -21,10 +21,10 @@ describe Diaspora::Taggable do
|
|||
end
|
||||
it 'links the tag to /p' do
|
||||
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
|
||||
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
|
||||
describe '#build_tags' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue