UserNotificationPrefs.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. declare(strict_types = 1);
  3. // {{{ License
  4. // This file is part of GNU social - https://www.gnu.org/software/social
  5. //
  6. // GNU social is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // GNU social is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  18. // }}}
  19. namespace Component\Notification\Entity;
  20. use App\Core\Entity;
  21. use DateTimeInterface;
  22. /**
  23. * Entity for user notification preferences
  24. *
  25. * @category DB
  26. * @package GNUsocial
  27. *
  28. * @author Hugo Sales <hugo@hsal.es>
  29. * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org
  30. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  31. */
  32. class UserNotificationPrefs extends Entity
  33. {
  34. // {{{ Autocode
  35. // @codeCoverageIgnoreStart
  36. private int $user_id;
  37. private string $transport;
  38. private ?int $target_actor_id = null;
  39. private bool $activity_by_subscribed = true;
  40. private bool $mention = true;
  41. private bool $reply = true;
  42. private bool $subscription = true;
  43. private bool $favorite = true;
  44. private bool $nudge = false;
  45. private bool $dm = true;
  46. private bool $post_on_status_change = false;
  47. private ?bool $enable_posting = true;
  48. private DateTimeInterface $created;
  49. private DateTimeInterface $modified;
  50. public function setUserId(int $user_id): self
  51. {
  52. $this->user_id = $user_id;
  53. return $this;
  54. }
  55. public function getUserId(): int
  56. {
  57. return $this->user_id;
  58. }
  59. public function setTransport(string $transport): self
  60. {
  61. $this->transport = mb_substr($transport, 0, 191);
  62. return $this;
  63. }
  64. public function getTransport(): string
  65. {
  66. return $this->transport;
  67. }
  68. public function setTargetActorId(?int $target_actor_id): self
  69. {
  70. $this->target_actor_id = $target_actor_id;
  71. return $this;
  72. }
  73. public function getTargetActorId(): ?int
  74. {
  75. return $this->target_actor_id;
  76. }
  77. public function setActivityBySubscribed(bool $activity_by_subscribed): self
  78. {
  79. $this->activity_by_subscribed = $activity_by_subscribed;
  80. return $this;
  81. }
  82. public function getActivityBySubscribed(): bool
  83. {
  84. return $this->activity_by_subscribed;
  85. }
  86. public function setMention(bool $mention): self
  87. {
  88. $this->mention = $mention;
  89. return $this;
  90. }
  91. public function getMention(): bool
  92. {
  93. return $this->mention;
  94. }
  95. public function setReply(bool $reply): self
  96. {
  97. $this->reply = $reply;
  98. return $this;
  99. }
  100. public function getReply(): bool
  101. {
  102. return $this->reply;
  103. }
  104. public function setSubscription(bool $subscription): self
  105. {
  106. $this->subscription = $subscription;
  107. return $this;
  108. }
  109. public function getSubscription(): bool
  110. {
  111. return $this->subscription;
  112. }
  113. public function setFavorite(bool $favorite): self
  114. {
  115. $this->favorite = $favorite;
  116. return $this;
  117. }
  118. public function getFavorite(): bool
  119. {
  120. return $this->favorite;
  121. }
  122. public function setNudge(bool $nudge): self
  123. {
  124. $this->nudge = $nudge;
  125. return $this;
  126. }
  127. public function getNudge(): bool
  128. {
  129. return $this->nudge;
  130. }
  131. public function setDm(bool $dm): self
  132. {
  133. $this->dm = $dm;
  134. return $this;
  135. }
  136. public function getDm(): bool
  137. {
  138. return $this->dm;
  139. }
  140. public function setPostOnStatusChange(bool $post_on_status_change): self
  141. {
  142. $this->post_on_status_change = $post_on_status_change;
  143. return $this;
  144. }
  145. public function getPostOnStatusChange(): bool
  146. {
  147. return $this->post_on_status_change;
  148. }
  149. public function setEnablePosting(?bool $enable_posting): self
  150. {
  151. $this->enable_posting = $enable_posting;
  152. return $this;
  153. }
  154. public function getEnablePosting(): ?bool
  155. {
  156. return $this->enable_posting;
  157. }
  158. public function setCreated(DateTimeInterface $created): self
  159. {
  160. $this->created = $created;
  161. return $this;
  162. }
  163. public function getCreated(): DateTimeInterface
  164. {
  165. return $this->created;
  166. }
  167. public function setModified(DateTimeInterface $modified): self
  168. {
  169. $this->modified = $modified;
  170. return $this;
  171. }
  172. public function getModified(): DateTimeInterface
  173. {
  174. return $this->modified;
  175. }
  176. // @codeCoverageIgnoreEnd
  177. // }}} Autocode
  178. public static function schemaDef(): array
  179. {
  180. return [
  181. 'name' => 'user_notification_prefs',
  182. 'fields' => [
  183. 'user_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'LocalUser.id', 'multiplicity' => 'one to one', 'not null' => true],
  184. 'transport' => ['type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'transport (ex email. xmpp, aim)'],
  185. 'target_actor_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to one', 'default' => null, 'description' => 'If not null, settings are specific only to a given actors'],
  186. 'activity_by_subscribed' => ['type' => 'bool', 'not null' => true, 'default' => true, 'description' => 'Notify when a new activity by someone we subscribe is made'],
  187. 'mention' => ['type' => 'bool', 'not null' => true, 'default' => true, 'description' => 'Notify when mentioned by someone we do not subscribe'],
  188. 'reply' => ['type' => 'bool', 'not null' => true, 'default' => true, 'description' => 'Notify when someone replies to a notice made by us'],
  189. 'subscription' => ['type' => 'bool', 'not null' => true, 'default' => true, 'description' => 'Notify someone subscribes us'],
  190. 'favorite' => ['type' => 'bool', 'not null' => true, 'default' => true, 'description' => 'Notify someone favorites a notice by us'],
  191. 'nudge' => ['type' => 'bool', 'not null' => true, 'default' => false, 'description' => 'Notify someone nudges us'],
  192. 'dm' => ['type' => 'bool', 'not null' => true, 'default' => true, 'description' => 'Notify someone sends us a direct message'],
  193. 'post_on_status_change' => ['type' => 'bool', 'not null' => true, 'default' => false, 'description' => 'Post a notice when our status in service changes'],
  194. 'enable_posting' => ['type' => 'bool', 'default' => true, 'description' => 'Enable posting from this service'],
  195. 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
  196. 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
  197. ],
  198. 'primary key' => ['user_id', 'transport'],
  199. 'indexes' => [
  200. 'user_notification_prefs_user_target_actor_idx' => ['user_id', 'target_actor_id'],
  201. ],
  202. ];
  203. }
  204. }