diff --git a/app/config/errors.php b/app/config/errors.php index 2c5dfbad01..5514e8e68e 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -785,5 +785,10 @@ return [ 'name' => Exception::MESSAGE_NOT_FOUND, 'description' => 'Message with the requested ID could not be found.', 'code' => 404, + ], + Exception::MESSAGE_ALREADY_SENT => [ + 'name' => Exception::MESSAGE_ALREADY_SENT, + 'description' => 'Message with the requested ID has already been sent.', + 'code' => 400, ] ]; diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index 40e6a159bc..e83fc1114d 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -1703,6 +1703,10 @@ App::patch('/v1/messaging/messages/email/:messageId') throw new Exception(Exception::MESSAGE_NOT_FOUND); } + if ($message->getAttribute('status') === 'sent') { + throw new Exception(Exception::MESSAGE_ALREADY_SENT); + } + if (\count($to) > 0) { $message->setAttribute('to', $to); } diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 861db5271c..ee17ccef0c 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -240,6 +240,7 @@ class Exception extends \Exception /** Message */ public const MESSAGE_NOT_FOUND = 'message_not_found'; + public const MESSAGE_ALREADY_SENT = 'message_already_sent'; protected $type = ''; protected $errors = [];