diff options
author | marco <marcoambrosini@pm.me> | 2021-06-16 12:49:48 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-16 12:49:48 +0300 |
commit | a043755863d98073a07e550db2fd0a0006605206 (patch) | |
tree | 68fd4ec1e75e7c269fe0ef21bdb0dca252ce9551 | |
parent | 4d5fcf72f3042e16c60d262a373d9f9500f62a09 (diff) | |
parent | 14a1f74f382bbabf9c81f85cf47859d301a960cc (diff) |
Merge pull request #5783 from nextcloud/bugfix/noid/stop-dashboard-polling-when-noone-is-watching
Stop polling rooms in the dashboard when the document is hidden
-rw-r--r-- | src/views/Dashboard.vue | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/views/Dashboard.vue b/src/views/Dashboard.vue index e5776bdf8..59411038c 100644 --- a/src/views/Dashboard.vue +++ b/src/views/Dashboard.vue @@ -84,6 +84,7 @@ export default { roomOptions: [], hasImportantConversations: false, loading: true, + windowVisibility: true, } }, @@ -145,14 +146,31 @@ export default { }, }, + watch: { + windowVisibility(newValue) { + if (newValue) { + this.fetchRooms() + } + }, + }, + + beforeDestroy() { + document.removeEventListener('visibilitychange', this.changeWindowVisibility) + }, + beforeMount() { this.fetchRooms() - // FIXME: reduce interval if user not active - setInterval(() => this.fetchRooms(), ROOM_POLLING_INTERVAL * 1000) + setInterval(this.fetchRooms, ROOM_POLLING_INTERVAL * 1000) + document.addEventListener('visibilitychange', this.changeWindowVisibility) }, methods: { fetchRooms() { + if (!this.windowVisibility) { + // Dashboard is not visible, so don't update the room list + return + } + axios.get(generateOcsUrl('apps/spreed/api/v4/room')).then((response) => { const rooms = response.data.ocs.data const importantRooms = rooms.filter((conversation) => { @@ -174,6 +192,10 @@ export default { }) }, + changeWindowVisibility() { + this.windowVisibility = !document.hidden + }, + clickStartNew() { window.location = generateUrl('/apps/spreed') }, |