From ae54a337195db3afc4447e81e5231a3e2f41ac1a Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Wed, 29 Apr 2020 14:46:56 +0800 Subject: [PATCH] FIX: discourse-presence breaks composer for users. --- .../composer-presence-display.js.es6 | 34 ++++++++----------- .../components/topic-presence-display.js.es6 | 4 +-- .../discourse/lib/presence-manager.js.es6 | 2 ++ .../composer-fields/presence.js.es6 | 8 +++-- .../presence.js.es6 | 6 ++-- .../initializers/discourse-presence.js.es6 | 2 +- 6 files changed, 30 insertions(+), 26 deletions(-) diff --git a/plugins/discourse-presence/assets/javascripts/discourse/components/composer-presence-display.js.es6 b/plugins/discourse-presence/assets/javascripts/discourse/components/composer-presence-display.js.es6 index 72edf988f71..b1329b1ddd3 100644 --- a/plugins/discourse-presence/assets/javascripts/discourse/components/composer-presence-display.js.es6 +++ b/plugins/discourse-presence/assets/javascripts/discourse/components/composer-presence-display.js.es6 @@ -24,7 +24,7 @@ export default Component.extend({ @on("didInsertElement") subscribe() { - this.presenceManager && this.presenceManager.subscribe(); + this.presenceManager.subscribe(); }, @discourseComputed( @@ -44,21 +44,19 @@ export default Component.extend({ @observes("reply", "title") typing() { - if (this.presenceManager) { - let action = this.action; + let action = this.action; - if (action !== REPLY && action !== EDIT) { - return; - } - - const postId = this.get("post.id"); - - this._throttle = this.presenceManager.throttlePublish( - action === EDIT ? EDITING : REPLYING, - this.whisper, - action === EDIT ? postId : undefined - ); + if (action !== REPLY && action !== EDIT) { + return; } + + const postId = this.get("post.id"); + + this._throttle = this.presenceManager.throttlePublish( + action === EDIT ? EDITING : REPLYING, + this.whisper, + action === EDIT ? postId : undefined + ); }, @observes("whisper") @@ -68,17 +66,15 @@ export default Component.extend({ @observes("post.id") stopEditing() { - if (this.presenceManager && !this.get("post.id")) { + if (!this.get("post.id")) { this.presenceManager.publish(CLOSED, this.whisper); } }, @on("willDestroyElement") composerClosing() { - if (this.presenceManager) { - this._cancelThrottle(); - this.presenceManager.publish(CLOSED, this.whisper); - } + this._cancelThrottle(); + this.presenceManager.publish(CLOSED, this.whisper); }, _cancelThrottle() { diff --git a/plugins/discourse-presence/assets/javascripts/discourse/components/topic-presence-display.js.es6 b/plugins/discourse-presence/assets/javascripts/discourse/components/topic-presence-display.js.es6 index 1f8ec4d27a3..bedb2921447 100644 --- a/plugins/discourse-presence/assets/javascripts/discourse/components/topic-presence-display.js.es6 +++ b/plugins/discourse-presence/assets/javascripts/discourse/components/topic-presence-display.js.es6 @@ -11,11 +11,11 @@ export default Component.extend({ @on("didInsertElement") subscribe() { - this.presenceManager && this.presenceManager.subscribe(); + this.presenceManager.subscribe(); }, @on("willDestroyElement") _destroyed() { - this.presenceManager && this.presenceManager.unsubscribe(); + this.presenceManager.unsubscribe(); } }); diff --git a/plugins/discourse-presence/assets/javascripts/discourse/lib/presence-manager.js.es6 b/plugins/discourse-presence/assets/javascripts/discourse/lib/presence-manager.js.es6 index fe5c1bd6b62..5943f76ce57 100644 --- a/plugins/discourse-presence/assets/javascripts/discourse/lib/presence-manager.js.es6 +++ b/plugins/discourse-presence/assets/javascripts/discourse/lib/presence-manager.js.es6 @@ -97,6 +97,8 @@ const PresenceManager = EmberObject.extend({ }, publish(state, whisper, postId) { + if (this.get("currentUser.hide_profile_and_presence")) return; + const data = { state, topic_id: this.get("topic.id") diff --git a/plugins/discourse-presence/assets/javascripts/discourse/templates/connectors/composer-fields/presence.js.es6 b/plugins/discourse-presence/assets/javascripts/discourse/templates/connectors/composer-fields/presence.js.es6 index 00fbc34d912..0240e680276 100644 --- a/plugins/discourse-presence/assets/javascripts/discourse/templates/connectors/composer-fields/presence.js.es6 +++ b/plugins/discourse-presence/assets/javascripts/discourse/templates/connectors/composer-fields/presence.js.es6 @@ -1,5 +1,9 @@ export default { - shouldRender(_, ctx) { - return ctx.siteSettings.presence_enabled; + shouldRender(args, component) { + return ( + component.siteSettings.presence_enabled && + args.model.topic && + args.model.topic.presenceManager + ); } }; diff --git a/plugins/discourse-presence/assets/javascripts/discourse/templates/connectors/topic-above-footer-buttons/presence.js.es6 b/plugins/discourse-presence/assets/javascripts/discourse/templates/connectors/topic-above-footer-buttons/presence.js.es6 index 00fbc34d912..db452d54c7a 100644 --- a/plugins/discourse-presence/assets/javascripts/discourse/templates/connectors/topic-above-footer-buttons/presence.js.es6 +++ b/plugins/discourse-presence/assets/javascripts/discourse/templates/connectors/topic-above-footer-buttons/presence.js.es6 @@ -1,5 +1,7 @@ export default { - shouldRender(_, ctx) { - return ctx.siteSettings.presence_enabled; + shouldRender(args, component) { + return ( + component.siteSettings.presence_enabled && args.model.presenceManager + ); } }; diff --git a/plugins/discourse-presence/assets/javascripts/initializers/discourse-presence.js.es6 b/plugins/discourse-presence/assets/javascripts/initializers/discourse-presence.js.es6 index 27a72524263..98ec8131987 100644 --- a/plugins/discourse-presence/assets/javascripts/initializers/discourse-presence.js.es6 +++ b/plugins/discourse-presence/assets/javascripts/initializers/discourse-presence.js.es6 @@ -6,7 +6,7 @@ function initializeDiscoursePresence(api) { const currentUser = api.getCurrentUser(); const siteSettings = api.container.lookup("site-settings:main"); - if (currentUser && !currentUser.hide_profile_and_presence) { + if (currentUser) { api.modifyClass("model:topic", { presenceManager: null });