Skip to content

Commit

Permalink
move push_notify logic to a js library
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
Signed-off-by: npmbuildbot-nextcloud[bot] <npmbuildbot-nextcloud[bot]@users.noreply.github.com>
  • Loading branch information
icewind1991 authored and npmbuildbot-nextcloud[bot] committed Jan 21, 2021
1 parent 9576192 commit e6aee7d
Show file tree
Hide file tree
Showing 6 changed files with 5,811 additions and 57 deletions.
40 changes: 20 additions & 20 deletions js/notifications-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/notifications-main.js.map

Large diffs are not rendered by default.

5,783 changes: 5,783 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@nextcloud/capabilities": "^1.0.2",
"@nextcloud/dialogs": "^3.1.1",
"@nextcloud/event-bus": "^1.2.0",
"@nextcloud/notify_push": "^1.0.0",
"@nextcloud/moment": "^1.1.1",
"@nextcloud/router": "^1.2.0",
"@nextcloud/vue": "^3.3.2",
Expand Down
31 changes: 6 additions & 25 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ import axios from '@nextcloud/axios'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
import { showError } from '@nextcloud/dialogs'
import { imagePath, generateOcsUrl } from '@nextcloud/router'
import { getNotificationsData, setupPush } from './services/notificationsService'
import { getCapabilities } from '@nextcloud/capabilities'
import { getNotificationsData } from './services/notificationsService'
import { listen } from '@nextcloud/notify_push'
export default {
name: 'App',
Expand Down Expand Up @@ -129,14 +129,11 @@ export default {
// Initial call to the notification endpoint
this._fetch()
const capabilities = getCapabilities()
if (capabilities.notify_push) {
this.pushEndpoints = capabilities.notify_push.endpoints
// Because we have push, we only background poll very infrequent
const hasPush = listen('notify_notification', () => {
this._fetch()
})
if (hasPush) {
this.pollIntervalBase = 15 * 60 * 1000
this._setupPush()
}
// Setup the background checker
Expand Down Expand Up @@ -263,22 +260,6 @@ export default {
}
},
async _setupPush() {
if (!this.pushEndpoints) {
return
}
const ws = await setupPush(this.pushEndpoints)
ws.onmessage = message => {
if (message.data === 'notify_notification') {
this._fetch()
}
}
ws.onclose = () => {
this._setupPush()
}
},
_backgroundFetch() {
this.backgroundFetching = true
this._fetch()
Expand Down
11 changes: 0 additions & 11 deletions src/services/notificationsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,6 @@ const refreshData = async(lastETag) => {
}
}

const setupPush = async(endpoints) => {
const response = await axios.post(endpoints.pre_auth)
const ws = new WebSocket(endpoints.websocket)
ws.onopen = () => {
ws.send('dummy')
ws.send(response.data)
}
return ws
}

export {
getNotificationsData,
setupPush,
}

0 comments on commit e6aee7d

Please sign in to comment.