Skip to content

Commit a6cd273

Browse files
committed
fix: move creation of browser notifications to the root App
Signed-off-by: Maksim Sukharev <[email protected]>
1 parent 5c01518 commit a6cd273

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

src/Components/Notification.vue

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ import moment from '@nextcloud/moment'
9393
import DefaultParameter from './Parameters/DefaultParameter.vue'
9494
import File from './Parameters/File.vue'
9595
import User from './Parameters/User.vue'
96-
import { emit } from '@nextcloud/event-bus'
97-
import { createWebNotification } from '../services/webNotificationsService.js'
9896
9997
export default {
10098
name: 'Notification',
@@ -250,26 +248,6 @@ export default {
250248
251249
mounted() {
252250
this._$el = $(this.$el)
253-
254-
// Parents: TransitionGroup > Transition > HeaderMenu
255-
if (typeof this.$parent.$parent.$parent.showBrowserNotifications === 'undefined') {
256-
console.error('Failed to read showBrowserNotifications property from App component')
257-
}
258-
259-
if (this.$parent.$parent.$parent.backgroundFetching) {
260-
// Can not rely on showBrowserNotifications because each tab should
261-
// be able to utilize the data from the notification in events.
262-
const event = {
263-
notification: this.$props,
264-
}
265-
266-
emit('notifications:notification:received', event)
267-
}
268-
269-
if (this.$parent.$parent.$parent.showBrowserNotifications
270-
&& this.$parent.$parent.$parent.webNotificationsThresholdId < this.notificationId) {
271-
createWebNotification(this)
272-
}
273251
},
274252
275253
methods: {

src/NotificationsApp.vue

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
103103
import Close from 'vue-material-design-icons/Close.vue'
104104
import axios from '@nextcloud/axios'
105105
import { getCurrentUser } from '@nextcloud/auth'
106-
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
106+
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
107107
import { showError } from '@nextcloud/dialogs'
108108
import { loadState } from '@nextcloud/initial-state'
109109
import {
@@ -117,6 +117,7 @@ import Message from 'vue-material-design-icons/Message.vue'
117117
import NcEmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js'
118118
import { getCapabilities } from '@nextcloud/capabilities'
119119
import NcHeaderMenu from '@nextcloud/vue/dist/Components/NcHeaderMenu.js'
120+
import { createWebNotification } from './services/webNotificationsService.js'
120121
121122
export default {
122123
name: 'NotificationsApp',
@@ -398,6 +399,7 @@ export default {
398399
this.lastETag = response.headers.etag
399400
this.lastTabId = response.tabId
400401
this.notifications = response.data
402+
this.processWebNotifications(response.data)
401403
console.debug('Got notification data, restoring default polling interval.')
402404
this._setPollingInterval(this.pollIntervalBase)
403405
this._updateDocTitleOnNewNotifications(this.notifications)
@@ -514,6 +516,21 @@ export default {
514516
this.webNotificationsGranted = permissions === 'granted'
515517
})
516518
},
519+
520+
processWebNotifications(notifications) {
521+
notifications.forEach(notification => {
522+
if (this.backgroundFetching) {
523+
// Can not rely on showBrowserNotifications because each tab should
524+
// be able to utilize the data from the notification in events.
525+
const event = { notification }
526+
emit('notifications:notification:received', event)
527+
}
528+
529+
if (this.showBrowserNotifications && this.webNotificationsThresholdId < notification.notificationId) {
530+
createWebNotification(notification)
531+
}
532+
})
533+
},
517534
},
518535
}
519536
</script>

0 commit comments

Comments
 (0)