diff --git a/app/assets/javascripts/discourse/components/scrolling-post-stream.js.es6 b/app/assets/javascripts/discourse/components/scrolling-post-stream.js.es6 index 4f4b87991..2eaaf8e3f 100644 --- a/app/assets/javascripts/discourse/components/scrolling-post-stream.js.es6 +++ b/app/assets/javascripts/discourse/components/scrolling-post-stream.js.es6 @@ -1,3 +1,4 @@ +import DiscourseURL from 'discourse/lib/url'; import { keyDirty } from 'discourse/widgets/widget'; import MountWidget from 'discourse/components/mount-widget'; @@ -129,6 +130,17 @@ export default MountWidget.extend({ $(window).bind('scroll.post-stream', debouncedScroll); this._scrollTriggered(); + this.appEvents.on('post-stream:posted', staged => { + const disableJumpReply = this.currentUser.get('disable_jump_reply'); + + this.queueRerender(() => { + if (staged && !disableJumpReply) { + const postNumber = staged.get('post_number'); + DiscourseURL.jumpToPost(postNumber, { skipIfOnScreen: true }); + } + }); + }); + this.$().on('mouseenter.post-stream', 'button.widget-button', e => { $('button.widget-button').removeClass('d-hover'); $(e.target).addClass('d-hover'); @@ -154,6 +166,7 @@ export default MountWidget.extend({ this.$().off('mouseenter.post-stream'); this.$().off('mouseleave.post-stream'); this.appEvents.off('post-stream:refresh'); + this.appEvents.off('post-stream:posted'); } }); diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6 index b7c1ae0d0..6031288a7 100644 --- a/app/assets/javascripts/discourse/controllers/composer.js.es6 +++ b/app/assets/javascripts/discourse/controllers/composer.js.es6 @@ -263,7 +263,6 @@ export default Ember.Controller.extend({ } var staged = false; - const disableJumpReply = Discourse.User.currentProp('disable_jump_reply'); // TODO: This should not happen in model const imageSizes = {}; @@ -290,6 +289,9 @@ export default Ember.Controller.extend({ } self.appEvents.trigger('post-stream:refresh'); + if (result.responseJson.action === "create_post") { + self.appEvents.trigger('post:highlight', result.payload.post_number); + } self.close(); const currentUser = Discourse.User.current(); @@ -299,14 +301,6 @@ export default Ember.Controller.extend({ currentUser.set('reply_count', currentUser.get('reply_count') + 1); } - // TODO disableJumpReply is super crude, it needs to provide some sort - // of notification to the end user - if (!composer.get('replyingToTopic') || !disableJumpReply) { - const post = result.target; - if (post && !staged) { - DiscourseURL.routeTo(post.get('url')); - } - } }).catch(function(error) { composer.set('disableDrafts', false); self.appEvents.one('composer:opened', () => bootbox.alert(error)); @@ -317,18 +311,10 @@ export default Ember.Controller.extend({ staged = composer.get('stagedPost'); } - Em.run.schedule('afterRender', function() { - if (staged && !disableJumpReply) { - const postNumber = staged.get('post_number'); - DiscourseURL.jumpToPost(postNumber, { skipIfOnScreen: true }); - self.appEvents.trigger('post:highlight', postNumber); - } - }); + this.appEvents.trigger('post-stream:posted', staged); this.messageBus.pause(); - promise.finally(function(){ - self.messageBus.resume(); - }); + promise.finally(() => this.messageBus.resume()); return promise; }, diff --git a/app/assets/javascripts/discourse/models/post-stream.js.es6 b/app/assets/javascripts/discourse/models/post-stream.js.es6 index effe485cc..f9118bf4a 100644 --- a/app/assets/javascripts/discourse/models/post-stream.js.es6 +++ b/app/assets/javascripts/discourse/models/post-stream.js.es6 @@ -363,7 +363,6 @@ export default RestModel.extend({ // Commit the post we staged. Call this after a save succeeds. commitPost(post) { - if (this.get('topic.id') === post.get('topic_id')) { if (this.get('loadedAllPosts')) { this.appendPost(post); diff --git a/app/assets/javascripts/discourse/views/topic.js.es6 b/app/assets/javascripts/discourse/views/topic.js.es6 index 93b3adb12..96cdf5826 100644 --- a/app/assets/javascripts/discourse/views/topic.js.es6 +++ b/app/assets/javascripts/discourse/views/topic.js.es6 @@ -185,7 +185,7 @@ function highlight(postNumber) { }); } -listenForViewEvent(TopicView, 'post:highlight', function(postNumber) { +listenForViewEvent(TopicView, 'post:highlight', postNumber => { Ember.run.scheduleOnce('afterRender', null, highlight, postNumber); });