Beta features (#326)

* Experimental performance improvements

* Apply fixes from StyleCI

* Support passing numeric ids instead of InputMessage objects, support using t.me links for sendMessage and other methods

* Apply fixes from StyleCI
This commit is contained in:
Daniil Gentili 2018-03-08 12:28:03 +01:00 committed by GitHub
parent b5dba1ec3e
commit ea360c3d4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 4 deletions

View File

@ -47,7 +47,7 @@ class Connection
public $object_queue = []; public $object_queue = [];
public $ack_queue = []; public $ack_queue = [];
public $i = []; public $i = [];
public $must_open = false; public $must_open = true;
public $last_recv = 0; public $last_recv = 0;
public function __magic_construct($proxy, $extra, $ip, $port, $protocol, $timeout, $ipv6) public function __magic_construct($proxy, $extra, $ip, $port, $protocol, $timeout, $ipv6)

View File

@ -266,7 +266,7 @@ class MTProto
$this->channels_state = []; $this->channels_state = [];
$this->got_state = false; $this->got_state = false;
} }
$this->connect_to_all_dcs(); //$this->connect_to_all_dcs();
//datacenter->__construct($this->settings['connection'], $this->settings['connection_settings']); //datacenter->__construct($this->settings['connection'], $this->settings['connection_settings']);
foreach ($this->calls as $id => $controller) { foreach ($this->calls as $id => $controller) {
if (!is_object($controller)) { if (!is_object($controller)) {

View File

@ -85,7 +85,7 @@ trait MessageHandler
\danog\MadelineProto\Logger::log('Trying to read from closed socket, sending initial ping'); \danog\MadelineProto\Logger::log('Trying to read from closed socket, sending initial ping');
if ($this->is_http($datacenter)) { if ($this->is_http($datacenter)) {
$this->method_call('http_wait', ['max_wait' => 500, 'wait_after' => 150, 'max_delay' => 500], ['datacenter' => $datacenter]); $this->method_call('http_wait', ['max_wait' => 500, 'wait_after' => 150, 'max_delay' => 500], ['datacenter' => $datacenter]);
} else { } elseif (isset($this->datacenter->sockets[$datacenter]->temp_auth_key['connection_inited']) && $this->datacenter->sockets[$datacenter]->temp_auth_key['connection_inited']) {
$this->method_call('ping', ['ping_id' => 0], ['datacenter' => $datacenter]); $this->method_call('ping', ['ping_id' => 0], ['datacenter' => $datacenter]);
} }
} }

View File

@ -228,6 +228,19 @@ trait PeerHandler
throw new \danog\MadelineProto\Exception('This peer is not present in the internal peer database'); throw new \danog\MadelineProto\Exception('This peer is not present in the internal peer database');
} }
if (preg_match('@(?:t|telegram)\.(?:me|dog)/(joinchat/)?([a-z0-9_-]*)@i', $id, $matches)) {
if ($matches[1] === '') {
$id = $matches[2];
} else {
$invite = $this->method_call('messages.checkChatInvite', ['hash' => $matches[2]], ['datacenter' => $this->datacenter->curdc]);
var_dump($invite);
if (isset($invite['chat'])) {
return $this->get_info($invite['chat']);
} else {
throw new \danog\MadelineProto\Exception('You have not joined this chat');
}
}
}
$id = strtolower(str_replace('@', '', $id)); $id = strtolower(str_replace('@', '', $id));
foreach ($this->chats as $chat) { foreach ($this->chats as $chat) {
if (isset($chat['username']) && strtolower($chat['username']) === $id) { if (isset($chat['username']) && strtolower($chat['username']) === $id) {

View File

@ -298,6 +298,9 @@ trait ResponseHandler
if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['chats'])) { if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['chats'])) {
$this->add_chats($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['chats']); $this->add_chats($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['chats']);
} }
if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['chat'])) {
$this->add_chats([$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['chat']]);
}
if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['result']['users'])) { if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['result']['users'])) {
$this->add_users($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['result']['users']); $this->add_users($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['result']['users']);
} }

View File

@ -332,6 +332,9 @@ trait TL
} }
} }
$auto = false; $auto = false;
if (!is_array($object) && $type['type'] === 'InputMessage') {
$object = ['_' => 'inputMessageID', 'id' => $object];
}
if ((!is_array($object) || isset($object['_']) && $this->constructors->find_by_predicate($object['_'])['type'] !== $type['type']) && in_array($type['type'], ['User', 'InputUser', 'Chat', 'InputChannel', 'Peer', 'InputPeer'])) { if ((!is_array($object) || isset($object['_']) && $this->constructors->find_by_predicate($object['_'])['type'] !== $type['type']) && in_array($type['type'], ['User', 'InputUser', 'Chat', 'InputChannel', 'Peer', 'InputPeer'])) {
$object = $this->get_info($object); $object = $this->get_info($object);
if (!isset($object[$type['type']])) { if (!isset($object[$type['type']])) {

View File

@ -89,7 +89,7 @@ trait Login
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['login_user'], \danog\MadelineProto\Logger::NOTICE); \danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['login_user'], \danog\MadelineProto\Logger::NOTICE);
try { try {
$authorization = $this->method_call('auth.signIn', ['phone_number' => $this->authorization['phone_number'], 'phone_code_hash' => $this->authorization['phone_code_hash'], 'phone_code' => $code], ['datacenter' => $this->datacenter->curdc]); $authorization = $this->method_call('auth.signIn', ['phone_number' => $this->authorization['phone_number'], 'phone_code_hash' => $this->authorization['phone_code_hash'], 'phone_code' => (string) $code], ['datacenter' => $this->datacenter->curdc]);
} catch (\danog\MadelineProto\RPCErrorException $e) { } catch (\danog\MadelineProto\RPCErrorException $e) {
if ($e->rpc === 'SESSION_PASSWORD_NEEDED') { if ($e->rpc === 'SESSION_PASSWORD_NEEDED') {
\danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['login_2fa_enabled'], \danog\MadelineProto\Logger::NOTICE); \danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['login_2fa_enabled'], \danog\MadelineProto\Logger::NOTICE);