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) {
const topic = this.get('model.topic');
const linkLookup = this.get('linkLookup');
if (linkLookup) {
const post = this.get('model.post');
if (post && post.get('user_id') !== this.currentUser.id) { return; }
if (!topic || !linkLookup) { return; }
const $links = $('a[href]', $preview);
$links.each((idx, l) => {
const href = $(l).prop('href');
if (href && href.length) {
const [warn, info] = linkLookup.check(post, href);
// Don't check if there's only one post
if (topic.get('posts_count') === 1) { return; }
if (warn) {
const body = I18n.t('composer.duplicate_link', {
domain: info.domain,
username: info.username,
post_url: info.post_url,
ago: relativeAge(moment(info.posted_at).toDate(), { format: 'medium' })
});
this.appEvents.trigger('composer-messages:create', {
extraClass: 'custom-body',
templateName: 'custom-body',
body
});
return false;
}
const post = this.get('model.post');
if (post && post.get('user_id') !== this.currentUser.id) { return; }
const $links = $('a[href]', $preview);
$links.each((idx, l) => {
const href = $(l).prop('href');
if (href && href.length) {
const [warn, info] = linkLookup.check(post, href);
if (warn) {
const body = I18n.t('composer.duplicate_link', {
domain: info.domain,
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() {

View File

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

View File

@ -232,8 +232,8 @@ class TopicLink < ActiveRecord::Base
normalized = tl.url.downcase.sub(/^https?:\/\//, '').sub(/\/$/, '')
lookup[normalized] = { domain: tl.domain,
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
lookup