diff --git a/src/danog/MadelineProto/API.php b/src/danog/MadelineProto/API.php index f371ab49..0542805c 100644 --- a/src/danog/MadelineProto/API.php +++ b/src/danog/MadelineProto/API.php @@ -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, diff --git a/src/danog/MadelineProto/InternalDoc.php b/src/danog/MadelineProto/InternalDoc.php index dc28470e..0d8ce906 100644 --- a/src/danog/MadelineProto/InternalDoc.php +++ b/src/danog/MadelineProto/InternalDoc.php @@ -6153,12 +6153,12 @@ class InternalDoc extends APIFactory * @template TReturn * @template TGenerator as \Generator * - * @param Promise|\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|TGenerator $promise Promise to which the timeout is applied. - * @psalm-param TReturnAlt $timeout + * @psalm-param TReturnAlt $default * * @return Promise * diff --git a/src/danog/MadelineProto/Loop/Update/FeedLoop.php b/src/danog/MadelineProto/Loop/Update/FeedLoop.php index ab336719..79f0f4e8 100644 --- a/src/danog/MadelineProto/Loop/Update/FeedLoop.php +++ b/src/danog/MadelineProto/Loop/Update/FeedLoop.php @@ -57,7 +57,7 @@ class FeedLoop extends ResumableSignalLoop */ private ?UpdateLoop $updater = null; /** - * Update state + * Update state. */ private ?UpdatesState $state = null; /** diff --git a/src/danog/MadelineProto/Lua.php b/src/danog/MadelineProto/Lua.php index fa60f3ef..0f434dbd 100644 --- a/src/danog/MadelineProto/Lua.php +++ b/src/danog/MadelineProto/Lua.php @@ -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); } diff --git a/src/danog/MadelineProto/MTProtoSession/Session.php b/src/danog/MadelineProto/MTProtoSession/Session.php index ec844bc0..769c266a 100644 --- a/src/danog/MadelineProto/MTProtoSession/Session.php +++ b/src/danog/MadelineProto/MTProtoSession/Session.php @@ -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 { diff --git a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php index 1b0a1768..0238b4f8 100644 --- a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php @@ -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 * } */ diff --git a/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php b/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php index 3c8efb6e..ea913f39 100644 --- a/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php @@ -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; } diff --git a/src/danog/MadelineProto/Stream/Async/RawStream.php b/src/danog/MadelineProto/Stream/Async/RawStream.php index 4b63af5a..4d1d9159 100644 --- a/src/danog/MadelineProto/Stream/Async/RawStream.php +++ b/src/danog/MadelineProto/Stream/Async/RawStream.php @@ -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; } } diff --git a/src/danog/MadelineProto/TL/Conversion/TD.php b/src/danog/MadelineProto/TL/Conversion/TD.php index 2ebd0dbb..be5bf3c7 100644 --- a/src/danog/MadelineProto/TL/Conversion/TD.php +++ b/src/danog/MadelineProto/TL/Conversion/TD.php @@ -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); diff --git a/src/danog/MadelineProto/TON/InternalDoc.php b/src/danog/MadelineProto/TON/InternalDoc.php index e01ce61d..2045750e 100644 --- a/src/danog/MadelineProto/TON/InternalDoc.php +++ b/src/danog/MadelineProto/TON/InternalDoc.php @@ -1424,12 +1424,12 @@ class InternalDoc extends APIFactory * @template TReturn * @template TGenerator as \Generator * - * @param Promise|\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|TGenerator $promise Promise to which the timeout is applied. - * @psalm-param TReturnAlt $timeout + * @psalm-param TReturnAlt $default * * @return Promise * diff --git a/src/danog/MadelineProto/Tools.php b/src/danog/MadelineProto/Tools.php index 9c331e15..4ee915f0 100644 --- a/src/danog/MadelineProto/Tools.php +++ b/src/danog/MadelineProto/Tools.php @@ -422,9 +422,9 @@ abstract class Tools extends StrTools * @template TReturn * @template TGenerator as \Generator * - * @param Promise|\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|TGenerator $promise Promise to which the timeout is applied. * @psalm-param TReturnAlt $default