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

move push_notify logic to a js library #837

Merged
merged 1 commit into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
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
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,
}