DAMN LOOK AT THE SPEED METER
This commit is contained in:
parent
d4975caa21
commit
5e9df575da
@ -44,7 +44,7 @@ class MTProto extends \Volatile
|
||||
use \danog\MadelineProto\Wrappers\DialogHandler;
|
||||
use \danog\MadelineProto\Wrappers\Login;
|
||||
|
||||
const V = 64;
|
||||
const V = 65;
|
||||
|
||||
const NOT_LOGGED_IN = 0;
|
||||
const WAITING_CODE = 1;
|
||||
|
@ -338,7 +338,6 @@ trait TL
|
||||
|
||||
}
|
||||
$auto = false;
|
||||
|
||||
if ((!$this->is_array($object) || (isset($object['_']) && $this->constructors->find_by_predicate($object['_'])['type'] !== $type['type'])) && $this->in_array($type['type'], ['User', 'InputUser', 'Chat', 'InputChannel', 'Peer', 'InputPeer'])) {
|
||||
$object = $this->get_info($object);
|
||||
if (!isset($object[$type['type']])) {
|
||||
@ -348,6 +347,7 @@ trait TL
|
||||
}
|
||||
if (!isset($object['_'])) {
|
||||
$constructorData = $this->constructors->find_by_predicate($type['type'], $layer);
|
||||
|
||||
if ($constructorData === false) {
|
||||
throw new Exception('Predicate was not set!');
|
||||
}
|
||||
|
@ -18,78 +18,75 @@ class TLConstructor extends \Volatile
|
||||
use \danog\MadelineProto\Tools;
|
||||
use TLParams;
|
||||
|
||||
public $id = [];
|
||||
public $predicate = [];
|
||||
public $type = [];
|
||||
public $params = [];
|
||||
public $layer = [];
|
||||
public $key = 0;
|
||||
public $by_id = [];
|
||||
public $by_predicate_and_layer = [];
|
||||
public $layers = [];
|
||||
//public $type = [];
|
||||
//public $params = [];
|
||||
//public $layer = [];
|
||||
//public $key = 0;
|
||||
|
||||
public function __sleep()
|
||||
{
|
||||
return ['id', 'predicate', 'type', 'params', 'layer', 'key'];
|
||||
return ['by_predicate_and_layer', 'by_id', 'layers'];
|
||||
}
|
||||
|
||||
public function add($json_dict, $scheme_type)
|
||||
{
|
||||
$this->id[$this->key] = $json_dict['id'];
|
||||
$this->predicate[$this->key] = (string) ((($scheme_type === 'mtproto' && $json_dict['predicate'] === 'message') ? 'MT' : '').$json_dict['predicate']);
|
||||
$this->type[$this->key] = (($scheme_type === 'mtproto' && $json_dict['type'] === 'Message') ? 'MT' : '').$json_dict['type'];
|
||||
$this->params[$this->key] = $json_dict['params'];
|
||||
$predicate = (string) ((($scheme_type === 'mtproto' && $json_dict['predicate'] === 'message') ? 'MT' : '').$json_dict['predicate']);
|
||||
$this->by_id[$json_dict['id']] = ['predicate' => $predicate, 'params' => $json_dict['params'], 'type' => (($scheme_type === 'mtproto' && $json_dict['type'] === 'Message') ? 'MT' : '').$json_dict['type']];
|
||||
if ($scheme_type === 'secret') {
|
||||
$this->layer[$this->key] = $json_dict['layer'];
|
||||
}
|
||||
$this->parse_params($this->key, $scheme_type === 'mtproto');
|
||||
$this->key++;
|
||||
$this->by_id[$json_dict['id']]['layer'] = $json_dict['layer'];
|
||||
$this->layers[$json_dict['layer']] = $json_dict['layer'];
|
||||
ksort($this->layers);
|
||||
} else $json_dict['layer'] = '';
|
||||
$this->by_predicate_and_layer[$json_dict['predicate'].$json_dict['layer']] = $json_dict['id'];
|
||||
$this->parse_params($json_dict['id'], $scheme_type === 'mtproto');
|
||||
}
|
||||
|
||||
public function find_by_type($type)
|
||||
{
|
||||
$key = array_search($type, (array) $this->type, true);
|
||||
|
||||
return ($key === false) ? false : [
|
||||
'id' => $this->id[$key],
|
||||
'predicate' => $this->predicate[$key],
|
||||
'type' => $this->type[$key],
|
||||
'params' => $this->array_cast_recursive($this->params[$key]),
|
||||
];
|
||||
foreach ($this->by_id as $id => $constructor) {
|
||||
if ($constructor['type'] === $type) {
|
||||
$constructor['id'] = $id;
|
||||
$constructor['params'] = $this->array_cast_recursive($constructor['params']);
|
||||
return $constructor;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function find_by_predicate($predicate, $layer = -1)
|
||||
{
|
||||
if ($layer !== -1) {
|
||||
$newlayer = -1;
|
||||
$keys = array_keys((array) $this->predicate, $predicate);
|
||||
foreach ($keys as $k) {
|
||||
if ($this->layer[$k] <= $layer && $this->layer[$k] > $newlayer) {
|
||||
$key = $k;
|
||||
$newlayer = $this->layer[$k];
|
||||
}
|
||||
if (!isset($key)) {
|
||||
$key = $keys[0];
|
||||
foreach ($this->layers as $alayer) {
|
||||
if ($alayer <= $layer && isset($this->by_predicate_and_layer[$predicate.$alayer])) {
|
||||
$chosenid = $this->by_predicate_and_layer[$predicate.$alayer];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$key = array_search($predicate, (array) $this->predicate, true);
|
||||
if (!isset($chosenid)) return false;
|
||||
$constructor = $this->by_id[$chosenid];
|
||||
$constructor['id'] = $chosenid;
|
||||
$constructor['params'] = $this->array_cast_recursive($constructor['params']);
|
||||
return $constructor;
|
||||
}
|
||||
|
||||
return ($key === false) ? false : [
|
||||
'id' => $this->id[$key],
|
||||
'predicate' => $this->predicate[$key],
|
||||
'type' => $this->type[$key],
|
||||
'params' => $this->array_cast_recursive($this->params[$key]),
|
||||
];
|
||||
if (isset($this->by_predicate_and_layer[$predicate])) {
|
||||
$constructor = $this->by_id[$this->by_predicate_and_layer[$predicate]];
|
||||
$constructor['id'] = $this->by_predicate_and_layer[$predicate];
|
||||
$constructor['params'] = $this->array_cast_recursive($constructor['params']);
|
||||
return $constructor;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function find_by_id($id)
|
||||
{
|
||||
$key = array_search($id, (array) $this->id, true);
|
||||
|
||||
return ($key === false) ? false : [
|
||||
'id' => $this->id[$key],
|
||||
'predicate' => $this->predicate[$key],
|
||||
'type' => $this->type[$key],
|
||||
'params' => $this->array_cast_recursive($this->params[$key]),
|
||||
];
|
||||
if (isset($this->by_id[$id])) {
|
||||
$constructor = $this->by_id[$id];
|
||||
$constructor['id'] = $id;
|
||||
$constructor['params'] = $this->array_cast_recursive($constructor['params']);
|
||||
return $constructor;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -17,54 +17,49 @@ class TLMethod extends \Volatile
|
||||
use \danog\Serializable;
|
||||
use \danog\MadelineProto\Tools;
|
||||
use TLParams;
|
||||
public $id = [];
|
||||
public $method = [];
|
||||
public $type = [];
|
||||
public $params = [];
|
||||
public $by_id = [];
|
||||
public $by_method = [];
|
||||
public $method_namespace = [];
|
||||
public $key = 0;
|
||||
|
||||
public function __sleep()
|
||||
{
|
||||
return ['id', 'method', 'type', 'params', 'method_namespace', 'key'];
|
||||
return ['by_id', 'by_method', 'method_namespace'];
|
||||
}
|
||||
|
||||
public function add($json_dict)
|
||||
{
|
||||
$this->id[$this->key] = $json_dict['id'];
|
||||
$this->method[$this->key] = $json_dict['method'];
|
||||
$this->type[$this->key] = $json_dict['type'];
|
||||
$this->params[$this->key] = $json_dict['params'];
|
||||
$this->by_id[$json_dict['id']] = ['method' => $json_dict['method'], 'type' => $json_dict['type'], 'params' => $json_dict['params']];
|
||||
$this->by_method[$json_dict['method']] = $json_dict['id'];
|
||||
|
||||
$namespace = explode('.', $json_dict['method']);
|
||||
if (isset($namespace[1])) {
|
||||
$this->method_namespace[$namespace[1]] = $namespace[0];
|
||||
}
|
||||
|
||||
$this->parse_params($this->key);
|
||||
$this->key++;
|
||||
$this->parse_params($json_dict['id']);
|
||||
}
|
||||
|
||||
public function find_by_method($method)
|
||||
{
|
||||
$key = array_search($method, (array) $this->method, true);
|
||||
|
||||
return ($key === false) ? false : [
|
||||
'id' => $this->id[$key],
|
||||
'method' => $this->method[$key],
|
||||
'type' => $this->type[$key],
|
||||
'params' => $this->array_cast_recursive($this->params[$key]),
|
||||
];
|
||||
}
|
||||
|
||||
public function find_by_id($id)
|
||||
{
|
||||
$key = array_search($id, (array) $this->id, true);
|
||||
|
||||
return ($key === false) ? false : [
|
||||
'id' => $this->id[$key],
|
||||
'method' => $this->method[$key],
|
||||
'type' => $this->type[$key],
|
||||
'params' => $this->array_cast_recursive($this->params[$key]),
|
||||
];
|
||||
if (isset($this->by_id[$id])) {
|
||||
$method = $this->by_id[$id];
|
||||
$method['id'] = $id;
|
||||
$method['params'] = $this->array_cast_recursive($method['params']);
|
||||
return $method;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function find_by_method($method_name)
|
||||
{
|
||||
if (isset($this->by_method[$method_name])) {
|
||||
$method = $this->by_id[$this->by_method[$method_name]];
|
||||
$method['id'] = $this->by_method[$method_name];
|
||||
$method['params'] = $this->array_cast_recursive($method['params']);
|
||||
return $method;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ trait TLParams
|
||||
{
|
||||
public function parse_params($key, $mtproto = false)
|
||||
{
|
||||
foreach ($this->params[$key] as $kkey => $param) {
|
||||
foreach ($this->by_id[$key]['params'] as $kkey => $param) {
|
||||
if (preg_match('/^flags\.\d*\?/', $param['type'])) {
|
||||
$flag = explode('?', explode('flags.', $param['type'])[1]);
|
||||
$param['pow'] = pow(2, $flag[0]);
|
||||
@ -36,7 +36,7 @@ trait TLParams
|
||||
}
|
||||
$param['type'] = (($mtproto && $param['type'] === 'Message') ? 'MT' : '').$param['type'];
|
||||
$param['type'] = (($mtproto && $param['type'] === '%Message') ? '%MTMessage' : $param['type']);
|
||||
$this->params[$key][$kkey] = $param;
|
||||
$this->by_id[$key]['params'][$kkey] = $param;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user