1
0
Fork 0
mirror of synced 2024-07-01 20:50:49 +12:00

Merge pull request #7571 from appwrite/fix-updating-message-status

Fix updating message status
This commit is contained in:
Jake Barnby 2024-02-13 12:38:39 +13:00 committed by GitHub
commit 0bd3fe6473
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 41 additions and 14 deletions

View file

@ -880,6 +880,16 @@ return [
'description' => 'Message with the requested ID has already been sent.',
'code' => 400,
],
Exception::MESSAGE_ALREADY_PROCESSING => [
'name' => Exception::MESSAGE_ALREADY_PROCESSING,
'description' => 'Message with the requested ID is already being processed.',
'code' => 400,
],
Exception::MESSAGE_ALREADY_FAILED => [
'name' => Exception::MESSAGE_ALREADY_FAILED,
'description' => 'Message with the requested ID has already failed.',
'code' => 400,
],
Exception::MESSAGE_ALREADY_SCHEDULED => [
'name' => Exception::MESSAGE_ALREADY_SCHEDULED,
'description' => 'Message with the requested ID has already been scheduled for delivery.',

View file

@ -3136,8 +3136,13 @@ App::patch('/v1/messaging/messages/email/:messageId')
throw new Exception(Exception::MESSAGE_NOT_FOUND);
}
if ($message->getAttribute('status') === MessageStatus::SENT) {
throw new Exception(Exception::MESSAGE_ALREADY_SENT);
switch ($message->getAttribute('status')) {
case MessageStatus::PROCESSING:
throw new Exception(Exception::MESSAGE_ALREADY_PROCESSING);
case MessageStatus::SENT:
throw new Exception(Exception::MESSAGE_ALREADY_SENT);
case MessageStatus::FAILED:
throw new Exception(Exception::MESSAGE_ALREADY_FAILED);
}
if (!\is_null($message->getAttribute('scheduledAt')) && $message->getAttribute('scheduledAt') < new \DateTime()) {
@ -3195,7 +3200,7 @@ App::patch('/v1/messaging/messages/email/:messageId')
'resourceUpdatedAt' => DateTime::now(),
'projectId' => $project->getId(),
'schedule' => $scheduledAt,
'active' => $status === 'processing',
'active' => $status === MessageStatus::SCHEDULED,
]));
$message->setAttribute('scheduleId', $schedule->getId());
@ -3209,7 +3214,7 @@ App::patch('/v1/messaging/messages/email/:messageId')
$schedule
->setAttribute('resourceUpdatedAt', DateTime::now())
->setAttribute('schedule', $scheduledAt)
->setAttribute('active', $status === 'processing');
->setAttribute('active', $status === MessageStatus::SCHEDULED);
$dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule);
}
@ -3266,8 +3271,13 @@ App::patch('/v1/messaging/messages/sms/:messageId')
throw new Exception(Exception::MESSAGE_NOT_FOUND);
}
if ($message->getAttribute('status') === 'sent') {
throw new Exception(Exception::MESSAGE_ALREADY_SENT);
switch ($message->getAttribute('status')) {
case MessageStatus::PROCESSING:
throw new Exception(Exception::MESSAGE_ALREADY_PROCESSING);
case MessageStatus::SENT:
throw new Exception(Exception::MESSAGE_ALREADY_SENT);
case MessageStatus::FAILED:
throw new Exception(Exception::MESSAGE_ALREADY_FAILED);
}
if (!is_null($message->getAttribute('scheduledAt')) && $message->getAttribute('scheduledAt') < new \DateTime()) {
@ -3309,7 +3319,7 @@ App::patch('/v1/messaging/messages/sms/:messageId')
'resourceUpdatedAt' => DateTime::now(),
'projectId' => $project->getId(),
'schedule' => $scheduledAt,
'active' => $status === 'processing',
'active' => $status === MessageStatus::SCHEDULED,
]));
$message->setAttribute('scheduleId', $schedule->getId());
@ -3323,7 +3333,7 @@ App::patch('/v1/messaging/messages/sms/:messageId')
$schedule
->setAttribute('resourceUpdatedAt', DateTime::now())
->setAttribute('schedule', $scheduledAt)
->setAttribute('active', $status === 'processing');
->setAttribute('active', $status === MessageStatus::SCHEDULED);
$dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule);
}
@ -3333,7 +3343,7 @@ App::patch('/v1/messaging/messages/sms/:messageId')
$message = $dbForProject->updateDocument('messages', $message->getId(), $message);
if ($status === 'processing' && \is_null($message->getAttribute('scheduledAt'))) {
if ($status === MessageStatus::PROCESSING) {
$queueForMessaging
->setMessageId($message->getId())
->trigger();
@ -3388,8 +3398,13 @@ App::patch('/v1/messaging/messages/push/:messageId')
throw new Exception(Exception::MESSAGE_NOT_FOUND);
}
if ($message->getAttribute('status') === 'sent') {
throw new Exception(Exception::MESSAGE_ALREADY_SENT);
switch ($message->getAttribute('status')) {
case MessageStatus::PROCESSING:
throw new Exception(Exception::MESSAGE_ALREADY_PROCESSING);
case MessageStatus::SENT:
throw new Exception(Exception::MESSAGE_ALREADY_SENT);
case MessageStatus::FAILED:
throw new Exception(Exception::MESSAGE_ALREADY_FAILED);
}
if (!is_null($message->getAttribute('scheduledAt')) && $message->getAttribute('scheduledAt') < new \DateTime()) {
@ -3463,7 +3478,7 @@ App::patch('/v1/messaging/messages/push/:messageId')
'resourceUpdatedAt' => DateTime::now(),
'projectId' => $project->getId(),
'schedule' => $scheduledAt,
'active' => $status === 'processing',
'active' => $status === MessageStatus::SCHEDULED,
]));
$message->setAttribute('scheduleId', $schedule->getId());
@ -3477,7 +3492,7 @@ App::patch('/v1/messaging/messages/push/:messageId')
$schedule
->setAttribute('resourceUpdatedAt', DateTime::now())
->setAttribute('schedule', $scheduledAt)
->setAttribute('active', $status === 'processing');
->setAttribute('active', $status === MessageStatus::SCHEDULED);
$dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule);
}
@ -3487,7 +3502,7 @@ App::patch('/v1/messaging/messages/push/:messageId')
$message = $dbForProject->updateDocument('messages', $message->getId(), $message);
if ($status === 'processing' && \is_null($message->getAttribute('scheduledAt'))) {
if ($status === MessageStatus::PROCESSING) {
$queueForMessaging
->setMessageId($message->getId())
->trigger();

View file

@ -266,6 +266,8 @@ class Exception extends \Exception
public const MESSAGE_NOT_FOUND = 'message_not_found';
public const MESSAGE_MISSING_TARGET = 'message_missing_target';
public const MESSAGE_ALREADY_SENT = 'message_already_sent';
public const MESSAGE_ALREADY_PROCESSING = 'message_already_processing';
public const MESSAGE_ALREADY_FAILED = 'message_already_failed';
public const MESSAGE_ALREADY_SCHEDULED = 'message_already_scheduled';
public const MESSAGE_TARGET_NOT_EMAIL = 'message_target_not_email';
public const MESSAGE_TARGET_NOT_SMS = 'message_target_not_sms';