Activitypub_pending_follow_requests.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * GNU social - a federating social network
  4. *
  5. * ActivityPubPlugin implementation for GNU Social
  6. *
  7. * LICENCE: This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. * @category Plugin
  21. * @package GNUsocial
  22. * @author Diogo Cordeiro <diogo@fc.up.pt>
  23. * @copyright 2018 Free Software Foundation http://fsf.org
  24. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  25. * @link https://www.gnu.org/software/social/
  26. */
  27. if (!defined('GNUSOCIAL')) {
  28. exit(1);
  29. }
  30. /**
  31. * ActivityPub's Pending follow requests
  32. *
  33. * @category Plugin
  34. * @package GNUsocial
  35. * @author Diogo Cordeiro <diogo@fc.up.pt>
  36. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  37. * @link http://www.gnu.org/software/social/
  38. */
  39. class Activitypub_pending_follow_requests extends Managed_DataObject
  40. {
  41. public $__table = 'Activitypub_pending_follow_requests';
  42. public $local_profile_id;
  43. public $remote_profile_id;
  44. private $_reldb = null;
  45. /**
  46. * Return table definition for Schema setup and DB_DataObject usage.
  47. *
  48. * @author Diogo Cordeiro <diogo@fc.up.pt>
  49. * @return array array of column definitions
  50. */
  51. public static function schemaDef()
  52. {
  53. return [
  54. 'fields' => [
  55. 'local_profile_id' => ['type' => 'integer', 'not null' => true],
  56. 'remote_profile_id' => ['type' => 'integer', 'not null' => true],
  57. 'relation_id' => ['type' => 'serial', 'not null' => true],
  58. ],
  59. 'primary key' => ['relation_id'],
  60. 'unique keys' => [
  61. 'Activitypub_pending_follow_requests_relation_id_key' => ['relation_id'],
  62. ],
  63. 'foreign keys' => [
  64. 'Activitypub_pending_follow_requests_local_profile_id_fkey' => ['profile', ['local_profile_id' => 'id']],
  65. 'Activitypub_pending_follow_requests_remote_profile_id_fkey' => ['profile', ['remote_profile_id' => 'id']],
  66. ],
  67. ];
  68. }
  69. public function __construct($actor, $remote_actor)
  70. {
  71. $this->local_profile_id = $actor;
  72. $this->remote_profile_id = $remote_actor;
  73. }
  74. /**
  75. * Add Follow request to table.
  76. *
  77. * @author Diogo Cordeiro <diogo@fc.up.pt>
  78. * @param int32 $actor actor id
  79. * @param int32 $remote_actor remote actor id
  80. * @return boolean true if added, false otherwise
  81. */
  82. public function add()
  83. {
  84. return !$this->exists() && $this->insert();
  85. }
  86. /**
  87. * Check if a Follow request is pending.
  88. *
  89. * @author Diogo Cordeiro <diogo@fc.up.pt>
  90. * @return boolean true if is pending, false otherwise
  91. */
  92. public function exists()
  93. {
  94. $this->_reldb = clone ($this);
  95. if ($this->_reldb->find() > 0) {
  96. $this->_reldb->fetch();
  97. return true;
  98. }
  99. return false;
  100. }
  101. /**
  102. * Remove a request from the pending table.
  103. *
  104. * @author Diogo Cordeiro <diogo@fc.up.pt>
  105. * @return boolean true if removed, false otherwise
  106. */
  107. public function remove()
  108. {
  109. return $this->exists() && $this->_reldb->delete();
  110. }
  111. }