From 4b58d08fd8f0b6609c7d6292018cdd50bb494755 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 29 Nov 2023 17:09:44 +1300 Subject: [PATCH] Add `providerType` to `Message` --- app/config/collections.php | 11 +++++ app/controllers/api/messaging.php | 38 ++++------------ src/Appwrite/Event/Messaging.php | 14 +++--- .../Utopia/Response/Model/Message.php | 8 +++- tests/e2e/Services/GraphQL/Base.php | 44 ++++++++++--------- 5 files changed, 57 insertions(+), 58 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index d1db57c426..cbaed36f71 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -1505,6 +1505,17 @@ $commonCollections = [ '$id' => ID::custom('messages'), 'name' => 'Messages', 'attributes' => [ + [ + '$id' => ID::custom('providerType'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => true, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('description'), 'type' => Database::VAR_STRING, diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index 85be4242c9..411243d7b3 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -2240,6 +2240,7 @@ App::post('/v1/messaging/messages/email') $message = $dbForProject->createDocument('messages', new Document([ '$id' => $messageId, + 'providerType' => MESSAGE_TYPE_EMAIL, 'topics' => $topics, 'users' => $users, 'targets' => $targets, @@ -2303,6 +2304,7 @@ App::post('/v1/messaging/messages/sms') $message = $dbForProject->createDocument('messages', new Document([ '$id' => $messageId, + 'providerType' => MESSAGE_TYPE_SMS, 'topics' => $topics, 'users' => $users, 'targets' => $targets, @@ -2370,41 +2372,19 @@ App::post('/v1/messaging/messages/push') throw new Exception(Exception::MESSAGE_MISSING_TARGET); } - $pushData = [ - 'title' => $title, - 'body' => $body, - ]; + $pushData = []; - if (!is_null($data)) { - $pushData['data'] = $data; - } + $keys = ['title', 'body', 'data', 'action', 'icon', 'sound', 'color', 'tag', 'badge']; - if ($action) { - $pushData['action'] = $action; - } - - if ($icon) { - $pushData['icon'] = $icon; - } - - if ($sound) { - $pushData['sound'] = $sound; - } - - if ($color) { - $pushData['color'] = $color; - } - - if ($tag) { - $pushData['tag'] = $tag; - } - - if ($badge) { - $pushData['badge'] = $badge; + foreach ($keys as $key) { + if (!empty($$key)) { + $pushData[$key] = $$key; + } } $message = $dbForProject->createDocument('messages', new Document([ '$id' => $messageId, + 'providerType' => MESSAGE_TYPE_PUSH, 'topics' => $topics, 'users' => $users, 'targets' => $targets, diff --git a/src/Appwrite/Event/Messaging.php b/src/Appwrite/Event/Messaging.php index 62d41f8c3b..9201799355 100644 --- a/src/Appwrite/Event/Messaging.php +++ b/src/Appwrite/Event/Messaging.php @@ -11,7 +11,7 @@ class Messaging extends Event protected ?string $messageId = null; protected ?Document $message = null; protected ?array $recipients = null; - protected ?string $deliveryTime = null; + protected ?string $scheduledAt = null; protected ?string $providerType = null; @@ -117,14 +117,14 @@ class Messaging extends Event } /** - * Sets Delivery time for the messaging event. + * Sets Scheduled delivery time for the messaging event. * - * @param string $deliveryTime + * @param string $scheduledAt * @return self */ - public function setDeliveryTime(string $deliveryTime): self + public function setScheduledAt(string $scheduledAt): self { - $this->deliveryTime = $deliveryTime; + $this->scheduledAt = $scheduledAt; return $this; } @@ -134,9 +134,9 @@ class Messaging extends Event * * @return string */ - public function getDeliveryTime(): string + public function getScheduledAt(): string { - return $this->deliveryTime; + return $this->scheduledAt; } /** diff --git a/src/Appwrite/Utopia/Response/Model/Message.php b/src/Appwrite/Utopia/Response/Model/Message.php index 27c70d7073..32c67b6936 100644 --- a/src/Appwrite/Utopia/Response/Model/Message.php +++ b/src/Appwrite/Utopia/Response/Model/Message.php @@ -29,6 +29,12 @@ class Message extends Any 'default' => '', 'example' => self::TYPE_DATETIME_EXAMPLE, ]) + ->addRule('providerType', [ + 'type' => self::TYPE_STRING, + 'description' => 'Message provider type.', + 'default' => '', + 'example' => MESSAGE_TYPE_EMAIL, + ]) ->addRule('topics', [ 'type' => self::TYPE_STRING, 'description' => 'Topic IDs set as recipients.', @@ -50,7 +56,7 @@ class Message extends Any 'array' => true, 'example' => ['5e5ea5c16897e'], ]) - ->addRule('deliveryTime', [ + ->addRule('scheduledAt', [ 'type' => self::TYPE_DATETIME, 'description' => 'The scheduled time for message.', 'required' => false, diff --git a/tests/e2e/Services/GraphQL/Base.php b/tests/e2e/Services/GraphQL/Base.php index 6939e6a9b5..2854d0bf42 100644 --- a/tests/e2e/Services/GraphQL/Base.php +++ b/tests/e2e/Services/GraphQL/Base.php @@ -2098,13 +2098,13 @@ trait Base } }'; case self::$CREATE_EMAIL: - return 'mutation createEmail($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $subject: String!, $content: String!, $status: String, $description: String, $html: Boolean, $deliveryTime: String) { - messagingCreateEmail(messageId: $messageId, topics: $topics, users: $users, targets: $targets, subject: $subject, content: $content, status: $status, description: $description, html: $html, deliveryTime: $deliveryTime) { + return 'mutation createEmail($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $subject: String!, $content: String!, $status: String, $description: String, $html: Boolean, $scheduledAt: String) { + messagingCreateEmail(messageId: $messageId, topics: $topics, users: $users, targets: $targets, subject: $subject, content: $content, status: $status, description: $description, html: $html, scheduledAt: $scheduledAt) { _id topics users targets - deliveryTime + scheduledAt deliveredAt deliveryErrors deliveredTotal @@ -2113,13 +2113,13 @@ trait Base } }'; case self::$CREATE_SMS: - return 'mutation createSMS($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $content: String!, $status: String, $description: String, $deliveryTime: String) { - messagingCreateSMS(messageId: $messageId, topics: $topics, users: $users, targets: $targets, content: $content, status: $status, description: $description, deliveryTime: $deliveryTime) { + return 'mutation createSMS($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $content: String!, $status: String, $description: String, $scheduledAt: String) { + messagingCreateSMS(messageId: $messageId, topics: $topics, users: $users, targets: $targets, content: $content, status: $status, description: $description, scheduledAt: $scheduledAt) { _id topics users targets - deliveryTime + scheduledAt deliveredAt deliveryErrors deliveredTotal @@ -2128,13 +2128,13 @@ trait Base } }'; case self::$CREATE_PUSH_NOTIFICATION: - return 'mutation createPushNotification($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $title: String!, $body: String!, $data: Json, $action: String, $icon: String, $sound: String, $color: String, $tag: String, $badge: String, $status: String, $description: String, $deliveryTime: String) { - messagingCreatePushNotification(messageId: $messageId, topics: $topics, users: $users, targets: $targets, title: $title, body: $body, data: $data, action: $action, icon: $icon, sound: $sound, color: $color, tag: $tag, badge: $badge, status: $status, description: $description, deliveryTime: $deliveryTime) { + return 'mutation createPushNotification($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $title: String!, $body: String!, $data: Json, $action: String, $icon: String, $sound: String, $color: String, $tag: String, $badge: String, $status: String, $description: String, $scheduledAt: String) { + messagingCreatePushNotification(messageId: $messageId, topics: $topics, users: $users, targets: $targets, title: $title, body: $body, data: $data, action: $action, icon: $icon, sound: $sound, color: $color, tag: $tag, badge: $badge, status: $status, description: $description, scheduledAt: $scheduledAt) { _id topics users targets - deliveryTime + scheduledAt deliveredAt deliveryErrors deliveredTotal @@ -2148,10 +2148,11 @@ trait Base total messages { _id + providerType topics users targets - deliveryTime + scheduledAt deliveredAt deliveryErrors deliveredTotal @@ -2164,10 +2165,11 @@ trait Base return 'query getMessage($messageId: String!) { messagingGetMessage(messageId: $messageId) { _id + providerType topics users targets - deliveryTime + scheduledAt deliveredAt deliveryErrors deliveredTotal @@ -2176,13 +2178,13 @@ trait Base } }'; case self::$UPDATE_EMAIL: - return 'mutation updateEmail($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $subject: String, $content: String, $status: String, $description: String, $html: Boolean, $deliveryTime: String) { - messagingUpdateEmail(messageId: $messageId, topics: $topics, users: $users, targets: $targets, subject: $subject, content: $content, status: $status, description: $description, html: $html, deliveryTime: $deliveryTime) { + return 'mutation updateEmail($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $subject: String, $content: String, $status: String, $description: String, $html: Boolean, $scheduledAt: String) { + messagingUpdateEmail(messageId: $messageId, topics: $topics, users: $users, targets: $targets, subject: $subject, content: $content, status: $status, description: $description, html: $html, scheduledAt: $scheduledAt) { _id topics users targets - deliveryTime + scheduledAt deliveredAt deliveryErrors deliveredTotal @@ -2191,13 +2193,13 @@ trait Base } }'; case self::$UPDATE_SMS: - return 'mutation updateSMS($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $content: String, $status: String, $description: String, $deliveryTime: String) { - messagingUpdateSMS(messageId: $messageId, topics: $topics, users: $users, targets: $targets, content: $content, status: $status, description: $description, deliveryTime: $deliveryTime) { + return 'mutation updateSMS($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $content: String, $status: String, $description: String, $scheduledAt: String) { + messagingUpdateSMS(messageId: $messageId, topics: $topics, users: $users, targets: $targets, content: $content, status: $status, description: $description, scheduledAt: $scheduledAt) { _id topics users targets - deliveryTime + scheduledAt deliveredAt deliveryErrors deliveredTotal @@ -2206,13 +2208,13 @@ trait Base } }'; case self::$UPDATE_PUSH_NOTIFICATION: - return 'mutation updatePushNotification($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $title: String, $body: String, $data: Json, $action: String, $icon: String, $sound: String, $color: String, $tag: String, $badge: String, $status: String, $description: String, $deliveryTime: String) { - messagingUpdatePushNotification(messageId: $messageId, topics: $topics, users: $users, targets: $targets, title: $title, body: $body, data: $data, action: $action, icon: $icon, sound: $sound, color: $color, tag: $tag, badge: $badge, status: $status, description: $description, deliveryTime: $deliveryTime) { + return 'mutation updatePushNotification($messageId: String!, $topics: [String!], $users: [String!], $targets: [String!], $title: String, $body: String, $data: Json, $action: String, $icon: String, $sound: String, $color: String, $tag: String, $badge: String, $status: String, $description: String, $scheduledAt: String) { + messagingUpdatePushNotification(messageId: $messageId, topics: $topics, users: $users, targets: $targets, title: $title, body: $body, data: $data, action: $action, icon: $icon, sound: $sound, color: $color, tag: $tag, badge: $badge, status: $status, description: $description, scheduledAt: $scheduledAt) { _id topics users targets - deliveryTime + scheduledAt deliveredAt deliveryErrors deliveredTotal @@ -2472,7 +2474,7 @@ trait Base protected string $stdout = ''; protected string $stderr = ''; - protected function packageCode($folder) + protected function packageCode($folder): void { Console::execute('cd ' . realpath(__DIR__ . "/../../../resources/functions") . "/$folder && tar --exclude code.tar.gz -czf code.tar.gz .", '', $this->stdout, $this->stderr); }