1
0
Fork 0
mirror of synced 2024-06-26 10:10:57 +12:00

review changes

This commit is contained in:
prateek banga 2023-10-20 17:02:13 +05:30
parent e040ecba36
commit af40c63357
4 changed files with 19 additions and 26 deletions

View file

@ -1367,9 +1367,9 @@ App::delete('/v1/messaging/topics/:topicId')
->label('sdk.response.model', Response::MODEL_NONE)
->param('topicId', '', new UID(), 'Topic ID.')
->inject('dbForProject')
->inject('deletes')
->inject('queueForDeletes')
->inject('response')
->action(function (string $topicId, Database $dbForProject, Delete $deletes, Response $response) {
->action(function (string $topicId, Database $dbForProject, Delete $queueForDeletes, Response $response) {
$topic = $dbForProject->getDocument('topics', $topicId);
if ($topic->isEmpty()) {
@ -1378,7 +1378,7 @@ App::delete('/v1/messaging/topics/:topicId')
$dbForProject->deleteDocument('topics', $topicId);
$deletes
$queueForDeletes
->setType(DELETE_TYPE_SUBSCRIBERS)
->setDocument($topic);
@ -1589,7 +1589,7 @@ App::post('/v1/messaging/messages/email')
->inject('project')
->inject('queueForMessaging')
->inject('response')
->action(function (string $messageId, string $providerId, array $to, string $subject, string $description, string $content, string $status, bool $html, ?string $deliveryTime, Database $dbForProject, Document $project, Messaging $queueForMessaging, Response $response) {
->action(function (string $messageId, string $providerId, array $to, string $subject, string $content, string $description, string $status, bool $html, ?string $deliveryTime, Database $dbForProject, Document $project, Messaging $queueForMessaging, Response $response) {
$messageId = $messageId == 'unique()' ? ID::unique() : $messageId;
$provider = $dbForProject->getDocument('providers', $providerId);
@ -1916,12 +1916,13 @@ App::patch('/v1/messaging/messages/email/:messageId')
}
$message->setAttribute('data', $data);
$message->setAttribute('search', $message->getId() . ' ' . $data['description'] . ' ' . $data['subject'] . ' ' . $message->getAttribute('providerId'));
if (!empty($description)) {
$message->setAttribute('description', $description);
}
$message->setAttribute('search', $message->getId() . ' ' . $message->getAttribute('description') . ' ' . $data['subject'] . ' ' . $message->getAttribute('providerId'));
if (!empty($status)) {
$message->setAttribute('status', $status);
}
@ -1992,7 +1993,6 @@ App::patch('/v1/messaging/messages/sms/:messageId')
}
$message->setAttribute('data', $data);
$message->setAttribute('search', $message->getId() . ' ' . $data['description'] . ' ' . $message->getAttribute('providerId'));
if (!empty($status)) {
$message->setAttribute('status', $status);
@ -2006,6 +2006,8 @@ App::patch('/v1/messaging/messages/sms/:messageId')
$message->setAttribute('deliveryTime', $deliveryTime);
}
$message->setAttribute('search', $message->getId() . ' ' . $message->getAttribute('description') . ' ' . $message->getAttribute('providerId'));
$message = $dbForProject->updateDocument('messages', $message->getId(), $message);
if ($status === 'processing') {
@ -2107,7 +2109,6 @@ App::patch('/v1/messaging/messages/push/:messageId')
}
$message->setAttribute('data', $pushData);
$message->setAttribute('search', $message->getId() . ' ' . $pushData['description'] . ' ' . $pushData['title'] . ' ' . $message->getAttribute('providerId'));
if (!empty($status)) {
$message->setAttribute('status', $status);
@ -2121,6 +2122,8 @@ App::patch('/v1/messaging/messages/push/:messageId')
$message->setAttribute('deliveryTime', $deliveryTime);
}
$message->setAttribute('search', $message->getId() . ' ' . $message->getAttribute('description') . ' ' . $pushData['title'] . ' ' . $message->getAttribute('providerId'));
$message = $dbForProject->updateDocument('messages', $message->getId(), $message);
if ($status === 'processing') {

View file

@ -398,8 +398,7 @@ App::post('/v1/users/:userId/targets')
->param('identifier', '', new Text(Database::LENGTH_KEY), 'The target identifier (token, email, phone etc.)')
->inject('response')
->inject('dbForProject')
->inject('events')
->action(function (string $userId, string $targetId, string $providerId, string $identifier, Response $response, Database $dbForProject, Event $events) {
->action(function (string $userId, string $targetId, string $providerId, string $identifier, Response $response, Database $dbForProject) {
$provider = $dbForProject->getDocument('providers', $providerId);
if ($provider->isEmpty()) {
@ -1217,8 +1216,7 @@ App::patch('/v1/users/:userId/targets/:targetId/identifier')
->param('identifier', '', new Text(Database::LENGTH_KEY), 'The target identifier (token, email, phone etc.)')
->inject('response')
->inject('dbForProject')
->inject('events')
->action(function (string $userId, string $targetId, string $identifier, Response $response, Database $dbForProject, Event $events) {
->action(function (string $userId, string $targetId, string $identifier, Response $response, Database $dbForProject) {
$user = $dbForProject->getDocument('users', $userId);
@ -1241,10 +1239,6 @@ App::patch('/v1/users/:userId/targets/:targetId/identifier')
$target = $dbForProject->updateDocument('targets', $target->getId(), $target);
$dbForProject->deleteCachedDocument('users', $user->getId());
$events
->setParam('userId', $userId)
->setParam('targetId', $targetId);
$response
->dynamic($target, Response::MODEL_TARGET);
});
@ -1396,8 +1390,7 @@ App::delete('/v1/users/:userId/targets/:targetId')
->param('targetId', '', new UID(), 'Target ID.')
->inject('response')
->inject('dbForProject')
->inject('events')
->action(function (string $userId, string $targetId, Response $response, Database $dbForProject, Event $events) {
->action(function (string $userId, string $targetId, Response $response, Database $dbForProject) {
$user = $dbForProject->getDocument('users', $userId);

View file

@ -12,7 +12,6 @@ use Appwrite\Event\Func;
use Appwrite\Event\Mail;
use Appwrite\Event\Messaging;
use Appwrite\Event\Migration;
use Appwrite\Event\Phone;
use Appwrite\Platform\Appwrite;
use Appwrite\Usage\Stats;
use Swoole\Runtime;

View file

@ -29,8 +29,6 @@ use Utopia\Messaging\Messages\SMS;
use function Swoole\Coroutine\batch;
require_once __DIR__ . '/../init.php';
class Messaging extends Action
{
protected ?SMSAdapter $sms = null;
@ -78,10 +76,10 @@ class Messaging extends Action
$provider = $dbForProject->getDocument('providers', $message->getAttribute('providerId'));
$this->processMessage($message, $provider);
$this->processMessage($dbForProject, $message, $provider);
}
private function processMessage(Document $message, Document $provider): void
private function processMessage(Database $dbForProject, Document $message, Document $provider): void
{
$adapter = match ($provider->getAttribute('type')) {
'sms' => $this->sms($provider),
@ -97,17 +95,17 @@ class Messaging extends Action
*/
$recipients = [];
$topics = $this->dbForProject->find('topics', [Query::equal('$id', $recipientsId)]);
$topics = $dbForProject->find('topics', [Query::equal('$id', $recipientsId)]);
foreach ($topics as $topic) {
$recipients = \array_merge($recipients, $topic->getAttribute('targets'));
}
$users = $this->dbForProject->find('users', [Query::equal('$id', $recipientsId)]);
$users = $dbForProject->find('users', [Query::equal('$id', $recipientsId)]);
foreach ($users as $user) {
$recipients = \array_merge($recipients, $user->getAttribute('targets'));
}
$targets = $this->dbForProject->find('targets', [Query::equal('$id', $recipientsId)]);
$targets = $dbForProject->find('targets', [Query::equal('$id', $recipientsId)]);
$recipients = \array_merge($recipients, $targets);
$recipients = \array_filter($recipients, function (Document $recipient) use ($provider) {
return $recipient->getAttribute('providerId') === $provider->getId();
@ -165,7 +163,7 @@ class Messaging extends Action
$message->setAttribute('deliveredTo', $deliveredTo);
$message->setAttribute('deliveredAt', DateTime::now());
$this->dbForProject->updateDocument('messages', $message->getId(), $message);
$dbForProject->updateDocument('messages', $message->getId(), $message);
}
public function shutdown(): void