FIX: Cleanup PresenceChannel instances when composer closed (#14741)

I was previously relying on `this.isDestroying` returning `true` during `willDestroyElement`. This was an incorrect assumption.

This commit refactors the logic into an explicit `cleanup` function, and also adds some cleanup for empty keys in the `subscribedProxy` array
This commit is contained in:
David Taylor
2021-10-27 15:17:10 +01:00
committed by GitHub
parent 103de1f20d
commit 79ad0860a2
2 changed files with 13 additions and 5 deletions

View File

@ -14,11 +14,10 @@ export default Component.extend({
"model.replyingToTopic",
"model.editingPost",
"model.whisper",
"model.composerOpened",
"isDestroying"
"model.composerOpened"
)
state(replyingToTopic, editingPost, whisper, composerOpen, isDestroying) {
if (!composerOpen || isDestroying) {
state(replyingToTopic, editingPost, whisper, composerOpen) {
if (!composerOpen) {
return;
} else if (editingPost) {
return "edit";
@ -73,6 +72,12 @@ export default Component.extend({
this._setupChannel("editChannel", this.editChannelName);
},
_cleanupChannels() {
this._setupChannel("replyChannel", null);
this._setupChannel("whisperChannel", null);
this._setupChannel("editChannel", null);
},
replyingUsers: union("replyChannel.users", "whisperChannel.users"),
editingUsers: readOnly("editChannel.users"),
@ -102,7 +107,7 @@ export default Component.extend({
@on("willDestroyElement")
closeComposer() {
this._setupChannels();
this._cleanupChannels();
this.composerPresenceManager.leave();
},
});