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);
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',

View File

@ -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

View File

@ -989,7 +989,7 @@ en:
drafts_offline: "drafts offline"
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:
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[: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