apiqvittermarkallnotificationsasseen.php 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3. · ·
  4. · Say hello to the API ·
  5. · (you will also get headers with e.g. unread notification count....) ·
  6. · ·
  7. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8. · ·
  9. · ·
  10. · Q V I T T E R ·
  11. · ·
  12. · https://git.gnu.io/h2p/Qvitter ·
  13. · ·
  14. · ·
  15. · <o) ·
  16. · /_//// ·
  17. · (____/ ·
  18. · (o< ·
  19. · o> \\\\_\ ·
  20. · \\) \____) ·
  21. · ·
  22. · ·
  23. · ·
  24. · Qvitter is free software: you can redistribute it and / or modify it ·
  25. · under the terms of the GNU Affero General Public License as published by ·
  26. · the Free Software Foundation, either version three of the License or (at ·
  27. · your option) any later version. ·
  28. · ·
  29. · Qvitter is distributed in hope that it will be useful but WITHOUT ANY ·
  30. · WARRANTY; without even the implied warranty of MERCHANTABILTY or FITNESS ·
  31. · FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for ·
  32. · more details. ·
  33. · ·
  34. · You should have received a copy of the GNU Affero General Public License ·
  35. · along with Qvitter. If not, see <http://www.gnu.org/licenses/>. ·
  36. · ·
  37. · Contact h@nnesmannerhe.im if you have any questions. ·
  38. · ·
  39. · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
  40. if (!defined('GNUSOCIAL')) { exit(1); }
  41. class ApiQvitterMarkAllNotificationsAsSeenAction extends ApiAuthAction
  42. {
  43. /**
  44. * Take arguments for running
  45. *
  46. * @param array $args $_REQUEST args
  47. *
  48. * @return boolean success flag
  49. */
  50. protected function prepare(array $args=array())
  51. {
  52. parent::prepare($args);
  53. return true;
  54. }
  55. /**
  56. * Handle the request
  57. *
  58. * @param array $args $_REQUEST data (unused)
  59. *
  60. * @return void
  61. */
  62. protected function handle()
  63. {
  64. parent::handle();
  65. $n = new QvitterNotification();
  66. $n->selectAdd();
  67. $n->selectAdd('id');
  68. $n->whereAdd(sprintf('qvitternotification.to_profile_id = "%s"', $n->escape($this->auth_user->id)));
  69. $ids = $n->fetchAll('id');
  70. $notifications = QvitterNotification::pivotGet('id', $ids);
  71. $notifications = new ArrayWrapper($notifications);
  72. $notifications = $notifications->fetchAll();
  73. foreach($notifications as $notification) {
  74. if($notification->is_seen == 0) {
  75. $orig = clone($notification);
  76. $notification->is_seen = 1;
  77. $notification->update($orig);
  78. }
  79. }
  80. $this->initDocument('json');
  81. $this->showJsonObjects(true);
  82. $this->endDocument('json');
  83. }
  84. }