You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.5 KiB

  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2018, Joas Schilling <coding@schilljs.com>
  5. *
  6. * @author Joas Schilling <coding@schilljs.com>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Talk;
  25. use OCA\Talk\Chat\ChatManager;
  26. use OCP\Capabilities\IPublicCapability;
  27. use OCP\IConfig;
  28. use OCP\IUser;
  29. use OCP\IUserSession;
  30. class Capabilities implements IPublicCapability {
  31. /** @var IConfig */
  32. protected $serverConfig;
  33. /** @var Config */
  34. protected $talkConfig;
  35. /** @var IUserSession */
  36. protected $userSession;
  37. public function __construct(IConfig $serverConfig,
  38. Config $talkConfig,
  39. IUserSession $userSession) {
  40. $this->serverConfig = $serverConfig;
  41. $this->talkConfig = $talkConfig;
  42. $this->userSession = $userSession;
  43. }
  44. public function getCapabilities(): array {
  45. $user = $this->userSession->getUser();
  46. if ($user instanceof IUser && $this->talkConfig->isDisabledForUser($user)) {
  47. return [];
  48. }
  49. $capabilities = [
  50. 'features' => [
  51. 'audio',
  52. 'video',
  53. 'chat-v2',
  54. 'conversation-v4',
  55. 'guest-signaling',
  56. 'empty-group-room',
  57. 'guest-display-names',
  58. 'multi-room-users',
  59. 'favorites',
  60. 'last-room-activity',
  61. 'no-ping',
  62. 'system-messages',
  63. 'delete-messages',
  64. 'mention-flag',
  65. 'in-call-flags',
  66. 'conversation-call-flags',
  67. 'notification-levels',
  68. 'invite-groups-and-mails',
  69. 'locked-one-to-one-rooms',
  70. 'read-only-rooms',
  71. 'listable-rooms',
  72. 'chat-read-marker',
  73. 'webinary-lobby',
  74. 'start-call-flag',
  75. 'chat-replies',
  76. 'circles-support',
  77. 'force-mute',
  78. 'sip-support',
  79. 'chat-read-status',
  80. 'phonebook-search',
  81. 'raise-hand',
  82. 'room-description',
  83. 'rich-object-sharing',
  84. 'temp-user-avatar-api',
  85. 'geo-location-sharing',
  86. 'voice-message-sharing',
  87. 'signaling-v3',
  88. 'publishing-permissions',
  89. 'clear-history',
  90. 'direct-mention-flag',
  91. 'notification-calls',
  92. ],
  93. 'config' => [
  94. 'attachments' => [
  95. 'allowed' => $user instanceof IUser,
  96. ],
  97. 'chat' => [
  98. 'max-length' => ChatManager::MAX_CHAT_LENGTH,
  99. 'read-privacy' => Participant::PRIVACY_PUBLIC,
  100. ],
  101. 'conversations' => [],
  102. 'previews' => [
  103. 'max-gif-size' => (int)$this->serverConfig->getAppValue('spreed', 'max-gif-size', '3145728')
  104. ],
  105. ],
  106. ];
  107. if ($user instanceof IUser) {
  108. $capabilities['config']['attachments']['folder'] = $this->talkConfig->getAttachmentFolder($user->getUID());
  109. $capabilities['config']['chat']['read-privacy'] = $this->talkConfig->getUserReadPrivacy($user->getUID());
  110. }
  111. $capabilities['config']['conversations']['can-create'] = $user instanceof IUser && !$this->talkConfig->isNotAllowedToCreateConversations($user);
  112. if ($this->serverConfig->getAppValue('spreed', 'has_reference_id', 'no') === 'yes') {
  113. $capabilities['features'][] = 'chat-reference-id';
  114. }
  115. return [
  116. 'spreed' => $capabilities,
  117. ];
  118. }
  119. }