FIX: Don't notify of duplicate links on edit of the first post

This commit is contained in:
Robin Ward 2016-06-09 13:02:44 -04:00
parent 024c2e90c1
commit df368ce251
3 changed files with 33 additions and 30 deletions

View File

@ -111,36 +111,39 @@ export default Ember.Controller.extend({
}, },
afterRefresh($preview) { afterRefresh($preview) {
const topic = this.get('model.topic');
const linkLookup = this.get('linkLookup'); const linkLookup = this.get('linkLookup');
if (linkLookup) { if (!topic || !linkLookup) { return; }
const post = this.get('model.post');
if (post && post.get('user_id') !== this.currentUser.id) { return; }
const $links = $('a[href]', $preview); // Don't check if there's only one post
$links.each((idx, l) => { if (topic.get('posts_count') === 1) { return; }
const href = $(l).prop('href');
if (href && href.length) {
const [warn, info] = linkLookup.check(post, href);
if (warn) { const post = this.get('model.post');
const body = I18n.t('composer.duplicate_link', { if (post && post.get('user_id') !== this.currentUser.id) { return; }
domain: info.domain,
username: info.username, const $links = $('a[href]', $preview);
post_url: info.post_url, $links.each((idx, l) => {
ago: relativeAge(moment(info.posted_at).toDate(), { format: 'medium' }) const href = $(l).prop('href');
}); if (href && href.length) {
this.appEvents.trigger('composer-messages:create', { const [warn, info] = linkLookup.check(post, href);
extraClass: 'custom-body',
templateName: 'custom-body', if (warn) {
body const body = I18n.t('composer.duplicate_link', {
}); domain: info.domain,
return false; username: info.username,
} post_url: topic.urlForPostNumber(info.post_number),
ago: relativeAge(moment(info.posted_at).toDate(), { format: 'medium' })
});
this.appEvents.trigger('composer-messages:create', {
extraClass: 'custom-body',
templateName: 'custom-body',
body
});
return false;
} }
return true; }
}); return true;
} });
}, },
toggleWhisper() { toggleWhisper() {

View File

@ -16,8 +16,8 @@ export default class LinkLookup {
const linkInfo = this._links[normalized]; const linkInfo = this._links[normalized];
if (linkInfo) { if (linkInfo) {
// Skip edits to the same URL // Skip edits to the same post
if (post && post.get('url') === linkInfo.post_url) { return NO_RESULT; } if (post && post.get('post_number') === linkInfo.post_number) { return NO_RESULT; }
_warned[href] = true; _warned[href] = true;
_warned[normalized] = true; _warned[normalized] = true;

View File

@ -232,8 +232,8 @@ class TopicLink < ActiveRecord::Base
normalized = tl.url.downcase.sub(/^https?:\/\//, '').sub(/\/$/, '') normalized = tl.url.downcase.sub(/^https?:\/\//, '').sub(/\/$/, '')
lookup[normalized] = { domain: tl.domain, lookup[normalized] = { domain: tl.domain,
username: tl.post.user.username_lower, username: tl.post.user.username_lower,
post_url: tl.post.url, posted_at: tl.post.created_at,
posted_at: tl.post.created_at } post_number: tl.post.post_number }
end end
lookup lookup