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(); $forceFull = $forceFull || $settings->getIpc()->getSlow();
} }
/** @psalm-trace $unserialized */
[$unserialized, $this->unlock] = yield Tools::timeoutWithDefault( [$unserialized, $this->unlock] = yield Tools::timeoutWithDefault(
Serialization::unserialize($this->session, $forceFull), Serialization::unserialize($this->session, $forceFull),
30000, 30000,

View File

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

View File

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

View File

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

View File

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

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']) { if (isset($update['message']['from_id']['user_id']) && $update['message']['from_id']['user_id'] === $this->authorization['user']['id']) {
$update['message']['out'] = true; $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 // First save to array, then once the feed loop signals resumal of loop, resume and handle
$this->updates[$this->updates_key++] = $update; $this->updates[$this->updates_key++] = $update;
} }

View File

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

View File

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

View File

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

View File

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