FIX: Duplicate link message should link to the post

This commit is contained in:
Robin Ward 2016-06-08 12:35:11 -04:00
parent ef6bcc08ce
commit 2169b1ecbc
4 changed files with 14 additions and 15 deletions

View file

@ -121,11 +121,12 @@ export default Ember.Controller.extend({
const [warn, info] = linkLookup.check(href); const [warn, info] = linkLookup.check(href);
if (warn) { if (warn) {
console.log(info);
const body = I18n.t('composer.duplicate_link', { const body = I18n.t('composer.duplicate_link', {
domain: info.domain, domain: info.domain,
username: info.username, username: info.username,
ago: relativeAge(moment(info.posted_at).toDate(), { format: 'medium' }), post_url: info.post_url,
href ago: relativeAge(moment(info.posted_at).toDate(), { format: 'medium' })
}); });
this.appEvents.trigger('composer-messages:create', { this.appEvents.trigger('composer-messages:create', {
extraClass: 'custom-body', extraClass: 'custom-body',

View file

@ -216,21 +216,18 @@ class TopicLink < ActiveRecord::Base
end end
def self.duplicate_lookup(topic) 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 = {} lookup = {}
results.each do |tl|
builder.exec.to_a.each do |row| normalized = tl.url.downcase.sub(/^https?:\/\//, '')
normalized = row['url'].downcase.sub(/^https?:\/\//, '') lookup[normalized] = { domain: tl.domain,
lookup[normalized] = {domain: row['domain'], username: row['username_lower'], posted_at: row['created_at']} username: tl.post.user.username_lower,
post_url: tl.post.url,
posted_at: tl.post.created_at }
end end
lookup lookup

View file

@ -989,7 +989,7 @@ en:
drafts_offline: "drafts offline" drafts_offline: "drafts offline"
group_mentioned: "By mentioning {{group}}, you are about to notify <a href='{{group_link}}'>{{count}} people</a>." group_mentioned: "By mentioning {{group}}, you are about to notify <a href='{{group_link}}'>{{count}} people</a>."
duplicate_link: "It looks like your link to <b>{{domain}}</b> was already posted in the topic by <b>@{{username}}</b> in <a href='{{href}}'>an earlier reply on {{ago}}</a>" duplicate_link: "It looks like your link to <b>{{domain}}</b> was already posted in the topic by <b>@{{username}}</b> in <a href='{{post_url}}'>an earlier reply on {{ago}}</a>"
error: error:
title_missing: "Title is required" title_missing: "Title is required"

View file

@ -286,6 +286,7 @@ http://b.com/#{'a'*500}
expect(ch[:domain]).to eq('www.codinghorror.com') expect(ch[:domain]).to eq('www.codinghorror.com')
expect(ch[:username]).to eq(post.username) expect(ch[:username]).to eq(post.username)
expect(ch[:posted_at]).to be_present expect(ch[:posted_at]).to be_present
expect(ch[:post_url]).to be_present
end end
it 'has the correct results' do it 'has the correct results' do