From b301b69d0045aad4aec452221372c83f7cab6ce6 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 12 May 2017 12:37:02 -0400 Subject: [PATCH] FIX: Don't warn users about duplicate links for: - The original post - If the post is older than (x) (Two Weeks for now) --- .../discourse/controllers/composer.js.es6 | 2 -- .../javascripts/discourse/lib/link-lookup.js.es6 | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6 index 19255347a22..70e1d4ee64d 100644 --- a/app/assets/javascripts/discourse/controllers/composer.js.es6 +++ b/app/assets/javascripts/discourse/controllers/composer.js.es6 @@ -228,8 +228,6 @@ export default Ember.Controller.extend({ if (topic.get('posts_count') === 1) { return; } 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'); diff --git a/app/assets/javascripts/discourse/lib/link-lookup.js.es6 b/app/assets/javascripts/discourse/lib/link-lookup.js.es6 index 2501775709a..f8d643efaf7 100644 --- a/app/assets/javascripts/discourse/lib/link-lookup.js.es6 +++ b/app/assets/javascripts/discourse/lib/link-lookup.js.es6 @@ -1,5 +1,4 @@ const _warned = {}; - const NO_RESULT = [false, null]; export default class LinkLookup { @@ -16,8 +15,18 @@ export default class LinkLookup { const linkInfo = this._links[normalized]; if (linkInfo) { - // Skip edits to the same post - if (post && post.get('post_number') === linkInfo.post_number) { return NO_RESULT; } + + if (post) { + // Skip edits to the OP + const postNumber = post.get('post_number'); + if (postNumber === 1) { return NO_RESULT; } + + // Don't warn on older posts + const createdAt = moment(post.get('created_at')); + if (createdAt.isBefore(moment().subtract(2, 'weeks'))) { + return NO_RESULT; + } + } _warned[href] = true; _warned[normalized] = true;