|
175 | 175 | self._onNewNotification(n); |
176 | 176 | } |
177 | 177 | }); |
178 | | - // TODO check if any removed from JSON |
| 178 | + |
179 | 179 | for (var n in self.getNotifications()) { |
180 | 180 | if (inJson.indexOf(self.getNotifications()[n].getId()) === -1) { |
181 | 181 | // Not in JSON, remove from UI |
|
229 | 229 | OCA.Notifications.notifications[notification.getId()] = notification; |
230 | 230 | // Add to the UI |
231 | 231 | OCA.Notifications.addToUI(notification); |
232 | | - // TODO make a noise? Anything else? |
| 232 | + |
| 233 | + // Trigger browsers web notification |
| 234 | + // https://github.com/owncloud/notifications/issues/1 |
| 235 | + if ("Notification" in window) { |
| 236 | + if (Notification.permission === "granted") { |
| 237 | + // If it's okay let's create a notification |
| 238 | + OCA.Notifications.createWebNotification(notification); |
| 239 | + } |
| 240 | + |
| 241 | + // Otherwise, we need to ask the user for permission |
| 242 | + else if (Notification.permission !== 'denied') { |
| 243 | + Notification.requestPermission(function (permission) { |
| 244 | + // If the user accepts, let's create a notification |
| 245 | + if (permission === "granted") { |
| 246 | + OCA.Notifications.createWebNotification(notification); |
| 247 | + } |
| 248 | + }); |
| 249 | + } |
| 250 | + } |
| 251 | + }, |
| 252 | + |
| 253 | + /** |
| 254 | + * Create a browser notification |
| 255 | + * |
| 256 | + * @see https://developer.mozilla.org/en/docs/Web/API/notification |
| 257 | + * @param {OCA.Notifications.Notification} notification |
| 258 | + */ |
| 259 | + createWebNotification: function (notification) { |
| 260 | + var n = new Notification(notification.getSubject(), { |
| 261 | + title: notification.getSubject(), |
| 262 | + lang: OC.getLocale(), |
| 263 | + body: notification.getMessage(), |
| 264 | + tag: notification.getId() |
| 265 | + }); |
| 266 | + setTimeout(n.close.bind(n), 5000); |
233 | 267 | }, |
234 | 268 |
|
235 | 269 | _shutDownNotifications: function() { |
|
0 commit comments