A platform for community discussion. Free, open, simple.
FIX: throttles topic tracking shortcut and enforces topic id (#9159)
Joffrey JAFFEUX3f2c0b42fecf
diff --git a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6index cf22919b07e..69f42cfee16 100644--- a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6+++ b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6@@ -3,6 +3,7 @@ import DiscourseURL from "discourse/lib/url";import Composer from "discourse/models/composer";import { minimumOffset } from "discourse/lib/offset-calculator";import { ajax } from "discourse/lib/ajax";+import { throttle } from "@ember/runloop";const bindings = {"!": { postAction: "showFlags" },@@ -298,34 +299,26 @@ export default {},setTrackingToMuted(event) {- this.appEvents.trigger("topic-notifications-button:changed", {- type: "notification",- id: 0,- event- });+ throttle(this, "_setTracking", { id: 0, event }, 250, true);},setTrackingToRegular(event) {- this.appEvents.trigger("topic-notifications-button:changed", {- type: "notification",- id: 1,- event- });+ throttle(this, "_setTracking", { id: 1, event }, 250, true);},setTrackingToTracking(event) {- this.appEvents.trigger("topic-notifications-button:changed", {- type: "notification",- id: 2,- event- });+ throttle(this, "_setTracking", { id: 2, event }, 250, true);},setTrackingToWatching(event) {+ throttle(this, "_setTracking", { id: 3, event }, 250, true);+ },++ _setTracking(params) {this.appEvents.trigger("topic-notifications-button:changed", {type: "notification",- id: 3,- event+ id: params.id,+ event: params.event});},diff --git a/app/assets/javascripts/select-kit/components/topic-notifications-button.js.es6 b/app/assets/javascripts/select-kit/components/topic-notifications-button.js.es6index 4ff6b5d151b..747685c2aef 100644--- a/app/assets/javascripts/select-kit/components/topic-notifications-button.js.es6+++ b/app/assets/javascripts/select-kit/components/topic-notifications-button.js.es6@@ -28,6 +28,17 @@ export default Component.extend({},_changeTopicNotificationLevel(level) {+ // this change is coming from a keyboard event+ if (level.event) {+ const topicSectionNode = level.event.target.querySelector("#topic");+ if (topicSectionNode && topicSectionNode.dataset.topicId) {+ const topicId = parseInt(topicSectionNode.dataset.topicId, 10);+ if (topicId && topicId !== this.topic.id) {+ return;+ }+ }+ }+if (level.id !== this.notificationLevel) {this.topic.details.updateNotifications(level.id);}