mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 03:54:59 +08:00
FIX: Duplicate link message should link to the post
This commit is contained in:
parent
ef6bcc08ce
commit
2169b1ecbc
|
@ -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',
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user