Loading Changelog.md +1 −0 Original line number Diff line number Diff line Loading @@ -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) * 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) * Fetch missing persons when receiving a mention for them [#6992](https://github.com/diaspora/diaspora/pull/6992) # 0.5.10.2 Loading lib/diaspora/mentionable.rb +9 −4 Original line number Diff line number Diff line Loading @@ -46,12 +46,11 @@ module Diaspora::Mentionable # @return [Array<Person>] array of people def self.people_from_string(msg_text) identifiers = msg_text.to_s.scan(REGEX).map do |match_str| _, handle = mention_attrs(match_str.first) handle _, identifier = mention_attrs(match_str.first) identifier if Validation::Rule::DiasporaId.new.valid_value?(identifier) end return [] if identifiers.empty? Person.where(diaspora_handle: identifiers) identifiers.compact.uniq.map {|identifier| find_or_fetch_person_by_identifier(identifier) }.compact end # takes a message text and converts mentions for people that are not in the Loading Loading @@ -81,6 +80,12 @@ module Diaspora::Mentionable 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 module MentionsInternal extend ::PeopleHelper Loading spec/lib/diaspora/mentionable_spec.rb +21 −2 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ STR describe "#people_from_string" do it "extracts the mentioned people from the text" do ppl = Diaspora::Mentionable.people_from_string(@test_txt) expect(ppl).to include(*@people) expect(ppl).to match_array(@people) end describe "returns an empty array if nobody was found" do Loading @@ -80,7 +80,26 @@ STR end 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 end end Loading spec/lib/publisher_spec.rb +1 −1 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ describe Publisher do describe '#text' 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") end end Loading Loading
Changelog.md +1 −0 Original line number Diff line number Diff line Loading @@ -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) * 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) * Fetch missing persons when receiving a mention for them [#6992](https://github.com/diaspora/diaspora/pull/6992) # 0.5.10.2 Loading
lib/diaspora/mentionable.rb +9 −4 Original line number Diff line number Diff line Loading @@ -46,12 +46,11 @@ module Diaspora::Mentionable # @return [Array<Person>] array of people def self.people_from_string(msg_text) identifiers = msg_text.to_s.scan(REGEX).map do |match_str| _, handle = mention_attrs(match_str.first) handle _, identifier = mention_attrs(match_str.first) identifier if Validation::Rule::DiasporaId.new.valid_value?(identifier) end return [] if identifiers.empty? Person.where(diaspora_handle: identifiers) identifiers.compact.uniq.map {|identifier| find_or_fetch_person_by_identifier(identifier) }.compact end # takes a message text and converts mentions for people that are not in the Loading Loading @@ -81,6 +80,12 @@ module Diaspora::Mentionable 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 module MentionsInternal extend ::PeopleHelper Loading
spec/lib/diaspora/mentionable_spec.rb +21 −2 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ STR describe "#people_from_string" do it "extracts the mentioned people from the text" do ppl = Diaspora::Mentionable.people_from_string(@test_txt) expect(ppl).to include(*@people) expect(ppl).to match_array(@people) end describe "returns an empty array if nobody was found" do Loading @@ -80,7 +80,26 @@ STR end 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 end end Loading
spec/lib/publisher_spec.rb +1 −1 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ describe Publisher do describe '#text' 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") end end Loading