Polyfill to_id

This commit is contained in:
Daniil Gentili 2020-10-03 17:41:21 +02:00
parent 118cf244b1
commit cdeb93b165
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
11 changed files with 28 additions and 25 deletions

View File

@ -192,6 +192,7 @@ class API extends InternalDoc
$forceFull = $forceFull || $settings->getIpc()->getSlow();
}
/** @psalm-trace $unserialized */
[$unserialized, $this->unlock] = yield Tools::timeoutWithDefault(
Serialization::unserialize($this->session, $forceFull),
30000,

View File

@ -6153,12 +6153,12 @@ class InternalDoc extends APIFactory
* @template TReturn
* @template TGenerator as \Generator<mixed, mixed, mixed, TReturn>
*
* @param Promise<TReturn>|\Generator $promise Promise to which the timeout is applied.
* @param int $timeout Timeout in milliseconds.
* @param mixed $default
* @param Promise|Generator $promise Promise to which the timeout is applied.
* @param int $timeout Timeout in milliseconds.
* @param mixed $default
*
* @psalm-param Promise<TReturn>|TGenerator $promise Promise to which the timeout is applied.
* @psalm-param TReturnAlt $timeout
* @psalm-param TReturnAlt $default
*
* @return Promise<TReturn|TReturnAlt>
*

View File

@ -57,7 +57,7 @@ class FeedLoop extends ResumableSignalLoop
*/
private ?UpdateLoop $updater = null;
/**
* Update state
* Update state.
*/
private ?UpdatesState $state = null;
/**

View File

@ -31,7 +31,6 @@ class Lua
throw new Exception(\danog\MadelineProto\Lang::$current_lang['script_not_exist']);
}
$this->MadelineProto = $MadelineProto;
$this->MadelineProto->API->datacenter->sockets[$this->MadelineProto->getSettings()->getConnection()->getDefaultDc()]->startUpdateLoop();
$this->script = $script;
$this->__wakeup();
}
@ -84,7 +83,7 @@ class Lua
if ($params === 0) {
return 0;
}
$result = $this->MadelineProto->API->methodCall($params['_'], $params, ['datacenter' => $this->MadelineProto->API->datacenter->curdc]);
$result = $this->MadelineProto->API->methodCall($params['_'], $params);
if (\is_callable($cb)) {
$cb($this->MadelineProto->mtproto_to_td($result), $cb_extra);
}
@ -92,7 +91,7 @@ class Lua
}
public function madelineFunction($params, $cb = null, $cb_extra = null)
{
$result = $this->MadelineProto->API->methodCall($params['_'], $params, ['datacenter' => $this->MadelineProto->API->datacenter->curdc]);
$result = $this->MadelineProto->API->methodCall($params['_'], $params);
if (\is_callable($cb)) {
$cb($result, $cb_extra);
}

View File

@ -19,12 +19,13 @@
namespace danog\MadelineProto\MTProtoSession;
use danog\MadelineProto\Connection;
use danog\MadelineProto\MTProto;
/**
* Manages MTProto session-specific data.
*
* @property MTProto $API
* @extends Connection
*/
abstract class Session
{

View File

@ -637,8 +637,8 @@ trait PeerHandler
* @return (((mixed|string)[]|mixed|string)[]|int|mixed|string)[]
*
* @psalm-return array{
* InputPeer: array{_: string, user_id?: mixed, access_hash?: mixed, min?: mixed, chat_id?: mixed, channel_id?: mixed},
* Peer: array{_: string, user_id?: mixed, chat_id?: mixed, channel_id?: mixed},
* InputPeer: array{_: string, user_id?: mixed, access_hash?: mixed, min?: mixed, chat_id?: mixed, channel_id?: mixed},
* Peer: array{_: string, user_id?: mixed, chat_id?: mixed, channel_id?: mixed},
* DialogPeer: array{_: string, peer: array{_: string, user_id?: mixed, chat_id?: mixed, channel_id?: mixed}},
* NotifyPeer: array{_: string, peer: array{_: string, user_id?: mixed, chat_id?: mixed, channel_id?: mixed}},
* InputDialogPeer: array{_: string, peer: array{_: string, user_id?: mixed, access_hash?: mixed, min?: mixed, chat_id?: mixed, channel_id?: mixed}},
@ -647,8 +647,8 @@ trait PeerHandler
* user_id?: int,
* chat_id?: int,
* channel_id?: int,
* InputUser?: {_: string, user_id?: int, access_hash?: mixed, min?: bool},
* InputChannel?: {_: string, channel_id: int, access_hash: mixed, min: bool},
* InputUser?: {_: string, user_id?: int, access_hash?: mixed, min?: bool},
* InputChannel?: {_: string, channel_id: int, access_hash: mixed, min: bool},
* type: string
* }
*/

View File

@ -415,6 +415,9 @@ trait UpdateHandler
if (isset($update['message']['from_id']['user_id']) && $update['message']['from_id']['user_id'] === $this->authorization['user']['id']) {
$update['message']['out'] = true;
}
if (isset($update['message']['peer_id'])) {
$update['message']['to_id'] = $update['message']['peer_id'];
}
// First save to array, then once the feed loop signals resumal of loop, resume and handle
$this->updates[$this->updates_key++] = $update;
}

View File

@ -42,10 +42,9 @@ trait RawStream
{
if (\method_exists($this, 'endGenerator')) {
return \danog\MadelineProto\Tools::call($this->endGenerator($finalData));
} else {
$promise = $this->write($finalData);
$promise->onResolve(fn () => $this->disconnect());
return $promise;
}
$promise = $this->write($finalData);
$promise->onResolve(fn () => $this->disconnect());
return $promise;
}
}

View File

@ -200,7 +200,7 @@ trait TD
if ($key === '_') {
$newparams['ID'] = \ucfirst($value);
} else {
if (!\is_numeric($key) && !\preg_match('/_^/', $key)) {
if (!\is_numeric($key) && !str_ends_with($key, '_')) {
$key = $key.'_';
}
$newparams[$key] = $this->tdToTdcli($value);

View File

@ -1424,12 +1424,12 @@ class InternalDoc extends APIFactory
* @template TReturn
* @template TGenerator as \Generator<mixed, mixed, mixed, TReturn>
*
* @param Promise<TReturn>|\Generator $promise Promise to which the timeout is applied.
* @param int $timeout Timeout in milliseconds.
* @param mixed $default
* @param Promise|Generator $promise Promise to which the timeout is applied.
* @param int $timeout Timeout in milliseconds.
* @param mixed $default
*
* @psalm-param Promise<TReturn>|TGenerator $promise Promise to which the timeout is applied.
* @psalm-param TReturnAlt $timeout
* @psalm-param TReturnAlt $default
*
* @return Promise<TReturn|TReturnAlt>
*

View File

@ -422,9 +422,9 @@ abstract class Tools extends StrTools
* @template TReturn
* @template TGenerator as \Generator<mixed, mixed, mixed, TReturn>
*
* @param Promise<TReturn>|\Generator $promise Promise to which the timeout is applied.
* @param int $timeout Timeout in milliseconds.
* @param mixed $default
* @param Promise|Generator $promise Promise to which the timeout is applied.
* @param int $timeout Timeout in milliseconds.
* @param mixed $default
*
* @psalm-param Promise<TReturn>|TGenerator $promise Promise to which the timeout is applied.
* @psalm-param TReturnAlt $default