Activitypub_pending_follow_requests.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. /**
  17. * ActivityPub implementation for GNU social
  18. *
  19. * @package GNUsocial
  20. * @author Diogo Cordeiro <diogo@fc.up.pt>
  21. * @copyright 2018-2019 Free Software Foundation, Inc http://www.fsf.org
  22. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  23. * @link http://www.gnu.org/software/social/
  24. */
  25. defined('GNUSOCIAL') || die();
  26. /**
  27. * ActivityPub's Pending follow requests
  28. *
  29. * @category Plugin
  30. * @package GNUsocial
  31. * @author Diogo Cordeiro <diogo@fc.up.pt>
  32. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  33. */
  34. class Activitypub_pending_follow_requests extends Managed_DataObject
  35. {
  36. public $__table = 'activitypub_pending_follow_requests';
  37. public $local_profile_id;
  38. public $remote_profile_id;
  39. private $_reldb = null;
  40. /**
  41. * Return table definition for Schema setup and DB_DataObject usage.
  42. *
  43. * @author Diogo Cordeiro <diogo@fc.up.pt>
  44. * @return array array of column definitions
  45. */
  46. public static function schemaDef()
  47. {
  48. return [
  49. 'fields' => [
  50. 'local_profile_id' => ['type' => 'int', 'not null' => true],
  51. 'remote_profile_id' => ['type' => 'int', 'not null' => true],
  52. 'relation_id' => ['type' => 'serial', 'not null' => true],
  53. ],
  54. 'primary key' => ['relation_id'],
  55. 'foreign keys' => [
  56. 'activitypub_pending_follow_requests_local_profile_id_fkey' => ['profile', ['local_profile_id' => 'id']],
  57. 'activitypub_pending_follow_requests_remote_profile_id_fkey' => ['profile', ['remote_profile_id' => 'id']],
  58. ],
  59. 'indexes' => [
  60. 'activitypub_pending_follow_requests_local_profile_id_idx' => ['local_profile_id'],
  61. 'activitypub_pending_follow_requests_remote_profile_id_idx' => ['remote_profile_id'],
  62. ],
  63. ];
  64. }
  65. public function __construct($actor, $remote_actor)
  66. {
  67. $this->local_profile_id = $actor;
  68. $this->remote_profile_id = $remote_actor;
  69. }
  70. /**
  71. * Add Follow request to table.
  72. *
  73. * @return boolean true if added, false otherwise
  74. * @author Diogo Cordeiro <diogo@fc.up.pt>
  75. */
  76. public function add()
  77. {
  78. return !$this->exists() && $this->insert();
  79. }
  80. /**
  81. * Check if a Follow request is pending.
  82. *
  83. * @author Diogo Cordeiro <diogo@fc.up.pt>
  84. * @return boolean true if is pending, false otherwise
  85. */
  86. public function exists()
  87. {
  88. $this->_reldb = clone($this);
  89. if ($this->_reldb->find() > 0) {
  90. $this->_reldb->fetch();
  91. return true;
  92. }
  93. return false;
  94. }
  95. /**
  96. * Remove a request from the pending table.
  97. *
  98. * @author Diogo Cordeiro <diogo@fc.up.pt>
  99. * @return boolean true if removed, false otherwise
  100. */
  101. public function remove()
  102. {
  103. return $this->exists() && $this->_reldb->delete();
  104. }
  105. }