From 85841b76e61e892815d50a405832eff4485223b0 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos <1697880+AngelFQC@users.noreply.github.com> Date: Tue, 24 Sep 2024 01:01:36 -0500 Subject: [PATCH] Message: Sender deletes own message_rel_user - refs BT#21988 --- assets/vue/views/message/MessageList.vue | 2 +- assets/vue/views/message/MessageShow.vue | 2 +- src/CoreBundle/Entity/Message.php | 11 +++++++++ src/CoreBundle/State/MessageProcessor.php | 30 ----------------------- 4 files changed, 13 insertions(+), 32 deletions(-) diff --git a/assets/vue/views/message/MessageList.vue b/assets/vue/views/message/MessageList.vue index 297c3a2a3d..f3e0a0c692 100644 --- a/assets/vue/views/message/MessageList.vue +++ b/assets/vue/views/message/MessageList.vue @@ -429,7 +429,7 @@ function sortingChanged(event) { } function findMyReceiver(message) { - const receivers = [...message.receiversTo, ...message.receiversCc] + const receivers = [...message.receiversTo, ...message.receiversCc, ...message.receiversSender] return receivers.find(({ receiver }) => receiver["@id"] === securityStore.user["@id"]) } diff --git a/assets/vue/views/message/MessageShow.vue b/assets/vue/views/message/MessageShow.vue index 594057d9c0..342c0a168a 100644 --- a/assets/vue/views/message/MessageShow.vue +++ b/assets/vue/views/message/MessageShow.vue @@ -188,7 +188,7 @@ store.dispatch("message/load", id).then((responseItem) => { }) function findMyReceiver(message) { - const receivers = [...message.receiversTo, ...message.receiversCc] + const receivers = [...message.receiversTo, ...message.receiversCc, ...message.receiversSender] return receivers.find(({ receiver }) => receiver["@id"] === securityStore.user["@id"]) } diff --git a/src/CoreBundle/Entity/Message.php b/src/CoreBundle/Entity/Message.php index ca7b8d0240..6eaf7b4551 100644 --- a/src/CoreBundle/Entity/Message.php +++ b/src/CoreBundle/Entity/Message.php @@ -222,6 +222,17 @@ class Message ; } + #[Groups(['message:read'])] + public function getReceiversSender(): array + { + return $this->receivers + ->filter( + fn (MessageRelUser $messageRelUser) => MessageRelUser::TYPE_SENDER === $messageRelUser->getReceiverType() + ) + ->getValues() + ; + } + #[Groups(['message:read'])] public function getFirstReceiver(): ?MessageRelUser { diff --git a/src/CoreBundle/State/MessageProcessor.php b/src/CoreBundle/State/MessageProcessor.php index 9efb64434f..1d6547a410 100644 --- a/src/CoreBundle/State/MessageProcessor.php +++ b/src/CoreBundle/State/MessageProcessor.php @@ -82,36 +82,6 @@ final class MessageProcessor implements ProcessorInterface return $message; } - private function processDeleteForUser($data): Message - { - /** @var Message $message */ - $message = $data; - - $request = $this->requestStack->getCurrentRequest(); - if (!$request) { - throw new LogicException('Cannot get current request'); - } - - $requestData = json_decode($request->getContent(), true); - if (!isset($requestData['userId'])) { - throw new InvalidArgumentException('The field userId is required.'); - } - - $userId = $requestData['userId']; - $messageRelUserRepository = $this->entityManager->getRepository(MessageRelUser::class); - $messageRelUser = $messageRelUserRepository->findOneBy([ - 'message' => $message, - 'receiver' => $userId, - ]); - - if ($messageRelUser) { - $this->entityManager->remove($messageRelUser); - $this->entityManager->flush(); - } - - return $message; - } - private function saveNotificationForInboxMessage(Message $message): void { $sender_info = api_get_user_info(