Update create and update message APIs to support draft messages
This commit is contained in:
parent
34af90b65e
commit
6eeb8c4cac
1 changed files with 52 additions and 45 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use Appwrite\Auth\Validator\Phone;
|
use Appwrite\Auth\Validator\Phone;
|
||||||
use Appwrite\Detector\Detector;
|
use Appwrite\Detector\Detector;
|
||||||
|
use Appwrite\Enum\MessageStatus;
|
||||||
use Appwrite\Event\Delete;
|
use Appwrite\Event\Delete;
|
||||||
use Appwrite\Event\Event;
|
use Appwrite\Event\Event;
|
||||||
use Appwrite\Event\Messaging;
|
use Appwrite\Event\Messaging;
|
||||||
|
@ -2282,7 +2283,7 @@ App::post('/v1/messaging/messages/email')
|
||||||
->param('cc', [], new ArrayList(new UID()), 'Array of target IDs to be added as CC.', true)
|
->param('cc', [], new ArrayList(new UID()), 'Array of target IDs to be added as CC.', true)
|
||||||
->param('bcc', [], new ArrayList(new UID()), 'Array of target IDs to be added as BCC.', true)
|
->param('bcc', [], new ArrayList(new UID()), 'Array of target IDs to be added as BCC.', true)
|
||||||
->param('description', '', new Text(256), 'Description for message.', true)
|
->param('description', '', new Text(256), 'Description for message.', true)
|
||||||
->param('status', 'processing', new WhiteList(['draft', 'canceled', 'processing']), 'Message Status. Value must be either draft or cancelled or processing.', true)
|
->param('status', MessageStatus::DRAFT, new WhiteList([MessageStatus::DRAFT, MessageStatus::SCHEDULED, MessageStatus::PROCESSING]), 'Message Status. Value must be one of: ' . implode(', ', [MessageStatus::DRAFT, MessageStatus::SCHEDULED, MessageStatus::PROCESSING]) . '.', true)
|
||||||
->param('html', false, new Boolean(), 'Is content of type HTML', true)
|
->param('html', false, new Boolean(), 'Is content of type HTML', true)
|
||||||
->param('scheduledAt', null, new DatetimeValidator(requireDateInFuture: true), 'Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.', true)
|
->param('scheduledAt', null, new DatetimeValidator(requireDateInFuture: true), 'Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.', true)
|
||||||
->inject('queueForEvents')
|
->inject('queueForEvents')
|
||||||
|
@ -2295,7 +2296,7 @@ App::post('/v1/messaging/messages/email')
|
||||||
? ID::unique()
|
? ID::unique()
|
||||||
: $messageId;
|
: $messageId;
|
||||||
|
|
||||||
if (\count($topics) === 0 && \count($users) === 0 && \count($targets) === 0) {
|
if ($status !== MessageStatus::DRAFT && \count($topics) === 0 && \count($users) === 0 && \count($targets) === 0) {
|
||||||
throw new Exception(Exception::MESSAGE_MISSING_TARGET);
|
throw new Exception(Exception::MESSAGE_MISSING_TARGET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2336,7 +2337,7 @@ App::post('/v1/messaging/messages/email')
|
||||||
'status' => $status,
|
'status' => $status,
|
||||||
]));
|
]));
|
||||||
|
|
||||||
if ($status === 'processing') {
|
if ($status === MessageStatus::PROCESSING) {
|
||||||
$queueForMessaging
|
$queueForMessaging
|
||||||
->setMessageId($message->getId())
|
->setMessageId($message->getId())
|
||||||
->setProject($project)
|
->setProject($project)
|
||||||
|
@ -2371,7 +2372,7 @@ App::post('/v1/messaging/messages/sms')
|
||||||
->param('users', [], new ArrayList(new UID()), 'List of User IDs.', true)
|
->param('users', [], new ArrayList(new UID()), 'List of User IDs.', true)
|
||||||
->param('targets', [], new ArrayList(new UID()), 'List of Targets IDs.', true)
|
->param('targets', [], new ArrayList(new UID()), 'List of Targets IDs.', true)
|
||||||
->param('description', '', new Text(256), 'Description for Message.', true)
|
->param('description', '', new Text(256), 'Description for Message.', true)
|
||||||
->param('status', 'processing', new WhiteList(['draft', 'canceled', 'processing']), 'Message Status. Value must be either draft or cancelled or processing.', true)
|
->param('status', MessageStatus::DRAFT, new WhiteList([MessageStatus::DRAFT, MessageStatus::SCHEDULED, MessageStatus::PROCESSING]), 'Message Status. Value must be one of: ' . implode(', ', [MessageStatus::DRAFT, MessageStatus::SCHEDULED, MessageStatus::PROCESSING]) . '.', true)
|
||||||
->param('scheduledAt', null, new DatetimeValidator(requireDateInFuture: true), 'Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.', true)
|
->param('scheduledAt', null, new DatetimeValidator(requireDateInFuture: true), 'Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.', true)
|
||||||
->inject('queueForEvents')
|
->inject('queueForEvents')
|
||||||
->inject('dbForProject')
|
->inject('dbForProject')
|
||||||
|
@ -2383,10 +2384,11 @@ App::post('/v1/messaging/messages/sms')
|
||||||
? ID::unique()
|
? ID::unique()
|
||||||
: $messageId;
|
: $messageId;
|
||||||
|
|
||||||
if (\count($topics) === 0 && \count($users) === 0 && \count($targets) === 0) {
|
if ($status !== MessageStatus::DRAFT && \count($topics) === 0 && \count($users) === 0 && \count($targets) === 0) {
|
||||||
throw new Exception(Exception::MESSAGE_MISSING_TARGET);
|
throw new Exception(Exception::MESSAGE_MISSING_TARGET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($targets)) {
|
||||||
$foundTargets = $dbForProject->find('targets', [
|
$foundTargets = $dbForProject->find('targets', [
|
||||||
Query::equal('$id', $targets),
|
Query::equal('$id', $targets),
|
||||||
Query::equal('providerType', [MESSAGE_TYPE_SMS]),
|
Query::equal('providerType', [MESSAGE_TYPE_SMS]),
|
||||||
|
@ -2402,6 +2404,7 @@ App::post('/v1/messaging/messages/sms')
|
||||||
throw new Exception(Exception::USER_TARGET_NOT_FOUND);
|
throw new Exception(Exception::USER_TARGET_NOT_FOUND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$message = $dbForProject->createDocument('messages', new Document([
|
$message = $dbForProject->createDocument('messages', new Document([
|
||||||
'$id' => $messageId,
|
'$id' => $messageId,
|
||||||
|
@ -2416,7 +2419,7 @@ App::post('/v1/messaging/messages/sms')
|
||||||
'status' => $status,
|
'status' => $status,
|
||||||
]));
|
]));
|
||||||
|
|
||||||
if ($status === 'processing') {
|
if ($status === MessageStatus::PROCESSING) {
|
||||||
$queueForMessaging
|
$queueForMessaging
|
||||||
->setMessageId($message->getId())
|
->setMessageId($message->getId())
|
||||||
->setProject($project)
|
->setProject($project)
|
||||||
|
@ -2459,7 +2462,7 @@ App::post('/v1/messaging/messages/push')
|
||||||
->param('color', '', new Text(256), 'Color for push notification. Available only for Android Platform.', true)
|
->param('color', '', new Text(256), 'Color for push notification. Available only for Android Platform.', true)
|
||||||
->param('tag', '', new Text(256), 'Tag for push notification. Available only for Android Platform.', true)
|
->param('tag', '', new Text(256), 'Tag for push notification. Available only for Android Platform.', true)
|
||||||
->param('badge', '', new Text(256), 'Badge for push notification. Available only for IOS Platform.', true)
|
->param('badge', '', new Text(256), 'Badge for push notification. Available only for IOS Platform.', true)
|
||||||
->param('status', 'processing', new WhiteList(['draft', 'canceled', 'processing']), 'Message Status. Value must be either draft or cancelled or processing.', true)
|
->param('status', MessageStatus::DRAFT, new WhiteList([MessageStatus::DRAFT, MessageStatus::SCHEDULED, MessageStatus::PROCESSING]), 'Message Status. Value must be one of: ' . implode(', ', [MessageStatus::DRAFT, MessageStatus::SCHEDULED, MessageStatus::PROCESSING]) . '.', true)
|
||||||
->param('scheduledAt', null, new DatetimeValidator(requireDateInFuture: true), 'Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.', true)
|
->param('scheduledAt', null, new DatetimeValidator(requireDateInFuture: true), 'Scheduled delivery time for message in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. DateTime value must be in future.', true)
|
||||||
->inject('queueForEvents')
|
->inject('queueForEvents')
|
||||||
->inject('dbForProject')
|
->inject('dbForProject')
|
||||||
|
@ -2471,10 +2474,11 @@ App::post('/v1/messaging/messages/push')
|
||||||
? ID::unique()
|
? ID::unique()
|
||||||
: $messageId;
|
: $messageId;
|
||||||
|
|
||||||
if (\count($topics) === 0 && \count($users) === 0 && \count($targets) === 0) {
|
if ($status !== MessageStatus::DRAFT && \count($topics) === 0 && \count($users) === 0 && \count($targets) === 0) {
|
||||||
throw new Exception(Exception::MESSAGE_MISSING_TARGET);
|
throw new Exception(Exception::MESSAGE_MISSING_TARGET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($targets)) {
|
||||||
$foundTargets = $dbForProject->find('targets', [
|
$foundTargets = $dbForProject->find('targets', [
|
||||||
Query::equal('$id', $targets),
|
Query::equal('$id', $targets),
|
||||||
Query::equal('providerType', [MESSAGE_TYPE_PUSH]),
|
Query::equal('providerType', [MESSAGE_TYPE_PUSH]),
|
||||||
|
@ -2490,6 +2494,7 @@ App::post('/v1/messaging/messages/push')
|
||||||
throw new Exception(Exception::USER_TARGET_NOT_FOUND);
|
throw new Exception(Exception::USER_TARGET_NOT_FOUND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$pushData = [];
|
$pushData = [];
|
||||||
|
|
||||||
|
@ -2513,7 +2518,7 @@ App::post('/v1/messaging/messages/push')
|
||||||
'status' => $status,
|
'status' => $status,
|
||||||
]));
|
]));
|
||||||
|
|
||||||
if ($status === 'processing') {
|
if ($status === MessageStatus::PROCESSING) {
|
||||||
$queueForMessaging
|
$queueForMessaging
|
||||||
->setMessageId($message->getId())
|
->setMessageId($message->getId())
|
||||||
->setProject($project)
|
->setProject($project)
|
||||||
|
@ -2700,7 +2705,7 @@ App::patch('/v1/messaging/messages/email/:messageId')
|
||||||
->param('subject', null, new Text(998), 'Email Subject.', true)
|
->param('subject', null, new Text(998), 'Email Subject.', true)
|
||||||
->param('description', null, new Text(256), 'Description for Message.', true)
|
->param('description', null, new Text(256), 'Description for Message.', true)
|
||||||
->param('content', null, new Text(64230), 'Email Content.', true)
|
->param('content', null, new Text(64230), 'Email Content.', true)
|
||||||
->param('status', null, new WhiteList(['draft', 'cancelled', 'processing']), 'Message Status. Value must be either draft or cancelled or processing.', true)
|
->param('status', MessageStatus::DRAFT, new WhiteList([MessageStatus::DRAFT, MessageStatus::SCHEDULED, MessageStatus::PROCESSING]), 'Message Status. Value must be one of: ' . implode(', ', [MessageStatus::DRAFT, MessageStatus::SCHEDULED, MessageStatus::PROCESSING]) . '.', true)
|
||||||
->param('html', null, new Boolean(), 'Is content of type HTML', true)
|
->param('html', null, new Boolean(), 'Is content of type HTML', true)
|
||||||
->param('cc', null, new ArrayList(new UID()), 'Array of target IDs to be added as CC.', true)
|
->param('cc', null, new ArrayList(new UID()), 'Array of target IDs to be added as CC.', true)
|
||||||
->param('bcc', null, new ArrayList(new UID()), 'Array of target IDs to be added as BCC.', true)
|
->param('bcc', null, new ArrayList(new UID()), 'Array of target IDs to be added as BCC.', true)
|
||||||
|
@ -2717,7 +2722,7 @@ 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') === 'sent') {
|
if ($message->getAttribute('status') === MessageStatus::SENT) {
|
||||||
throw new Exception(Exception::MESSAGE_ALREADY_SENT);
|
throw new Exception(Exception::MESSAGE_ALREADY_SENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2736,6 +2741,7 @@ App::patch('/v1/messaging/messages/email/:messageId')
|
||||||
if (!\is_null($targets) || !\is_null($cc) || !\is_null($bcc)) {
|
if (!\is_null($targets) || !\is_null($cc) || !\is_null($bcc)) {
|
||||||
$mergedTargets = \array_merge(...\array_filter([$targets, $cc, $bcc]));
|
$mergedTargets = \array_merge(...\array_filter([$targets, $cc, $bcc]));
|
||||||
|
|
||||||
|
if (!empty($mergedTargets)) {
|
||||||
$foundTargets = $dbForProject->find('targets', [
|
$foundTargets = $dbForProject->find('targets', [
|
||||||
Query::equal('$id', $mergedTargets),
|
Query::equal('$id', $mergedTargets),
|
||||||
Query::equal('providerType', [MESSAGE_TYPE_EMAIL]),
|
Query::equal('providerType', [MESSAGE_TYPE_EMAIL]),
|
||||||
|
@ -2750,6 +2756,7 @@ App::patch('/v1/messaging/messages/email/:messageId')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$data = $message->getAttribute('data');
|
$data = $message->getAttribute('data');
|
||||||
|
|
||||||
|
@ -2793,7 +2800,7 @@ App::patch('/v1/messaging/messages/email/:messageId')
|
||||||
|
|
||||||
$message = $dbForProject->updateDocument('messages', $message->getId(), $message);
|
$message = $dbForProject->updateDocument('messages', $message->getId(), $message);
|
||||||
|
|
||||||
if ($status === 'processing') {
|
if ($status === MessageStatus::PROCESSING) {
|
||||||
$queueForMessaging
|
$queueForMessaging
|
||||||
->setMessageId($message->getId())
|
->setMessageId($message->getId())
|
||||||
->setProject($project)
|
->setProject($project)
|
||||||
|
|
Loading…
Reference in a new issue