Avoid JSON issues with request field and inflated photo payloads

This commit is contained in:
Daniil Gentili 2020-09-13 01:06:08 +02:00
parent 22dd19a9de
commit d3dc7a0155
8 changed files with 17 additions and 8 deletions

View File

@ -14,7 +14,7 @@ interface DbArray extends DbType, \ArrayAccess, \Countable
public function offsetUnset($offset): Promise;
public function count(): Promise;
public function getIterator(): Producer;
/**
* @deprecated
* @internal

View File

@ -5,7 +5,6 @@ namespace danog\MadelineProto\Db\Driver;
use Amp\Redis\Config;
use Amp\Redis\Redis as RedisRedis;
use Amp\Redis\RemoteExecutorFactory;
use Amp\Sql\Common\ConnectionPool;
class Redis
{

View File

@ -18,7 +18,7 @@ abstract class DriverArray implements DbArray
{
throw new \RuntimeException('Native isset not support promises. Use isset method');
}
abstract protected function initConnection(array $settings): \Generator;
/**

View File

@ -21,7 +21,7 @@ class MysqlArray extends SqlArray
{
return ['table', 'settings'];
}
/**
* Check if key isset.
*

View File

@ -476,7 +476,14 @@ trait ResponseHandler
}
$botAPI = isset($request['botAPI']) && $request['botAPI'];
if (isset($response['_']) && !$this->isCdn() && $this->API->getTL()->getConstructors()->findByPredicate($response['_'])['type'] === 'Updates') {
$response['request'] = ['_' => $request['_'], 'body' => $request['body'] ?? []];
$body = [];
if (isset($request['body']['peer'])) {
$body['peer'] = $this->API->getID($request['body']['peer']);
}
if (isset($request['body']['message'])) {
$body['message'] = (string) $request['body']['message'];
}
$response['request'] = ['_' => $request['_'], 'body' => $body];
\danog\MadelineProto\Tools::callForkDefer($this->API->handleUpdates($response));
}
unset($request);

View File

@ -194,11 +194,11 @@ trait BotAPI
case 'updateShortSentMessage':
$newd['message_id'] = $data['id'];
$newd['date'] = $data['date'];
$newd['text'] = $data['request']['message'];
$newd['text'] = $data['request']['body']['message'];
if ($data['out']) {
$newd['from'] = (yield from $this->getPwrChat($this->authorization['user']));
}
$newd['chat'] = yield from $this->getPwrChat($data['request']['peer']);
$newd['chat'] = yield from $this->getPwrChat($data['request']['body']['peer']);
if (isset($data['entities'])) {
$newd['entities'] = yield from $this->MTProtoToBotAPI($data['entities']);
}

View File

@ -1037,7 +1037,7 @@ class TL
return $x['value'];
}
} elseif ($x['_'] === 'photoStrippedSize') {
$x['inflated'] = Tools::inflateStripped($x['bytes']);
$x['inflated'] = new Types\Bytes(Tools::inflateStripped($x['bytes']));
}
if (isset($this->callbacks[TLCallback::CONSTRUCTOR_CALLBACK][$x['_']])) {
foreach ($this->callbacks[TLCallback::CONSTRUCTOR_CALLBACK][$x['_']] as $callback) {

View File

@ -9,6 +9,9 @@ use danog\MadelineProto\Lang;
*/
function mergeExtracted(): void
{
if (!\file_exists('extracted.json')) {
return;
}
foreach (\json_decode(\file_get_contents('extracted.json'), true) as $key => $value) {
$key = \preg_replace(['|flags\.\d+[?]|', '/Vector[<].*/'], ['', 'Vector t'], $key);
$key = \str_replace('param_hash_type_int', 'param_hash_type_Vector t', $key);