From 96a249bb05e9f7ddb2dd66968718d7baa27cd0c9 Mon Sep 17 00:00:00 2001 From: kaioken Date: Sun, 28 Jul 2024 15:00:17 -0400 Subject: [PATCH] refact: add user to share msg --- src/Domains/Social/Enums/AppEnum.php | 1 + .../Services/MessageInteractionService.php | 4 ++ tests/GraphQL/Social/MessageTest.php | 46 +++++++++++++++++-- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/Domains/Social/Enums/AppEnum.php b/src/Domains/Social/Enums/AppEnum.php index 901c1c6cd..b02e2ba2f 100644 --- a/src/Domains/Social/Enums/AppEnum.php +++ b/src/Domains/Social/Enums/AppEnum.php @@ -7,4 +7,5 @@ enum AppEnum: STRING { case SHAREABLE_LINK = 'APP_SHAREABLE_LINK'; + case SHAREABLE_LINK_WITH_USERNAME = 'APP_SHAREABLE_LINK_WITH_USERNAME'; } diff --git a/src/Domains/Social/Messages/Services/MessageInteractionService.php b/src/Domains/Social/Messages/Services/MessageInteractionService.php index 2db4d8427..77281bb0c 100644 --- a/src/Domains/Social/Messages/Services/MessageInteractionService.php +++ b/src/Domains/Social/Messages/Services/MessageInteractionService.php @@ -27,6 +27,10 @@ public function share(UserInterface $who, ?UserInterface $to = null): string $shareUrl = $this->message->app->get(AppEnum::SHAREABLE_LINK->value) ?? $this->message->app->url; + if ($this->message->app->get(AppEnum::SHAREABLE_LINK_WITH_USERNAME->value)) { + $shareUrl .= '/' . $this->message->user->displayname; + } + return $shareUrl . '/' . (! empty($this->message->slug) ? $this->message->slug : $this->message->getId()); } diff --git a/tests/GraphQL/Social/MessageTest.php b/tests/GraphQL/Social/MessageTest.php index 7e0895cc3..2c18cd97a 100644 --- a/tests/GraphQL/Social/MessageTest.php +++ b/tests/GraphQL/Social/MessageTest.php @@ -229,7 +229,7 @@ public function testMessages() createMessage(input: $input) { id message - users { + user { id } } @@ -252,7 +252,7 @@ public function testMessages() data { message message_types_id, - users { + user { id } } @@ -262,6 +262,46 @@ public function testMessages() )->assertSuccessful(); } + public function testShareMessage() + { + $messageType = MessageType::factory()->create(); + $message = fake()->text(); + $response = $this->graphQL( + ' + mutation createMessage($input: MessageInput!) { + createMessage(input: $input) { + id + message + user { + id + } + } + } + ', + [ + 'input' => [ + 'message' => $message, + 'message_verb' => $messageType->verb, + 'system_modules_id' => 1, + 'entity_id' => '1', + ], + ] + ); + + $createdMessageId = $response['data']['createMessage']['id']; + + $this->graphQL( + ' + mutation shareMessage($id: ID!) { + shareMessage(id: $id) + } + ', + [ + 'id' => $createdMessageId, + ] + )->assertSuccessful(); + } + public function testCreateChildMessage() { $messageType = MessageType::factory()->create(); @@ -415,7 +455,7 @@ public function testGroupMessageByDate() createMessage(input: $input) { id message - users { + user { id } }