diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2021-05-31 17:44:09 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-31 17:44:09 +0300 |
commit | 6e995e6a2b0f8f36bd5c1248c4fe628fe6cd299f (patch) | |
tree | 281786d9718c2771b4811f26575994bb8d6fab11 | |
parent | cc98dbdb6de9f49e4277a177d4e0f7fee0dcd13e (diff) | |
parent | 61aa4e33b55782cb7859cb198c0cecb35d5a9adf (diff) |
Merge pull request #5616 from nextcloud/feature/1576/allow-to-specify-meta-data-on-a-share
Allow to specify meta-data for sharing
-rw-r--r-- | docs/chat.md | 22 | ||||
-rw-r--r-- | lib/Chat/Parser/SystemMessage.php | 15 | ||||
-rw-r--r-- | lib/Chat/SystemMessage/Listener.php | 5 | ||||
-rw-r--r-- | tests/psalm-baseline.xml | 8 |
4 files changed, 38 insertions, 12 deletions
diff --git a/docs/chat.md b/docs/chat.md index ceb4b608f..d3da178b8 100644 --- a/docs/chat.md +++ b/docs/chat.md @@ -131,6 +131,28 @@ See [OCP\RichObjectStrings\Definitions](https://github.com/nextcloud/server/blob - Data: The full message array of the new message, as defined in [Receive chat messages of a conversation](#receive-chat-messages-of-a-conversation) +## Share a file to the chat + +* Method: `POST` +* Endpoint: `ocs/v2.php/apps/files_sharing/api/v1/shares` +* Data: + + field | type | Description + ---|---|--- + `shareType` | int | `10` means share to a conversation + `shareWith` | string | The token of the conversation to share the file to + `path` | string | The file path inside the user's root to share + `referenceId` | string | A reference string to be able to identify the generated chat message again in a "get messages" request, should be a random sha256 (only available with `chat-reference-id` capability) + `talkMetaData` | string | JSON encoded array of the meta data + +* `talkMetaData` array: + + field | type | Description + ---|---|--- + `messageType` | string | A message type to show the message in different styles. Currently known: `voice-message` and `comment` + +* Response: [See official OCS Share API docs](https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-share-api.html?highlight=sharing#create-a-new-share) + ## Deleting a chat message * Required capability: `delete-messages` diff --git a/lib/Chat/Parser/SystemMessage.php b/lib/Chat/Parser/SystemMessage.php index fe0e1e7f9..669ac3f8a 100644 --- a/lib/Chat/Parser/SystemMessage.php +++ b/lib/Chat/Parser/SystemMessage.php @@ -31,6 +31,7 @@ use OCA\Talk\Participant; use OCA\Talk\Room; use OCA\Talk\Share\RoomShareProvider; use OCP\Comments\IComment; +use OCP\Files\InvalidPathException; use OCP\Files\IRootFolder; use OCP\Files\Node; use OCP\Files\NotFoundException; @@ -39,6 +40,7 @@ use OCP\IPreview as IPreviewManager; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; +use OCP\Share\Exceptions\ShareNotFound; class SystemMessage { @@ -324,7 +326,12 @@ class SystemMessage { try { $parsedParameters['file'] = $this->getFileFromShare($participant, $parameters['share']); $parsedMessage = '{file}'; - $chatMessage->setMessageType('comment'); + $metaData = $parameters['metaData'] ?? []; + if (isset($metaData['messageType']) && $metaData['messageType'] === 'voice-message') { + $chatMessage->setMessageType('voice-message'); + } else { + $chatMessage->setMessageType('comment'); + } } catch (\Exception $e) { $parsedMessage = $this->l->t('{actor} shared a file which is no longer available'); if ($currentUserIsActor) { @@ -423,9 +430,9 @@ class SystemMessage { * @param Participant $participant * @param string $shareId * @return array - * @throws \OCP\Files\InvalidPathException - * @throws \OCP\Files\NotFoundException - * @throws \OCP\Share\Exceptions\ShareNotFound + * @throws InvalidPathException + * @throws NotFoundException + * @throws ShareNotFound */ protected function getFileFromShare(Participant $participant, string $shareId): array { $share = $this->shareProvider->getShareById($shareId); diff --git a/lib/Chat/SystemMessage/Listener.php b/lib/Chat/SystemMessage/Listener.php index a17d87546..3c2def29d 100644 --- a/lib/Chat/SystemMessage/Listener.php +++ b/lib/Chat/SystemMessage/Listener.php @@ -312,7 +312,10 @@ class Listener { $manager = \OC::$server->query(Manager::class); $room = $manager->getRoomByToken($share->getSharedWith()); - $listener->sendSystemMessage($room, 'file_shared', ['share' => $share->getId()]); + $metaData = \OC::$server->getRequest()->getParam('talkMetaData') ?? ''; + $metaData = json_decode($metaData, true); + $metaData = is_array($metaData) ? $metaData : []; + $listener->sendSystemMessage($room, 'file_shared', ['share' => $share->getId(), 'metaData' => $metaData]); }; /** * @psalm-suppress UndefinedClass diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index da88847b7..5e7b91655 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -29,7 +29,7 @@ <code>$this->rootFolder</code> <code>IRootFolder</code> <code>IRootFolder</code> - <code>\OCP\Share\Exceptions\ShareNotFound</code> + <code>ShareNotFound</code> </MissingDependency> <UndefinedClass occurrences="1"> <code>\OC_Util</code> @@ -203,9 +203,6 @@ <code>IRootFolder</code> <code>IRootFolder</code> </MissingDependency> - <UndefinedClass occurrences="1"> - <code>SharedStorage</code> - </UndefinedClass> </file> <file src="lib/Controller/SignalingController.php"> <UndefinedClass occurrences="1"> @@ -237,9 +234,6 @@ <code>ShareNotFound</code> <code>ShareNotFound</code> </MissingDependency> - <UndefinedClass occurrences="1"> - <code>GroupFolderStorage</code> - </UndefinedClass> </file> <file src="lib/Flow/Operation.php"> <InvalidArgument occurrences="1"/> |