diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6
index cea291053..9631040a3 100644
--- a/app/assets/javascripts/discourse/controllers/composer.js.es6
+++ b/app/assets/javascripts/discourse/controllers/composer.js.es6
@@ -121,11 +121,12 @@ export default Ember.Controller.extend({
const [warn, info] = linkLookup.check(href);
if (warn) {
+ console.log(info);
const body = I18n.t('composer.duplicate_link', {
domain: info.domain,
username: info.username,
- ago: relativeAge(moment(info.posted_at).toDate(), { format: 'medium' }),
- href
+ post_url: info.post_url,
+ ago: relativeAge(moment(info.posted_at).toDate(), { format: 'medium' })
});
this.appEvents.trigger('composer-messages:create', {
extraClass: 'custom-body',
diff --git a/app/models/topic_link.rb b/app/models/topic_link.rb
index c1e54cd4c..0f19ba7d3 100644
--- a/app/models/topic_link.rb
+++ b/app/models/topic_link.rb
@@ -216,21 +216,18 @@ class TopicLink < ActiveRecord::Base
end
def self.duplicate_lookup(topic)
- builder = SqlBuilder.new("SELECT tl.url, tl.domain, u.username_lower, p.created_at
- FROM topic_links AS tl
- INNER JOIN posts AS p ON p.id = tl.post_id
- INNER JOIN users AS u ON p.user_id = u.id
- /*where*/
- ORDER BY p.created_at DESC
- LIMIT 200")
- builder.where('tl.topic_id = :topic_id', topic_id: topic.id)
+ results = TopicLink
+ .includes(:post => :user)
+ .where(topic_id: topic.id).limit(200)
lookup = {}
-
- builder.exec.to_a.each do |row|
- normalized = row['url'].downcase.sub(/^https?:\/\//, '')
- lookup[normalized] = {domain: row['domain'], username: row['username_lower'], posted_at: row['created_at']}
+ results.each do |tl|
+ normalized = tl.url.downcase.sub(/^https?:\/\//, '')
+ lookup[normalized] = { domain: tl.domain,
+ username: tl.post.user.username_lower,
+ post_url: tl.post.url,
+ posted_at: tl.post.created_at }
end
lookup
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index ce457927e..a7d58b669 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -989,7 +989,7 @@ en:
drafts_offline: "drafts offline"
group_mentioned: "By mentioning {{group}}, you are about to notify {{count}} people."
- duplicate_link: "It looks like your link to {{domain}} was already posted in the topic by @{{username}} in an earlier reply on {{ago}}"
+ duplicate_link: "It looks like your link to {{domain}} was already posted in the topic by @{{username}} in an earlier reply on {{ago}}"
error:
title_missing: "Title is required"
diff --git a/spec/models/topic_link_spec.rb b/spec/models/topic_link_spec.rb
index 7a7109d58..bb5afa16c 100644
--- a/spec/models/topic_link_spec.rb
+++ b/spec/models/topic_link_spec.rb
@@ -286,6 +286,7 @@ http://b.com/#{'a'*500}
expect(ch[:domain]).to eq('www.codinghorror.com')
expect(ch[:username]).to eq(post.username)
expect(ch[:posted_at]).to be_present
+ expect(ch[:post_url]).to be_present
end
it 'has the correct results' do