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,9 +111,13 @@ export default Ember.Controller.extend({
},
afterRefresh($preview) {
const topic = this.get('model.topic');
const linkLookup = this.get('linkLookup');
if (linkLookup) {
if (!topic || !linkLookup) { return; }
// Don't check if there's only one post
if (topic.get('posts_count') === 1) { return; }
const post = this.get('model.post');
if (post && post.get('user_id') !== this.currentUser.id) { return; }
@ -127,7 +131,7 @@ export default Ember.Controller.extend({
const body = I18n.t('composer.duplicate_link', {
domain: info.domain,
username: info.username,
post_url: info.post_url,
post_url: topic.urlForPostNumber(info.post_number),
ago: relativeAge(moment(info.posted_at).toDate(), { format: 'medium' })
});
this.appEvents.trigger('composer-messages:create', {
@ -140,7 +144,6 @@ export default Ember.Controller.extend({
}
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