Skip to content

Commit

Permalink
Update current blocks and actions
Browse files Browse the repository at this point in the history
  • Loading branch information
galchenkov committed Oct 20, 2020
1 parent fd16378 commit 3ce030d
Show file tree
Hide file tree
Showing 6 changed files with 821 additions and 50 deletions.
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@
],
"minimum-stability": "dev",
"require": {
"php": ">=5.3.0",
"firebase/php-jwt": "dev-master"
"php": ">=7",
"firebase/php-jwt": "dev-master",
"ext-json": "*"
},
"autoload": {
"psr-0": {
"Chatium": "src/"
},
"files": [
"src/Chatium/Actions.php",
"src/Chatium/Blocks.php",
"src/Chatium/Context.php",
"src/Chatium/Responses.php",
"src/Chatium/Actions.php",
"src/Chatium/Context.php"
"src/Chatium/Types.php"
]
}
}
219 changes: 205 additions & 14 deletions src/Chatium/Actions.php
Original file line number Diff line number Diff line change
@@ -1,36 +1,227 @@
<?php namespace Chatium\Actions;

function apiCall($url, $apiParams = [], $options = [])
/**
* @param string $url
* @param array $apiParams
* @param array $props
* @return array
*/
function apiCall(string $url, array $apiParams = [], array $props = [])
{
return array_merge(
['type' => 'apiCall', 'url' => $url, 'apiParams' => $apiParams],
isset($options['confirm']) ? ['confirm' => $options['confirm']] : [],
isset($options['sendPlayerState']) ? ['sendPlayerState' => $options['sendPlayerState']] : [],
);
$action = ['type' => 'apiCall', 'url' => $url, 'apiParams' => $apiParams];

if (isset($props['confirm'])) $action['confirm'] = $props['confirm'];
if (isset($props['sendPlayerState'])) $action['sendPlayerState'] = $props['sendPlayerState'];

return $action;
}

function showToast($toast)
/**
* @param string $filePutUrl
* @param array $props
* @return array
*/
function attachMedia(string $filePutUrl, array $props = [])
{
return [
'type' => 'showToast',
'toast' => $toast,
];
$action = ['type' => 'attachMedia', 'filePutUrl' => $filePutUrl];

if (isset($props['menuTitle'])) $action['menuTitle'] = $props['menuTitle'];
if (isset($props['progressTitle'])) $action['progressTitle'] = $props['progressTitle'];
if (isset($props['multiple'])) $action['multiple'] = $props['multiple'];
if (isset($props['mediaType'])) $action['mediaType'] = $props['mediaType'];
if (isset($props['submitUrl'])) $action['submitUrl'] = $props['submitUrl'];
if (isset($props['file'])) $action['file'] = $props['file'];

return $action;
}

function copyToClipboard($value)
/**
* @return array
*/
function confirmEmail()
{
return ['type' => 'confirmEmail'];
}

/**
* @return array
*/
function confirmPhone()
{
return ['type' => 'confirmPhone'];
}

/**
* @param string $value
* @return array
*/
function copyToClipboard(string $value)
{
return [
'type' => 'copyToClipboard',
'value' => $value,
];
}

function updateCurrentScreenBlock($blockId, $data, $merge = true)
/**
* @return array
*/
function goBack()
{
return ['type' => 'goBack'];
}

/**
* @param string $url
* @param array $props
* @return array
*/
function navigate(string $url, array $props = [])
{
$action = ['type' => 'navigate', 'url' => $url];

if (isset($props['replace'])) $action['replace'] = $props['replace'];
if (isset($props['openInExternalApp'])) $action['openInExternalApp'] = $props['openInExternalApp'];
if (isset($props['openInModalScreen'])) $action['openInModalScreen'] = $props['openInModalScreen'];
if (isset($props['fullScreenModal'])) $action['fullScreenModal'] = $props['fullScreenModal'];
if (isset($props['openInCurrentScreen'])) $action['openInCurrentScreen'] = $props['openInCurrentScreen'];
if (isset($props['openInBrowser'])) $action['openInBrowser'] = $props['openInBrowser'];
if (isset($props['resetStack'])) $action['resetStack'] = $props['resetStack'];

return $action;
}

/**
* @param string $galleryId
* @return array
*/
function nextSlide(string $galleryId)
{
return [
'type' => 'gallery:nextSlide',
'galleryId' => $galleryId,
];
}

/**
* @return array
*/
function noop()
{
return ['type' => 'noop'];
}

/**
* @param array $media
* @return array
*/
function preloadMedia(array $media)
{
return [
'type' => 'preloadMedia',
'media' => $media,
];
}

/**
* @return array
*/
function refresh()
{
return ['type' => 'refresh'];
}

/**
* @param string $token
* @param int $amount
* @param string $description
* @param string $integration
* @param array $payload
* @return array
*/
function requestPayment(string $token, int $amount, string $description, string $integration, array $payload = [])
{
return [
'type' => 'requestPayment',
'token' => $token,
'amount' => $amount,
'description' => $description,
'integration' => $integration,
'payload' => $payload,
];
}

/**
* @return array
*/
function resetSearch()
{
return ['type' => 'resetSearch'];
}

/**
* @param string $url
* @return array
*/
function selectContacts(string $url)
{
return ['type' => 'selectContacts', 'url' => $url];
}

/**
* @param array $menu
* @return array
*/
function showContextMenu(array $menu)
{
return ['type' => 'showContextMenu', 'menu' => $menu];
}

/**
* @param string $submitUrl
* @param array $props
* @return array
*/
function showTextDialog(string $submitUrl, array $props)
{
$type = [
'type' => 'showTextDialog',
'inputType' => 'text',
'submitUrl' => $submitUrl
];

if (isset($props['title'])) $type['title'] = $props['title'];
if (isset($props['description'])) $type['description'] = $props['description'];
if (isset($props['submitButtonTitle'])) $type['submitButtonTitle'] = $props['submitButtonTitle'];
if (isset($props['cancelButtonTitle'])) $type['cancelButtonTitle'] = $props['cancelButtonTitle'];

return $type;
}

/**
* @param string $toast
* @return array
*/
function showToast(string $toast)
{
return [
'type' => 'showToast',
'toast' => $toast,
];
}

/**
* @param string $blockId
* @param array $update
* @param bool $merge
* @return array
*/
function updateCurrentScreenBlock(string $blockId, array $update, bool $merge = true)
{
return [
'type' => 'updateCurrentScreenBlock',
'blockId' => $blockId,
'data' => $data,
'update' => $update,
'merge' => $merge,
];
}
Loading

0 comments on commit 3ce030d

Please sign in to comment.