From 5c444e62bef5a8f2c1211828e9fce561ee450ef9 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sun, 12 Feb 2017 19:54:16 +0100 Subject: [PATCH] Add @ before mentions for mobile and notifications fixes #7269 --- lib/diaspora/mentionable.rb | 4 ++-- spec/lib/diaspora/mentionable_spec.rb | 25 +++++++++++----------- spec/lib/diaspora/message_renderer_spec.rb | 6 +++--- spec/lib/publisher_spec.rb | 2 +- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/diaspora/mentionable.rb b/lib/diaspora/mentionable.rb index 72a0ffcf5..fb6117a45 100644 --- a/lib/diaspora/mentionable.rb +++ b/lib/diaspora/mentionable.rb @@ -32,7 +32,7 @@ module Diaspora::Mentionable name, diaspora_id = mention_attrs(match_str) person = people.find {|p| p.diaspora_handle == diaspora_id } - ERB::Util.h(MentionsInternal.mention_link(person, name, diaspora_id, opts)) + "@#{ERB::Util.h(MentionsInternal.mention_link(person, name, diaspora_id, opts))}" } end @@ -64,7 +64,7 @@ module Diaspora::Mentionable if person && allowed_people.include?(person.id) match_str else - MentionsInternal.profile_link(person, name, diaspora_id) + "@#{MentionsInternal.profile_link(person, name, diaspora_id)}" end } end diff --git a/spec/lib/diaspora/mentionable_spec.rb b/spec/lib/diaspora/mentionable_spec.rb index 58b453c17..477e6837b 100644 --- a/spec/lib/diaspora/mentionable_spec.rb +++ b/spec/lib/diaspora/mentionable_spec.rb @@ -44,7 +44,8 @@ STR fmt_msg = Diaspora::Mentionable.format(test_text_with_names, people) [people, names].transpose.each do |person, name| - expect(fmt_msg).to include person_link(person, class: "mention hovercardable", display_name: name) + link = person_link(person, class: "mention hovercardable", display_name: name) + expect(fmt_msg).to include "@#{link}" end end @@ -52,7 +53,8 @@ STR fmt_msg = Diaspora::Mentionable.format(test_text_without_names, people) people.each do |person| - expect(fmt_msg).to include person_link(person, class: "mention hovercardable", display_name: person.name) + link = person_link(person, class: "mention hovercardable", display_name: person.name) + expect(fmt_msg).to include "@#{link}" end end @@ -80,7 +82,7 @@ STR fmt_msg = Diaspora::Mentionable.format(test_text_with_names, people, plain_text: true) names.each do |name| - expect(fmt_msg).to include CGI.escapeHTML(name) + expect(fmt_msg).to include "@#{CGI.escapeHTML(name)}" end expect(fmt_msg).not_to include "", "hovercardable" end @@ -89,9 +91,9 @@ STR it "leaves the names of people that cannot be found" do test_txt_plain = <<-STR This post contains a lot of mentions -one Alice A, -two Bob B and finally -three "Eve> E. +one @Alice A, +two @Bob B and finally +three @"Eve> E. STR fmt_msg = Diaspora::Mentionable.format(test_text_with_names, []) @@ -101,9 +103,9 @@ STR it "uses the diaspora ID when the person cannot be found" do test_txt_plain = <<-STR This post contains a lot of mentions -one #{people[0].diaspora_handle}, -two #{people[1].diaspora_handle} and finally -three #{people[2].diaspora_handle}. +one @#{people[0].diaspora_handle}, +two @#{people[1].diaspora_handle} and finally +three @#{people[2].diaspora_handle}. STR fmt_msg = Diaspora::Mentionable.format(test_text_without_names, []) @@ -180,8 +182,7 @@ STR user_a.aspects.where(name: "generic").first.contacts.map(&:person_id) ) - expect(txt).to include("user C") - expect(txt).to include(local_or_remote_person_path(user_c.person)) + expect(txt).to include("@[user C](#{local_or_remote_person_path(user_c.person)}") expect(txt).not_to include("href") expect(txt).not_to include(mention) end @@ -203,7 +204,7 @@ STR mention = "@{non_existing_user@example.org}" txt = Diaspora::Mentionable.filter_people("mentioning #{mention}", []) - expect(txt).to eq "mentioning non_existing_user@example.org" + expect(txt).to eq "mentioning @non_existing_user@example.org" end end diff --git a/spec/lib/diaspora/message_renderer_spec.rb b/spec/lib/diaspora/message_renderer_spec.rb index 78611a324..f72adc240 100644 --- a/spec/lib/diaspora/message_renderer_spec.rb +++ b/spec/lib/diaspora/message_renderer_spec.rb @@ -195,17 +195,17 @@ describe Diaspora::MessageRenderer do context "with mention" do it "contains the name of the mentioned person" do msg = message("@{#{alice.diaspora_handle}} is cool", mentioned_people: alice.person) - expect(msg.plain_text_without_markdown).to eq "#{alice.name} is cool" + expect(msg.plain_text_without_markdown).to eq "@#{alice.name} is cool" end it "uses the name from mention when the mention contains a name" do msg = message("@{Alice; #{alice.diaspora_handle}} is cool", mentioned_people: alice.person) - expect(msg.plain_text_without_markdown).to eq "Alice is cool" + expect(msg.plain_text_without_markdown).to eq "@Alice is cool" end it "uses the diaspora ID when the person cannot be found" do msg = message("@{#{alice.diaspora_handle}} is cool", mentioned_people: []) - expect(msg.plain_text_without_markdown).to eq "#{alice.diaspora_handle} is cool" + expect(msg.plain_text_without_markdown).to eq "@#{alice.diaspora_handle} is cool" end end end diff --git a/spec/lib/publisher_spec.rb b/spec/lib/publisher_spec.rb index 8eeb76d24..f8479d884 100644 --- a/spec/lib/publisher_spec.rb +++ b/spec/lib/publisher_spec.rb @@ -16,7 +16,7 @@ describe Publisher do describe '#text' do it 'is a formatted version of the prefill' do p = Publisher.new(alice, prefill: "@{alice; #{alice.diaspora_handle}}") - expect(p.text).to eq("alice") + expect(p.text).to eq("@alice") end end