Merge pull request #6992 from SuperTux88/4491-fetch-mentioned-people
fetch mentioned people if they don't exist locally yet
This commit is contained in:
commit
fedd378dcf
4 changed files with 32 additions and 7 deletions
|
|
@ -199,6 +199,7 @@ The command will report queues that still have jobs and launch sidekiq process f
|
||||||
* Display message when there are no posts in a stream [#6974](https://github.com/diaspora/diaspora/pull/6974)
|
* Display message when there are no posts in a stream [#6974](https://github.com/diaspora/diaspora/pull/6974)
|
||||||
* Add bootstrap-markdown editor to the publisher [#6551](https://github.com/diaspora/diaspora/pull/6551)
|
* Add bootstrap-markdown editor to the publisher [#6551](https://github.com/diaspora/diaspora/pull/6551)
|
||||||
* Don't create notifications for ignored users [#6984](https://github.com/diaspora/diaspora/pull/6984)
|
* Don't create notifications for ignored users [#6984](https://github.com/diaspora/diaspora/pull/6984)
|
||||||
|
* Fetch missing persons when receiving a mention for them [#6992](https://github.com/diaspora/diaspora/pull/6992)
|
||||||
|
|
||||||
# 0.5.10.2
|
# 0.5.10.2
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,12 +46,11 @@ module Diaspora::Mentionable
|
||||||
# @return [Array<Person>] array of people
|
# @return [Array<Person>] array of people
|
||||||
def self.people_from_string(msg_text)
|
def self.people_from_string(msg_text)
|
||||||
identifiers = msg_text.to_s.scan(REGEX).map do |match_str|
|
identifiers = msg_text.to_s.scan(REGEX).map do |match_str|
|
||||||
_, handle = mention_attrs(match_str.first)
|
_, identifier = mention_attrs(match_str.first)
|
||||||
handle
|
identifier if Validation::Rule::DiasporaId.new.valid_value?(identifier)
|
||||||
end
|
end
|
||||||
|
|
||||||
return [] if identifiers.empty?
|
identifiers.compact.uniq.map {|identifier| find_or_fetch_person_by_identifier(identifier) }.compact
|
||||||
Person.where(diaspora_handle: identifiers)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# takes a message text and converts mentions for people that are not in the
|
# takes a message text and converts mentions for people that are not in the
|
||||||
|
|
@ -81,6 +80,12 @@ module Diaspora::Mentionable
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
private_class_method def self.find_or_fetch_person_by_identifier(identifier)
|
||||||
|
Person.find_or_fetch_by_identifier(identifier)
|
||||||
|
rescue DiasporaFederation::Discovery::DiscoveryError
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
# inline module for namespacing
|
# inline module for namespacing
|
||||||
module MentionsInternal
|
module MentionsInternal
|
||||||
extend ::PeopleHelper
|
extend ::PeopleHelper
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ STR
|
||||||
describe "#people_from_string" do
|
describe "#people_from_string" do
|
||||||
it "extracts the mentioned people from the text" do
|
it "extracts the mentioned people from the text" do
|
||||||
ppl = Diaspora::Mentionable.people_from_string(@test_txt)
|
ppl = Diaspora::Mentionable.people_from_string(@test_txt)
|
||||||
expect(ppl).to include(*@people)
|
expect(ppl).to match_array(@people)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "returns an empty array if nobody was found" do
|
describe "returns an empty array if nobody was found" do
|
||||||
|
|
@ -80,7 +80,26 @@ STR
|
||||||
end
|
end
|
||||||
|
|
||||||
it "gets a post with invalid handles" do
|
it "gets a post with invalid handles" do
|
||||||
ppl = Diaspora::Mentionable.people_from_string("@{a; xxx@xxx.xx} @{b; yyy@yyyy.yyy} @{...} @{bla; blubb}")
|
ppl = Diaspora::Mentionable.people_from_string("@{...} @{bla; blubb}")
|
||||||
|
expect(ppl).to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it "filters duplicate handles" do
|
||||||
|
ppl = Diaspora::Mentionable.people_from_string("@{a; #{alice.diaspora_handle}} @{a; #{alice.diaspora_handle}}")
|
||||||
|
expect(ppl).to eq([alice.person])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "fetches unknown handles" do
|
||||||
|
person = FactoryGirl.build(:person)
|
||||||
|
expect(Person).to receive(:find_or_fetch_by_identifier).with("xxx@xxx.xx").and_return(person)
|
||||||
|
ppl = Diaspora::Mentionable.people_from_string("@{a; xxx@xxx.xx}")
|
||||||
|
expect(ppl).to eq([person])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "handles DiscoveryError" do
|
||||||
|
expect(Person).to receive(:find_or_fetch_by_identifier).with("yyy@yyy.yy")
|
||||||
|
.and_raise(DiasporaFederation::Discovery::DiscoveryError)
|
||||||
|
ppl = Diaspora::Mentionable.people_from_string("@{b; yyy@yyy.yy}")
|
||||||
expect(ppl).to be_empty
|
expect(ppl).to be_empty
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ describe Publisher do
|
||||||
|
|
||||||
describe '#text' do
|
describe '#text' do
|
||||||
it 'is a formatted version of the prefill' do
|
it 'is a formatted version of the prefill' do
|
||||||
p = Publisher.new(alice, :prefill => "@{alice; alice@pod.com}")
|
p = Publisher.new(alice, prefill: "@{alice; #{alice.diaspora_handle}}")
|
||||||
expect(p.text).to eq("alice")
|
expect(p.text).to eq("alice")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue