fix: Use bus.$off to remove listeners on destroy (#3478)
This commit is contained in:
parent
86dfdfb9ab
commit
0899f62912
8 changed files with 44 additions and 24 deletions
|
@ -74,9 +74,10 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_last_seen
|
def update_last_seen
|
||||||
@conversation.agent_last_seen_at = DateTime.now.utc
|
# rubocop:disable Rails/SkipsModelValidations
|
||||||
@conversation.assignee_last_seen_at = DateTime.now.utc if assignee?
|
@conversation.update_column(:agent_last_seen_at, DateTime.now.utc)
|
||||||
@conversation.save!
|
@conversation.update_column(:assignee_last_seen_at, DateTime.now.utc) if assignee?
|
||||||
|
# rubocop:enable Rails/SkipsModelValidations
|
||||||
end
|
end
|
||||||
|
|
||||||
def custom_attributes
|
def custom_attributes
|
||||||
|
|
|
@ -3,10 +3,12 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { BUS_EVENTS } from 'shared/constants/busEvents';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
methods: {
|
methods: {
|
||||||
onMenuItemClick() {
|
onMenuItemClick() {
|
||||||
bus.$emit('sidemenu_icon_click');
|
bus.$emit(BUS_EVENTS.TOGGLE_SIDEMENU);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,12 +29,16 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
bus.$on('newToastMessage', message => {
|
bus.$on('newToastMessage', this.onNewToastMessage);
|
||||||
|
},
|
||||||
|
beforeDestroy() {
|
||||||
|
bus.$off('newToastMessage', this.onNewToastMessage);
|
||||||
|
},
|
||||||
|
onNewToastMessage(message) {
|
||||||
this.snackMessages.push({ key: new Date().getTime(), message });
|
this.snackMessages.push({ key: new Date().getTime(), message });
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
this.snackMessages.splice(0, 1);
|
this.snackMessages.splice(0, 1);
|
||||||
}, this.duration);
|
}, this.duration);
|
||||||
});
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -243,25 +243,31 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
bus.$on('scrollToMessage', () => {
|
bus.$on(BUS_EVENTS.SCROLL_TO_MESSAGE, this.onScrollToMessage);
|
||||||
this.$nextTick(() => this.scrollToBottom());
|
bus.$on(BUS_EVENTS.SET_TWEET_REPLY, this.setSelectedTweet);
|
||||||
this.makeMessagesRead();
|
|
||||||
});
|
|
||||||
|
|
||||||
bus.$on(BUS_EVENTS.SET_TWEET_REPLY, selectedTweetId => {
|
|
||||||
this.selectedTweetId = selectedTweetId;
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.addScrollListener();
|
this.addScrollListener();
|
||||||
},
|
},
|
||||||
|
|
||||||
unmounted() {
|
beforeDestroy() {
|
||||||
|
this.removeBusListeners();
|
||||||
this.removeScrollListener();
|
this.removeScrollListener();
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
removeBusListeners() {
|
||||||
|
bus.$off(BUS_EVENTS.SCROLL_TO_MESSAGE, this.onScrollToMessage);
|
||||||
|
bus.$off(BUS_EVENTS.SET_TWEET_REPLY, this.setSelectedTweet);
|
||||||
|
},
|
||||||
|
setSelectedTweet(tweetId) {
|
||||||
|
this.selectedTweetId = tweetId;
|
||||||
|
},
|
||||||
|
onScrollToMessage() {
|
||||||
|
this.$nextTick(() => this.scrollToBottom());
|
||||||
|
this.makeMessagesRead();
|
||||||
|
},
|
||||||
showPopoutReplyBox() {
|
showPopoutReplyBox() {
|
||||||
this.isPopoutReplyBox = !this.isPopoutReplyBox;
|
this.isPopoutReplyBox = !this.isPopoutReplyBox;
|
||||||
},
|
},
|
||||||
|
|
|
@ -93,6 +93,7 @@ import { REPLY_EDITOR_MODES } from 'dashboard/components/widgets/WootWriter/cons
|
||||||
import WootMessageEditor from 'dashboard/components/widgets/WootWriter/Editor';
|
import WootMessageEditor from 'dashboard/components/widgets/WootWriter/Editor';
|
||||||
import { checkFileSizeLimit } from 'shared/helpers/FileHelper';
|
import { checkFileSizeLimit } from 'shared/helpers/FileHelper';
|
||||||
import { MAXIMUM_FILE_UPLOAD_SIZE } from 'shared/constants/messages';
|
import { MAXIMUM_FILE_UPLOAD_SIZE } from 'shared/constants/messages';
|
||||||
|
import { BUS_EVENTS } from 'shared/constants/busEvents';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
isEscape,
|
isEscape,
|
||||||
|
@ -368,7 +369,7 @@ export default {
|
||||||
this.clearMessage();
|
this.clearMessage();
|
||||||
try {
|
try {
|
||||||
await this.$store.dispatch('sendMessage', messagePayload);
|
await this.$store.dispatch('sendMessage', messagePayload);
|
||||||
this.$emit('scrollToMessage');
|
this.$emit(BUS_EVENTS.SCROLL_TO_MESSAGE);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMessage =
|
const errorMessage =
|
||||||
error?.response?.data?.error ||
|
error?.response?.data?.error ||
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
<script>
|
<script>
|
||||||
import Sidebar from '../../components/layout/Sidebar';
|
import Sidebar from '../../components/layout/Sidebar';
|
||||||
import CommandBar from './commands/commandbar.vue';
|
import CommandBar from './commands/commandbar.vue';
|
||||||
|
import { BUS_EVENTS } from 'shared/constants/busEvents';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
@ -50,11 +51,10 @@ export default {
|
||||||
this.$store.dispatch('setCurrentAccountId', this.$route.params.accountId);
|
this.$store.dispatch('setCurrentAccountId', this.$route.params.accountId);
|
||||||
window.addEventListener('resize', this.handleResize);
|
window.addEventListener('resize', this.handleResize);
|
||||||
this.handleResize();
|
this.handleResize();
|
||||||
bus.$on('sidemenu_icon_click', () => {
|
bus.$on(BUS_EVENTS.TOGGLE_SIDEMENU, this.toggleSidebar);
|
||||||
this.isSidebarOpen = !this.isSidebarOpen;
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
|
bus.$off(BUS_EVENTS.TOGGLE_SIDEMENU, this.toggleSidebar);
|
||||||
window.removeEventListener('resize', this.handleResize);
|
window.removeEventListener('resize', this.handleResize);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -65,6 +65,9 @@ export default {
|
||||||
this.isOnDesktop = false;
|
this.isOnDesktop = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
toggleSidebar() {
|
||||||
|
this.isSidebarOpen = !this.isSidebarOpen;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -23,6 +23,7 @@ import ChatList from '../../../components/ChatList';
|
||||||
import ConversationBox from '../../../components/widgets/conversation/ConversationBox';
|
import ConversationBox from '../../../components/widgets/conversation/ConversationBox';
|
||||||
import PopOverSearch from './search/PopOverSearch';
|
import PopOverSearch from './search/PopOverSearch';
|
||||||
import uiSettingsMixin from 'dashboard/mixins/uiSettings';
|
import uiSettingsMixin from 'dashboard/mixins/uiSettings';
|
||||||
|
import { BUS_EVENTS } from 'shared/constants/busEvents';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
@ -108,7 +109,7 @@ export default {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.$store.dispatch('setActiveChat', chat).then(() => {
|
this.$store.dispatch('setActiveChat', chat).then(() => {
|
||||||
bus.$emit('scrollToMessage');
|
bus.$emit(BUS_EVENTS.SCROLL_TO_MESSAGE);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.$store.dispatch('clearSelectedState');
|
this.$store.dispatch('clearSelectedState');
|
||||||
|
|
|
@ -3,4 +3,6 @@ export const BUS_EVENTS = {
|
||||||
SHOW_ALERT: 'SHOW_ALERT',
|
SHOW_ALERT: 'SHOW_ALERT',
|
||||||
START_NEW_CONVERSATION: 'START_NEW_CONVERSATION',
|
START_NEW_CONVERSATION: 'START_NEW_CONVERSATION',
|
||||||
FOCUS_CUSTOM_ATTRIBUTE: 'FOCUS_CUSTOM_ATTRIBUTE',
|
FOCUS_CUSTOM_ATTRIBUTE: 'FOCUS_CUSTOM_ATTRIBUTE',
|
||||||
|
SCROLL_TO_MESSAGE: 'SCROLL_TO_MESSAGE',
|
||||||
|
TOGGLE_SIDEMENU: 'TOGGLE_SIDEMENU',
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue