FIX: Throttle typing function in discourse-presence.

This commit is contained in:
Guo Xiang Tan 2020-05-13 13:26:24 +08:00
parent 0e09c5837f
commit aa40a07d73
No known key found for this signature in database
GPG Key ID: FBD110179AAC1F20
3 changed files with 14 additions and 20 deletions
plugins/discourse-presence/assets/javascripts/discourse

@ -1,12 +1,18 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { cancel } from "@ember/runloop"; import { cancel, throttle } from "@ember/runloop";
import { equal, gt } from "@ember/object/computed"; import { equal, gt } from "@ember/object/computed";
import { inject as service } from "@ember/service"; import { inject as service } from "@ember/service";
import discourseComputed, { import discourseComputed, {
observes, observes,
on on
} from "discourse-common/utils/decorators"; } 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"; import { REPLY, EDIT } from "discourse/models/composer";
export default Component.extend({ export default Component.extend({
@ -55,6 +61,10 @@ export default Component.extend({
@observes("reply", "title") @observes("reply", "title")
typing() { typing() {
throttle(this, this._typing, KEEP_ALIVE_DURATION_SECONDS * 1000);
},
_typing() {
const action = this.action; const action = this.action;
if (action !== REPLY && action !== EDIT) { if (action !== REPLY && action !== EDIT) {
@ -70,7 +80,7 @@ export default Component.extend({
this._prevPublishData = data; this._prevPublishData = data;
this._throttle = this.presenceManager.throttlePublish( this._throttle = this.presenceManager.publish(
data.topicId, data.topicId,
data.state, data.state,
data.whisper, data.whisper,

@ -1,5 +1,5 @@
import EmberObject from "@ember/object"; 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 { ajax } from "discourse/lib/ajax";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
@ -99,17 +99,6 @@ const Presence = EmberObject.extend({
return `/presence/${topicId}`; return `/presence/${topicId}`;
}, },
throttlePublish(state, whisper, postId) {
return throttle(
this,
this.publish,
state,
whisper,
postId,
KEEP_ALIVE_DURATION_SECONDS * 1000
);
},
publish(state, whisper, postId) { publish(state, whisper, postId) {
if (this.get("currentUser.hide_profile_and_presence")) return; if (this.get("currentUser.hide_profile_and_presence")) return;

@ -36,11 +36,6 @@ const PresenceManager = Service.extend({
return this._getPresence(topicId).editingUsers; 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) { publish(topicId, state, whisper, postId) {
if (!topicId) return; if (!topicId) return;
return this._getPresence(topicId).publish(state, whisper, postId); return this._getPresence(topicId).publish(state, whisper, postId);