NotificationActions.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. Copyright (C) 2017 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. // @flow
  15. import alt from '../alt'
  16. import NotificationSource from '../sources/NotificationSource'
  17. class NotificationActions {
  18. notify(message, level, options) {
  19. if (options && options.persist) {
  20. NotificationSource.notify(message, level, options).then(
  21. notification => { this.notifySuccess(notification) },
  22. response => { this.notifyFailed(response) }
  23. )
  24. }
  25. return { message, level, ...options }
  26. }
  27. notifySuccess(notification) {
  28. return notification
  29. }
  30. notifyFailed(response) {
  31. return response || true
  32. }
  33. loadNotifications() {
  34. NotificationSource.loadNotifications().then(
  35. notifications => { this.loadNotificationsSuccess(notifications) },
  36. response => { this.loadNotificationsFailed(response) }
  37. )
  38. return true
  39. }
  40. loadNotificationsSuccess(notifications) {
  41. return notifications
  42. }
  43. loadNotificationsFailed(response) {
  44. return response || true
  45. }
  46. clearNotifications() {
  47. NotificationSource.clearNotifications().then(
  48. () => { this.clearNotificationsSuccess() },
  49. response => { this.clearNotificationsFailed(response) }
  50. )
  51. return true
  52. }
  53. clearNotificationsSuccess() {
  54. return true
  55. }
  56. clearNotificationsFailed(response) {
  57. return response || true
  58. }
  59. }
  60. export default alt.createActions(NotificationActions)