Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak in message list #4139

Merged
merged 2 commits into from
Sep 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/components/MessagesList/MessagesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import MessagesGroup from './MessagesGroup/MessagesGroup'
import { fetchMessages, lookForNewMessages } from '../../services/messagesService'
import CancelableRequest from '../../utils/cancelableRequest'
import Axios from '@nextcloud/axios'
import { subscribe } from '@nextcloud/event-bus'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
import isInLobby from '../../mixins/isInLobby'
import debounce from 'debounce'
import { EventBus } from '../../services/EventBus'
Expand Down Expand Up @@ -233,18 +233,15 @@ export default {
this.scrollToBottom()
EventBus.$on('scrollChatToBottom', this.handleScrollChatToBottomEvent)

subscribe('networkOffline', () => {
console.debug('Canceling message request as we are offline')
this.cancelLookForNewMessages()
})
subscribe('networkOnline', () => {
console.debug('Restarting polling of new chat messages')
this.getNewMessages()
})
subscribe('networkOffline', this.handleNetworkOffline)
subscribe('networkOnline', this.handleNetworkOnline)
},
beforeDestroy() {
EventBus.$off('scrollChatToBottom', this.handleScrollChatToBottomEvent)
this.cancelLookForNewMessages()

unsubscribe('networkOffline', this.handleNetworkOffline)
unsubscribe('networkOnline', this.handleNetworkOnline)
},

methods: {
Expand Down Expand Up @@ -595,6 +592,16 @@ export default {
getFirstKnownMessageId() {
return this.messagesList[0].id.toString()
},

handleNetworkOffline() {
console.debug('Canceling message request as we are offline')
this.cancelLookForNewMessages()
},

handleNetworkOnline() {
console.debug('Restarting polling of new chat messages')
this.getNewMessages()
},
},
}
</script>
Expand Down