Users.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace OCA\Files_Sharing\Activity\Providers;
  24. use OCP\Activity\IEvent;
  25. class Users extends Base {
  26. const SUBJECT_SHARED_USER_SELF = 'shared_user_self';
  27. const SUBJECT_RESHARED_USER_BY = 'reshared_user_by';
  28. const SUBJECT_UNSHARED_USER_SELF = 'unshared_user_self';
  29. const SUBJECT_UNSHARED_USER_BY = 'unshared_user_by';
  30. const SUBJECT_SHARED_WITH_BY = 'shared_with_by';
  31. const SUBJECT_UNSHARED_BY = 'unshared_by';
  32. /**
  33. * @param IEvent $event
  34. * @return IEvent
  35. * @throws \InvalidArgumentException
  36. * @since 11.0.0
  37. */
  38. public function parseShortVersion(IEvent $event) {
  39. $parsedParameters = $this->getParsedParameters($event);
  40. if ($event->getSubject() === self::SUBJECT_SHARED_USER_SELF) {
  41. $subject = $this->l->t('Shared with {user}');
  42. } else if ($event->getSubject() === self::SUBJECT_UNSHARED_USER_SELF) {
  43. $subject = $this->l->t('Removed share for {user}');
  44. } else if ($event->getSubject() === self::SUBJECT_RESHARED_USER_BY) {
  45. $subject = $this->l->t('{actor} shared with {user}');
  46. } else if ($event->getSubject() === self::SUBJECT_UNSHARED_USER_BY) {
  47. $subject = $this->l->t('{actor} removed share for {user}');
  48. } else if ($event->getSubject() === self::SUBJECT_SHARED_WITH_BY) {
  49. $subject = $this->l->t('Shared by {actor}');
  50. } else if ($event->getSubject() === self::SUBJECT_UNSHARED_BY) {
  51. $subject = $this->l->t('{actor} removed share');
  52. } else {
  53. throw new \InvalidArgumentException();
  54. }
  55. if ($this->activityManager->getRequirePNG()) {
  56. $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
  57. } else {
  58. $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
  59. }
  60. $this->setSubjects($event, $subject, $parsedParameters);
  61. return $event;
  62. }
  63. /**
  64. * @param IEvent $event
  65. * @return IEvent
  66. * @throws \InvalidArgumentException
  67. * @since 11.0.0
  68. */
  69. public function parseLongVersion(IEvent $event) {
  70. $parsedParameters = $this->getParsedParameters($event);
  71. if ($event->getSubject() === self::SUBJECT_SHARED_USER_SELF) {
  72. $subject = $this->l->t('You shared {file} with {user}');
  73. } else if ($event->getSubject() === self::SUBJECT_UNSHARED_USER_SELF) {
  74. $subject = $this->l->t('You removed {user} from {file}');
  75. } else if ($event->getSubject() === self::SUBJECT_RESHARED_USER_BY) {
  76. $subject = $this->l->t('{actor} shared {file} with {user}');
  77. } else if ($event->getSubject() === self::SUBJECT_UNSHARED_USER_BY) {
  78. $subject = $this->l->t('{actor} removed {user} from {file}');
  79. } else if ($event->getSubject() === self::SUBJECT_SHARED_WITH_BY) {
  80. $subject = $this->l->t('{actor} shared {file} with you');
  81. } else if ($event->getSubject() === self::SUBJECT_UNSHARED_BY) {
  82. $subject = $this->l->t('{actor} removed you from the share named {file}');
  83. } else {
  84. throw new \InvalidArgumentException();
  85. }
  86. if ($this->activityManager->getRequirePNG()) {
  87. $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
  88. } else {
  89. $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
  90. }
  91. $this->setSubjects($event, $subject, $parsedParameters);
  92. return $event;
  93. }
  94. protected function getParsedParameters(IEvent $event) {
  95. $subject = $event->getSubject();
  96. $parameters = $event->getSubjectParameters();
  97. switch ($subject) {
  98. case self::SUBJECT_SHARED_USER_SELF:
  99. case self::SUBJECT_UNSHARED_USER_SELF:
  100. return [
  101. 'file' => $this->getFile($parameters[0], $event),
  102. 'user' => $this->getUser($parameters[1]),
  103. ];
  104. case self::SUBJECT_SHARED_WITH_BY:
  105. case self::SUBJECT_UNSHARED_BY:
  106. return [
  107. 'file' => $this->getFile($parameters[0], $event),
  108. 'actor' => $this->getUser($parameters[1]),
  109. ];
  110. case self::SUBJECT_RESHARED_USER_BY:
  111. case self::SUBJECT_UNSHARED_USER_BY:
  112. return [
  113. 'file' => $this->getFile($parameters[0], $event),
  114. 'user' => $this->getUser($parameters[2]),
  115. 'actor' => $this->getUser($parameters[1]),
  116. ];
  117. }
  118. return [];
  119. }
  120. }