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

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

View File

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

View File

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

View File

@ -1037,7 +1037,7 @@ class TL
return $x['value']; return $x['value'];
} }
} elseif ($x['_'] === 'photoStrippedSize') { } 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['_']])) { if (isset($this->callbacks[TLCallback::CONSTRUCTOR_CALLBACK][$x['_']])) {
foreach ($this->callbacks[TLCallback::CONSTRUCTOR_CALLBACK][$x['_']] as $callback) { foreach ($this->callbacks[TLCallback::CONSTRUCTOR_CALLBACK][$x['_']] as $callback) {

View File

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