mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
Presence api response models
This commit is contained in:
parent
c6f16cde4a
commit
01c6cc86ce
3 changed files with 123 additions and 1 deletions
|
|
@ -2840,7 +2840,7 @@ return [
|
|||
'filters' => ['json'],
|
||||
],
|
||||
],
|
||||
// TODO: shall we create the perms_md5 now only for the upsertion based on perms_md5 or later via patch script?
|
||||
// TODO: shall we create the perms_md5 now only for the upsertion based on perms_md5 or later via patch script?
|
||||
// permissions must be sorted before md5 conversion to have deterministic hashes
|
||||
'indexes' => [
|
||||
[
|
||||
|
|
|
|||
|
|
@ -64,6 +64,8 @@ class Response extends SwooleResponse
|
|||
public const MODEL_COLUMN_INDEX_LIST = 'columnIndexList';
|
||||
public const MODEL_DOCUMENT = 'document';
|
||||
public const MODEL_DOCUMENT_LIST = 'documentList';
|
||||
public const MODEL_PRESENCE = 'presence';
|
||||
public const MODEL_PRESENCE_LIST = 'presenceList';
|
||||
public const MODEL_ROW = 'row';
|
||||
public const MODEL_ROW_LIST = 'rowList';
|
||||
|
||||
|
|
|
|||
120
src/Appwrite/Utopia/Response/Model/Presence.php
Normal file
120
src/Appwrite/Utopia/Response/Model/Presence.php
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Document as DatabaseDocument;
|
||||
|
||||
class Presence extends Any
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return 'Presence';
|
||||
}
|
||||
|
||||
public function getType(): string
|
||||
{
|
||||
return Response::MODEL_PRESENCE;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->addRule('$id', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Presence ID.',
|
||||
'default' => '',
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('$sequence', [
|
||||
'type' => self::TYPE_ID,
|
||||
'description' => 'Presence sequence ID.',
|
||||
'default' => '',
|
||||
'example' => '1',
|
||||
'readOnly' => true,
|
||||
])
|
||||
->addRule('$createdAt', [
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Presence creation date in ISO 8601 format.',
|
||||
'default' => '',
|
||||
'example' => self::TYPE_DATETIME_EXAMPLE,
|
||||
])
|
||||
->addRule('$updatedAt', [
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Presence update date in ISO 8601 format.',
|
||||
'default' => '',
|
||||
'example' => self::TYPE_DATETIME_EXAMPLE,
|
||||
])
|
||||
->addRule('$permissions', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Presence permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).',
|
||||
'default' => '',
|
||||
'example' => ['read("any")'],
|
||||
'array' => true,
|
||||
])
|
||||
->addRule('userInternalId', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'User internal ID.',
|
||||
'default' => '',
|
||||
'example' => '1',
|
||||
])
|
||||
->addRule('userId', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'User ID.',
|
||||
'default' => '',
|
||||
'example' => '674af8f3e12a5f9ac0be',
|
||||
])
|
||||
->addRule('status', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Presence status.',
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'example' => 'online',
|
||||
])
|
||||
->addRule('source', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Presence source.',
|
||||
'default' => '',
|
||||
'example' => 'HTTP',
|
||||
])
|
||||
->addRule('expiry', [
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Presence expiry date in ISO 8601 format.',
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'example' => self::TYPE_DATETIME_EXAMPLE,
|
||||
])
|
||||
// not adding hostname here in the response model
|
||||
->addRule('metadata', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Presence metadata.',
|
||||
'required' => false,
|
||||
'default' => [],
|
||||
'example' => ['device' => 'web'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function filter(DatabaseDocument $document): DatabaseDocument
|
||||
{
|
||||
$document->removeAttribute('$collection');
|
||||
$document->removeAttribute('$tenant');
|
||||
|
||||
if (!$document->isEmpty()) {
|
||||
$document->setAttribute('$sequence', (string) $document->getAttribute('$sequence', ''));
|
||||
}
|
||||
|
||||
foreach ($document->getAttributes() as $attribute) {
|
||||
if (\is_array($attribute)) {
|
||||
foreach ($attribute as $subAttribute) {
|
||||
if ($subAttribute instanceof DatabaseDocument) {
|
||||
$this->filter($subAttribute);
|
||||
}
|
||||
}
|
||||
} elseif ($attribute instanceof DatabaseDocument) {
|
||||
$this->filter($attribute);
|
||||
}
|
||||
}
|
||||
|
||||
return $document;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue