FIX: Throttle typing function in discourse-presence.

FIX: Throttle typing function in discourse-presence.

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 6f94bad..c8bde29 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
@@ -1,12 +1,18 @@
 import Component from "@ember/component";
-import { cancel } from "@ember/runloop";
+import { cancel, throttle } from "@ember/runloop";
 import { equal, gt } from "@ember/object/computed";
 import { inject as service } from "@ember/service";
 import discourseComputed, {
   observes,
   on
 } from "discourse-common/utils/decorators";
-import { REPLYING, CLOSED, EDITING, COMPOSER_TYPE } from "../lib/presence";
+import {
+  REPLYING,
+  CLOSED,
+  EDITING,
+  COMPOSER_TYPE,
+  KEEP_ALIVE_DURATION_SECONDS
+} from "../lib/presence";
 import { REPLY, EDIT } from "discourse/models/composer";
 
 export default Component.extend({
@@ -55,6 +61,10 @@ export default Component.extend({
 
   @observes("reply", "title")
   typing() {
+    throttle(this, this._typing, KEEP_ALIVE_DURATION_SECONDS * 1000);
+  },
+
+  _typing() {
     const action = this.action;
 
     if (action !== REPLY && action !== EDIT) {
@@ -70,7 +80,7 @@ export default Component.extend({
 
     this._prevPublishData = data;
 
-    this._throttle = this.presenceManager.throttlePublish(
+    this._throttle = this.presenceManager.publish(
       data.topicId,
       data.state,
       data.whisper,
diff --git a/plugins/discourse-presence/assets/javascripts/discourse/lib/presence.js.es6 b/plugins/discourse-presence/assets/javascripts/discourse/lib/presence.js.es6
index 57eedc0..7bf057f 100644
--- a/plugins/discourse-presence/assets/javascripts/discourse/lib/presence.js.es6
+++ b/plugins/discourse-presence/assets/javascripts/discourse/lib/presence.js.es6
@@ -1,5 +1,5 @@
 import EmberObject from "@ember/object";
-import { cancel, later, throttle } from "@ember/runloop";
+import { cancel, later } from "@ember/runloop";
 import { ajax } from "discourse/lib/ajax";
 import discourseComputed from "discourse-common/utils/decorators";
 
@@ -99,17 +99,6 @@ const Presence = EmberObject.extend({
     return `/presence/${topicId}`;
   },
 
-  throttlePublish(state, whisper, postId) {
-    return throttle(
-      this,
-      this.publish,
-      state,
-      whisper,
-      postId,
-      KEEP_ALIVE_DURATION_SECONDS * 1000
-    );
-  },
-
   publish(state, whisper, postId) {
     if (this.get("currentUser.hide_profile_and_presence")) return;
 
diff --git a/plugins/discourse-presence/assets/javascripts/discourse/services/presence-manager.js.es6 b/plugins/discourse-presence/assets/javascripts/discourse/services/presence-manager.js.es6
index 1aaca2d..63af48d 100644
--- a/plugins/discourse-presence/assets/javascripts/discourse/services/presence-manager.js.es6
+++ b/plugins/discourse-presence/assets/javascripts/discourse/services/presence-manager.js.es6
@@ -36,11 +36,6 @@ const PresenceManager = Service.extend({
     return this._getPresence(topicId).editingUsers;
   },
 
-  throttlePublish(topicId, state, whisper, postId) {
-    if (!topicId) return;
-    return this._getPresence(topicId).throttlePublish(state, whisper, postId);
-  },
-
   publish(topicId, state, whisper, postId) {
     if (!topicId) return;
     return this._getPresence(topicId).publish(state, whisper, postId);

GitHub sha: aa40a07d

In core we prefer to use full module names like discourse/lib/presence - I see it didn’t start in this PR but it’s generally easier for us to reason with for deprecations and loading. Just something to keep in mind in the future.

Thank you for sharing :+1: I’ve fixed it in https://github.com/discourse/discourse/commit/c5ef4651797b411ed9201239f205d13bd163742e