FIX: discourse-presence breaks composer for users.

This commit is contained in:
Guo Xiang Tan 2020-04-29 14:46:56 +08:00
parent 4fe4b3cce3
commit ae54a33719
No known key found for this signature in database
GPG Key ID: FBD110179AAC1F20
6 changed files with 30 additions and 26 deletions

View File

@ -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() {

View File

@ -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();
}
});

View File

@ -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")

View File

@ -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
);
}
};

View File

@ -1,5 +1,7 @@
export default {
shouldRender(_, ctx) {
return ctx.siteSettings.presence_enabled;
shouldRender(args, component) {
return (
component.siteSettings.presence_enabled && args.model.presenceManager
);
}
};

View File

@ -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
});