Merge pull request #7571 from appwrite/fix-updating-message-status
Fix updating message status
This commit is contained in:
commit
0bd3fe6473
3 changed files with 41 additions and 14 deletions
|
@ -880,6 +880,16 @@ return [
|
||||||
'description' => 'Message with the requested ID has already been sent.',
|
'description' => 'Message with the requested ID has already been sent.',
|
||||||
'code' => 400,
|
'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 => [
|
Exception::MESSAGE_ALREADY_SCHEDULED => [
|
||||||
'name' => Exception::MESSAGE_ALREADY_SCHEDULED,
|
'name' => Exception::MESSAGE_ALREADY_SCHEDULED,
|
||||||
'description' => 'Message with the requested ID has already been scheduled for delivery.',
|
'description' => 'Message with the requested ID has already been scheduled for delivery.',
|
||||||
|
|
|
@ -3136,8 +3136,13 @@ App::patch('/v1/messaging/messages/email/:messageId')
|
||||||
throw new Exception(Exception::MESSAGE_NOT_FOUND);
|
throw new Exception(Exception::MESSAGE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($message->getAttribute('status') === MessageStatus::SENT) {
|
switch ($message->getAttribute('status')) {
|
||||||
throw new Exception(Exception::MESSAGE_ALREADY_SENT);
|
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()) {
|
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(),
|
'resourceUpdatedAt' => DateTime::now(),
|
||||||
'projectId' => $project->getId(),
|
'projectId' => $project->getId(),
|
||||||
'schedule' => $scheduledAt,
|
'schedule' => $scheduledAt,
|
||||||
'active' => $status === 'processing',
|
'active' => $status === MessageStatus::SCHEDULED,
|
||||||
]));
|
]));
|
||||||
|
|
||||||
$message->setAttribute('scheduleId', $schedule->getId());
|
$message->setAttribute('scheduleId', $schedule->getId());
|
||||||
|
@ -3209,7 +3214,7 @@ App::patch('/v1/messaging/messages/email/:messageId')
|
||||||
$schedule
|
$schedule
|
||||||
->setAttribute('resourceUpdatedAt', DateTime::now())
|
->setAttribute('resourceUpdatedAt', DateTime::now())
|
||||||
->setAttribute('schedule', $scheduledAt)
|
->setAttribute('schedule', $scheduledAt)
|
||||||
->setAttribute('active', $status === 'processing');
|
->setAttribute('active', $status === MessageStatus::SCHEDULED);
|
||||||
|
|
||||||
$dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule);
|
$dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule);
|
||||||
}
|
}
|
||||||
|
@ -3266,8 +3271,13 @@ App::patch('/v1/messaging/messages/sms/:messageId')
|
||||||
throw new Exception(Exception::MESSAGE_NOT_FOUND);
|
throw new Exception(Exception::MESSAGE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($message->getAttribute('status') === 'sent') {
|
switch ($message->getAttribute('status')) {
|
||||||
throw new Exception(Exception::MESSAGE_ALREADY_SENT);
|
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()) {
|
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(),
|
'resourceUpdatedAt' => DateTime::now(),
|
||||||
'projectId' => $project->getId(),
|
'projectId' => $project->getId(),
|
||||||
'schedule' => $scheduledAt,
|
'schedule' => $scheduledAt,
|
||||||
'active' => $status === 'processing',
|
'active' => $status === MessageStatus::SCHEDULED,
|
||||||
]));
|
]));
|
||||||
|
|
||||||
$message->setAttribute('scheduleId', $schedule->getId());
|
$message->setAttribute('scheduleId', $schedule->getId());
|
||||||
|
@ -3323,7 +3333,7 @@ App::patch('/v1/messaging/messages/sms/:messageId')
|
||||||
$schedule
|
$schedule
|
||||||
->setAttribute('resourceUpdatedAt', DateTime::now())
|
->setAttribute('resourceUpdatedAt', DateTime::now())
|
||||||
->setAttribute('schedule', $scheduledAt)
|
->setAttribute('schedule', $scheduledAt)
|
||||||
->setAttribute('active', $status === 'processing');
|
->setAttribute('active', $status === MessageStatus::SCHEDULED);
|
||||||
|
|
||||||
$dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule);
|
$dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule);
|
||||||
}
|
}
|
||||||
|
@ -3333,7 +3343,7 @@ App::patch('/v1/messaging/messages/sms/:messageId')
|
||||||
|
|
||||||
$message = $dbForProject->updateDocument('messages', $message->getId(), $message);
|
$message = $dbForProject->updateDocument('messages', $message->getId(), $message);
|
||||||
|
|
||||||
if ($status === 'processing' && \is_null($message->getAttribute('scheduledAt'))) {
|
if ($status === MessageStatus::PROCESSING) {
|
||||||
$queueForMessaging
|
$queueForMessaging
|
||||||
->setMessageId($message->getId())
|
->setMessageId($message->getId())
|
||||||
->trigger();
|
->trigger();
|
||||||
|
@ -3388,8 +3398,13 @@ App::patch('/v1/messaging/messages/push/:messageId')
|
||||||
throw new Exception(Exception::MESSAGE_NOT_FOUND);
|
throw new Exception(Exception::MESSAGE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($message->getAttribute('status') === 'sent') {
|
switch ($message->getAttribute('status')) {
|
||||||
throw new Exception(Exception::MESSAGE_ALREADY_SENT);
|
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()) {
|
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(),
|
'resourceUpdatedAt' => DateTime::now(),
|
||||||
'projectId' => $project->getId(),
|
'projectId' => $project->getId(),
|
||||||
'schedule' => $scheduledAt,
|
'schedule' => $scheduledAt,
|
||||||
'active' => $status === 'processing',
|
'active' => $status === MessageStatus::SCHEDULED,
|
||||||
]));
|
]));
|
||||||
|
|
||||||
$message->setAttribute('scheduleId', $schedule->getId());
|
$message->setAttribute('scheduleId', $schedule->getId());
|
||||||
|
@ -3477,7 +3492,7 @@ App::patch('/v1/messaging/messages/push/:messageId')
|
||||||
$schedule
|
$schedule
|
||||||
->setAttribute('resourceUpdatedAt', DateTime::now())
|
->setAttribute('resourceUpdatedAt', DateTime::now())
|
||||||
->setAttribute('schedule', $scheduledAt)
|
->setAttribute('schedule', $scheduledAt)
|
||||||
->setAttribute('active', $status === 'processing');
|
->setAttribute('active', $status === MessageStatus::SCHEDULED);
|
||||||
|
|
||||||
$dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule);
|
$dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule);
|
||||||
}
|
}
|
||||||
|
@ -3487,7 +3502,7 @@ App::patch('/v1/messaging/messages/push/:messageId')
|
||||||
|
|
||||||
$message = $dbForProject->updateDocument('messages', $message->getId(), $message);
|
$message = $dbForProject->updateDocument('messages', $message->getId(), $message);
|
||||||
|
|
||||||
if ($status === 'processing' && \is_null($message->getAttribute('scheduledAt'))) {
|
if ($status === MessageStatus::PROCESSING) {
|
||||||
$queueForMessaging
|
$queueForMessaging
|
||||||
->setMessageId($message->getId())
|
->setMessageId($message->getId())
|
||||||
->trigger();
|
->trigger();
|
||||||
|
|
|
@ -266,6 +266,8 @@ class Exception extends \Exception
|
||||||
public const MESSAGE_NOT_FOUND = 'message_not_found';
|
public const MESSAGE_NOT_FOUND = 'message_not_found';
|
||||||
public const MESSAGE_MISSING_TARGET = 'message_missing_target';
|
public const MESSAGE_MISSING_TARGET = 'message_missing_target';
|
||||||
public const MESSAGE_ALREADY_SENT = 'message_already_sent';
|
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_ALREADY_SCHEDULED = 'message_already_scheduled';
|
||||||
public const MESSAGE_TARGET_NOT_EMAIL = 'message_target_not_email';
|
public const MESSAGE_TARGET_NOT_EMAIL = 'message_target_not_email';
|
||||||
public const MESSAGE_TARGET_NOT_SMS = 'message_target_not_sms';
|
public const MESSAGE_TARGET_NOT_SMS = 'message_target_not_sms';
|
||||||
|
|
Loading…
Reference in a new issue