no authentication, n-query in stream

This commit is contained in:
Raphael Sofaer 2011-02-08 15:48:58 -08:00
parent 0000185875
commit f8cec95d7a
3 changed files with 12 additions and 4 deletions

View file

@ -39,10 +39,11 @@ class StatusMessage < Post
regex = /@\{([^;]+); ([^\}]+)\}/
escaped_message = ERB::Util.h(raw_message)
form_message = escaped_message.gsub(regex) do |matched_string|
inner_captures = matched_string.match(regex).captures
person = people.detect{ |p|
p.diaspora_handle == matched_string.match(regex).captures.last
p.diaspora_handle == inner_captures.last
}
"<a href=\"/people/#{person.id}\">#{ERB::Util.h(person.name)}</a>"
person ? "<a href=\"/people/#{person.id}\">#{ERB::Util.h(person.name)}</a>" : inner_captures.first
end
form_message
end
@ -52,7 +53,7 @@ class StatusMessage < Post
identifiers = self.raw_message.scan(regex).map do |match|
match.last
end
self.person.owner.contact_people.where(:diaspora_handle => identifiers)
Person.where(:diaspora_handle => identifiers)
end
def to_activity

View file

@ -35,7 +35,7 @@ class User < ActiveRecord::Base
has_many :aspects, :dependent => :destroy
has_many :aspect_memberships, :through => :aspects
has_many :contacts
has_many :contact_people, :through => :contacts
has_many :contact_people, :through => :contacts, :source => :person
has_many :services
before_destroy :disconnect_everyone, :remove_person

View file

@ -75,6 +75,13 @@ STR
@sm.formatted_message.should == <<-STR
#{link_to(@people[0].name, person_path(@people[0]))} can mention people like Raphael #{link_to(@people[1].name, person_path(@people[1]))}
can mention people like Raphaellike Raphael #{link_to(@people[2].name, person_path(@people[2]))} can mention people like Raph
STR
end
it 'leaves the name of people that cannot be found' do
@sm.stub(:mentioned_people).and_return([])
@sm.formatted_message.should == <<-STR
Raphael can mention people like Raphael Ilya
can mention people like Raphaellike Raphael Daniel can mention people like Raph
STR
end
it 'escapes the link title' do