bookmarksnoticestream.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. defined('GNUSOCIAL') || die();
  17. class RawBookmarksNoticeStream extends NoticeStream
  18. {
  19. protected $user_id;
  20. protected $own;
  21. public function __construct($user_id, $own)
  22. {
  23. $this->user_id = $user_id;
  24. $this->own = $own;
  25. }
  26. public function getNoticeIds($offset, $limit, $since_id, $max_id)
  27. {
  28. $notice = new Notice();
  29. $notice->selectAdd();
  30. $notice->selectAdd('notice.*');
  31. $notice->joinAdd(['uri', 'bookmark:uri']);
  32. $notice->whereAdd(sprintf('bookmark.profile_id = %d', $this->user_id));
  33. $notice->whereAdd('notice.is_local <> ' . Notice::GATEWAY);
  34. Notice::addWhereSinceId($notice, $since_id, 'notice.id', 'bookmark.created');
  35. Notice::addWhereMaxId($notice, $max_id, 'notice.id', 'bookmark.created');
  36. // NOTE: we sort by bookmark time, not by notice time!
  37. $notice->orderBy('bookmark.created DESC');
  38. if (!is_null($offset)) {
  39. $notice->limit($offset, $limit);
  40. }
  41. $ids = [];
  42. if ($notice->find()) {
  43. while ($notice->fetch()) {
  44. $ids[] = $notice->id;
  45. }
  46. }
  47. $notice->free();
  48. unset($notice);
  49. return $ids;
  50. }
  51. }
  52. /**
  53. * Notice stream for bookmarks
  54. *
  55. * @category Stream
  56. * @package StatusNet
  57. * @author Stephane Berube <chimo@chromic.org>
  58. * @copyright 2011 StatusNet, Inc.
  59. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  60. * @link http://status.net/
  61. */
  62. class BookmarksNoticeStream extends ScopingNoticeStream
  63. {
  64. public function __construct($user_id, $own, Profile $scoped = null)
  65. {
  66. $stream = new RawBookmarksNoticeStream($user_id, $own);
  67. if ($own) {
  68. $key = 'bookmark:ids_by_user_own:'.$user_id;
  69. } else {
  70. $key = 'bookmark:ids_by_user:'.$user_id;
  71. }
  72. parent::__construct(new CachingNoticeStream($stream, $key), $scoped);
  73. }
  74. }