outbox.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. * GNUsocial implementation of Direct Messages
  18. *
  19. * @package GNUsocial
  20. * @author Mikael Nordfeldth <mmn@hethane.se>
  21. * @author Bruno Casteleiro <brunoccast@fc.up.pt>
  22. * @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
  23. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  24. */
  25. defined('GNUSOCIAL') || die();
  26. /**
  27. * Action handler for the outbox
  28. *
  29. * @category Plugin
  30. * @package GNUsocial
  31. * @author Evan Prodromou <evan@status.net>
  32. * @author Bruno Casteleiro <brunoccast@fc.up.pt>
  33. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  34. */
  35. class OutboxAction extends MailboxAction
  36. {
  37. /**
  38. * Title of the page
  39. *
  40. * @return string page title
  41. */
  42. function title() : string
  43. {
  44. if ($this->page > 1) {
  45. // TRANS: Title for outbox for any but the fist page.
  46. // TRANS: %1$s is the user nickname, %2$d is the page number.
  47. return sprintf(_m('Outbox for %1$s - page %2$d'),
  48. $this->user->getNickname(), $page);
  49. } else {
  50. // TRANS: Title for first page of outbox.
  51. return sprintf(_m('Outbox for %s'), $this->user->getNickname());
  52. }
  53. }
  54. /**
  55. * Retrieve the messages for this user and this page.
  56. *
  57. * @return Notice data object with stream for messages
  58. */
  59. function getMessages()
  60. {
  61. return MessageModel::outboxMessages($this->user, $this->page);
  62. }
  63. /**
  64. * Retrieve outbox MessageList widget.
  65. */
  66. function getMessageList($message)
  67. {
  68. return new OutboxMessageList($this, $message);
  69. }
  70. /**
  71. * Instructions for using this page.
  72. *
  73. * @return string localised instructions for using the page
  74. */
  75. function getInstructions() : string
  76. {
  77. // TRANS: Instructions for outbox.
  78. return _m('This is your outbox, which lists private messages you have sent.');
  79. }
  80. }
  81. /**
  82. * Outbox MessageList widget
  83. *
  84. * @category Plugin
  85. * @package GNUsocial
  86. * @author Evan Prodromou <evan@status.net>
  87. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  88. */
  89. class OutboxMessageList extends MessageList
  90. {
  91. function newItem($message)
  92. {
  93. return new OutboxMessageListItem($this->out, $message);
  94. }
  95. }
  96. /**
  97. * Outbox MessageListItem widget
  98. *
  99. * @category Plugin
  100. * @package GNUsocial
  101. * @author Evan Prodromou <evan@status.net>
  102. * @author Bruno Casteleiro <brunoccast@fc.up.pt>
  103. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  104. */
  105. class OutboxMessageListItem extends MessageListItem
  106. {
  107. /**
  108. * Returns the profile we want to show with the message
  109. *
  110. * Note that the plugin now handles sending for multiple profiles,
  111. * but since the UI isn't changed yet, we still retrieve a single
  112. * profile from this function (or null, if for blocking reasons
  113. * there are no attentions stored).
  114. *
  115. * @return Profile|null
  116. */
  117. function getMessageProfile() : ?Profile
  118. {
  119. $attentions = $this->message->getAttentionProfiles();
  120. return empty($attentions) ? null : $attentions[0];
  121. }
  122. }