2016-12-23 12:19:13 +01:00
< ? php
2018-02-24 17:54:13 +01:00
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
/**
* PeerHandler module .
*
* This file is part of MadelineProto .
* MadelineProto is free software : you can redistribute it and / or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation , either version 3 of the License , or ( at your option ) any later version .
* MadelineProto is distributed in the hope that it will be useful , but WITHOUT ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE .
* See the GNU Affero General Public License for more details .
* You should have received a copy of the GNU General Public License along with MadelineProto .
* If not , see < http :// www . gnu . org / licenses />.
*
* @ author Daniil Gentili < daniil @ daniil . it >
2020-02-17 14:13:46 +01:00
* @ copyright 2016 - 2020 Daniil Gentili < daniil @ daniil . it >
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
* @ license https :// opensource . org / licenses / AGPL - 3.0 AGPLv3
*
2019-10-31 15:07:35 +01:00
* @ link https :// docs . madelineproto . xyz MadelineProto documentation
2018-08-30 19:58:58 +02:00
*/
2018-02-24 17:54:39 +01:00
2016-12-23 12:19:13 +01:00
namespace danog\MadelineProto\MTProtoTools ;
2019-12-13 13:29:53 +01:00
use Amp\Http\Client\Request ;
2020-10-18 14:46:34 +02:00
use Amp\Promise ;
2020-02-09 16:24:57 +01:00
use danog\Decoder\FileId ;
use danog\Decoder\PhotoSizeSource\PhotoSizeSourceDialogPhoto ;
2020-05-03 03:33:54 +02:00
use danog\MadelineProto\Db\DbArray ;
2020-09-22 11:48:12 +02:00
use danog\MadelineProto\Settings ;
2020-10-01 18:02:54 +02:00
use danog\MadelineProto\Tools ;
2020-02-09 16:24:57 +01:00
use const danog\Decoder\PROFILE_PHOTO ;
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
2016-12-23 12:19:13 +01:00
/**
2016-12-23 12:19:37 +01:00
* Manages peers .
2020-09-22 11:48:12 +02:00
*
* @ property Settings $settings Settings
2016-12-23 12:19:13 +01:00
*/
trait PeerHandler
{
2019-04-29 16:42:08 +02:00
public $caching_simple = [];
public $caching_simple_username = [];
public $caching_possible_username = [];
2019-09-14 16:59:34 +02:00
public $caching_full_info = [];
2020-04-27 02:21:18 +02:00
2019-12-27 20:29:22 +01:00
/**
* Convert MTProto channel ID to bot API channel ID .
*
* @ param int $id MTProto channel ID
*
2020-10-01 21:36:07 +02:00
* @ return float | int
2019-12-27 20:29:22 +01:00
*/
public static function toSupergroup ( $id )
2018-03-04 00:41:26 +01:00
{
2019-09-02 17:08:36 +02:00
return - ( $id + \pow ( 10 , ( int ) \floor ( \log ( $id , 10 ) + 3 )));
2018-03-04 00:41:26 +01:00
}
2019-12-27 20:29:22 +01:00
/**
* Convert bot API channel ID to MTProto channel ID .
*
* @ param int $id Bot API channel ID
*
2020-10-01 21:36:07 +02:00
* @ return float | int
2019-12-27 20:29:22 +01:00
*/
2020-10-01 21:36:07 +02:00
public static function fromSupergroup ( $id )
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
{
2019-09-02 17:08:36 +02:00
return - $id - \pow ( 10 , ( int ) \floor ( \log ( - $id , 10 )));
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
}
2019-12-27 20:29:22 +01:00
/**
* Check whether provided bot API ID is a channel .
*
* @ param int $id Bot API ID
*
* @ return boolean
*/
public static function isSupergroup ( $id ) : bool
2018-03-04 00:41:26 +01:00
{
2019-09-02 17:08:36 +02:00
$log = \log ( - $id , 10 );
return ( $log - \intval ( $log )) * 1000 < 10 ;
2018-03-04 00:41:26 +01:00
}
2019-12-28 16:07:09 +01:00
/**
* Set support info .
*
* @ param array $support Support info
*
* @ internal
*
* @ return void
*/
public function addSupport ( array $support ) : void
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
{
$this -> supportUser = $support [ 'user' ][ 'id' ];
}
2020-05-03 03:33:54 +02:00
2019-12-28 16:07:09 +01:00
/**
* Add user info .
*
* @ param array $user User info
*
2020-05-03 03:33:54 +02:00
* @ return \Generator
* @ throws \danog\MadelineProto\Exception
2019-12-28 16:07:09 +01:00
*/
2020-05-03 03:33:54 +02:00
public function addUser ( array $user ) : \Generator
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
{
2020-05-03 03:33:54 +02:00
$existingChat = yield $this -> chats [ $user [ 'id' ]];
2020-05-09 00:47:12 +02:00
if ( $existingChat ) {
$this -> cacheChatUsername ( $user [ 'id' ], $user );
}
2019-09-14 15:31:52 +02:00
if ( ! isset ( $user [ 'access_hash' ]) && ! ( $user [ 'min' ] ? ? false )) {
2020-05-03 03:33:54 +02:00
if ( ! empty ( $existingChat [ 'access_hash' ])) {
2019-09-14 15:31:52 +02:00
$this -> logger -> logger ( " No access hash with user { $user [ 'id' ] } , using backup " );
2020-05-03 03:33:54 +02:00
$user [ 'access_hash' ] = $existingChat [ 'access_hash' ];
2019-09-14 15:39:42 +02:00
} elseif ( ! isset ( $this -> caching_simple [ $user [ 'id' ]]) && ! ( isset ( $user [ 'username' ]) && isset ( $this -> caching_simple_username [ $user [ 'username' ]]))) {
2019-04-29 16:42:08 +02:00
$this -> logger -> logger ( " No access hash with user { $user [ 'id' ] } , trying to fetch by ID... " );
2019-06-04 14:55:58 +02:00
if ( isset ( $user [ 'username' ]) && ! isset ( $this -> caching_simple_username [ $user [ 'username' ]])) {
$this -> caching_possible_username [ $user [ 'id' ]] = $user [ 'username' ];
}
2019-10-29 21:33:23 +01:00
$this -> cachePwrChat ( $user [ 'id' ], false , true );
2020-05-03 03:33:54 +02:00
} elseif ( isset ( $user [ 'username' ]) && ! $existingChat && ! isset ( $this -> caching_simple_username [ $user [ 'username' ]])) {
2018-12-28 03:32:10 +01:00
$this -> logger -> logger ( " No access hash with user { $user [ 'id' ] } , trying to fetch by username... " );
2019-10-29 21:33:23 +01:00
$this -> cachePwrChat ( $user [ 'username' ], false , true );
2019-04-29 16:42:08 +02:00
} else {
$this -> logger -> logger ( " No access hash with user { $user [ 'id' ] } , tried and failed to fetch data... " );
2016-12-23 21:06:38 +01:00
}
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
return ;
}
switch ( $user [ '_' ]) {
case 'user' :
2020-05-03 03:33:54 +02:00
if ( ! $existingChat || $existingChat !== $user ) {
2018-12-28 03:32:10 +01:00
$this -> logger -> logger ( " Updated user { $user [ 'id' ] } " , \danog\MadelineProto\Logger :: ULTRA_VERBOSE );
2020-05-03 03:33:54 +02:00
if (( $user [ 'min' ] ? ? false ) && ! ( $existingChat [ 'min' ] ? ? false )) {
2019-09-14 15:31:52 +02:00
$this -> logger -> logger ( " { $user [ 'id' ] } is min, filling missing fields " , \danog\MadelineProto\Logger :: ULTRA_VERBOSE );
2020-05-03 03:33:54 +02:00
if ( isset ( $existingChat [ 'access_hash' ])) {
2019-09-14 16:04:40 +02:00
$user [ 'min' ] = false ;
2020-05-03 03:33:54 +02:00
$user [ 'access_hash' ] = $existingChat [ 'access_hash' ];
2019-09-14 15:31:52 +02:00
}
}
2020-09-27 19:36:17 +02:00
yield $this -> chats -> offsetSet ( $user [ 'id' ], $user );
2019-10-29 21:33:23 +01:00
$this -> cachePwrChat ( $user [ 'id' ], false , true );
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
}
2020-05-09 00:47:12 +02:00
$this -> cacheChatUsername ( $user [ 'id' ], $user );
2019-09-13 16:55:48 +02:00
break ;
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
case 'userEmpty' :
break ;
default :
throw new \danog\MadelineProto\Exception ( 'Invalid user provided' , $user );
2016-12-23 21:06:38 +01:00
}
2016-12-23 12:19:13 +01:00
}
2019-12-28 16:07:09 +01:00
/**
* Add chat to database .
*
* @ param array $chat Chat
*
* @ internal
*
2020-10-01 21:36:07 +02:00
* @ return \Generator
*
* @ psalm - return \Generator < int , \Amp\Promise | null , mixed , void >
2019-12-28 16:07:09 +01:00
*/
public function addChat ( $chat ) : \Generator
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
{
switch ( $chat [ '_' ]) {
case 'chat' :
case 'chatEmpty' :
case 'chatForbidden' :
2020-05-03 03:33:54 +02:00
$existingChat = yield $this -> chats [ - $chat [ 'id' ]];
if ( ! $existingChat || $existingChat !== $chat ) {
2018-12-28 03:32:10 +01:00
$this -> logger -> logger ( " Updated chat - { $chat [ 'id' ] } " , \danog\MadelineProto\Logger :: ULTRA_VERBOSE );
2020-09-27 19:36:17 +02:00
yield $this -> chats -> offsetSet ( - $chat [ 'id' ], $chat );
2020-09-22 11:48:12 +02:00
$this -> cachePwrChat ( - $chat [ 'id' ], $this -> getSettings () -> getPeer () -> getFullFetch (), true );
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
}
2020-05-09 00:47:12 +02:00
$this -> cacheChatUsername ( - $chat [ 'id' ], $chat );
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
break ;
case 'channelEmpty' :
break ;
case ' channel ' :
case 'channelForbidden' :
2019-10-29 21:33:23 +01:00
$bot_api_id = $this -> toSupergroup ( $chat [ 'id' ]);
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
if ( ! isset ( $chat [ 'access_hash' ])) {
2019-04-29 16:42:08 +02:00
if ( ! isset ( $this -> caching_simple [ $bot_api_id ]) && ! ( isset ( $chat [ 'username' ]) && isset ( $this -> caching_simple_username [ $chat [ 'username' ]]))) {
$this -> logger -> logger ( " No access hash with { $chat [ '_' ] } { $bot_api_id } , trying to fetch by ID... " );
2019-06-04 14:55:58 +02:00
if ( isset ( $chat [ 'username' ]) && ! isset ( $this -> caching_simple_username [ $chat [ 'username' ]])) {
$this -> caching_possible_username [ $bot_api_id ] = $chat [ 'username' ];
}
2019-10-29 21:33:23 +01:00
$this -> cachePwrChat ( $bot_api_id , false , true );
2020-05-03 03:33:54 +02:00
} elseif ( isset ( $chat [ 'username' ]) && ! ( yield $this -> chats [ $bot_api_id ]) && ! isset ( $this -> caching_simple_username [ $chat [ 'username' ]])) {
2019-04-29 16:42:08 +02:00
$this -> logger -> logger ( " No access hash with { $chat [ '_' ] } { $bot_api_id } , trying to fetch by username... " );
2019-10-29 21:33:23 +01:00
$this -> cachePwrChat ( $chat [ 'username' ], false , true );
2019-04-29 16:42:08 +02:00
} else {
$this -> logger -> logger ( " No access hash with { $chat [ '_' ] } { $bot_api_id } , tried and failed to fetch data... " );
2017-05-10 10:39:31 +02:00
}
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
return ;
}
2020-05-03 03:33:54 +02:00
$existingChat = yield $this -> chats [ $bot_api_id ];
if ( ! $existingChat || $existingChat !== $chat ) {
2020-01-31 19:29:43 +01:00
$this -> logger -> logger ( " Updated chat { $bot_api_id } " , \danog\MadelineProto\Logger :: ULTRA_VERBOSE );
2020-05-03 03:33:54 +02:00
if (( $chat [ 'min' ] ? ? false ) && $existingChat && ! ( $existingChat [ 'min' ] ? ? false )) {
2020-01-31 19:29:43 +01:00
$this -> logger -> logger ( " { $bot_api_id } is min, filling missing fields " , \danog\MadelineProto\Logger :: ULTRA_VERBOSE );
2020-05-03 03:33:54 +02:00
$newchat = $existingChat ;
2019-09-14 16:04:40 +02:00
foreach ([ 'title' , 'username' , 'photo' , 'banned_rights' , 'megagroup' , 'verified' ] as $field ) {
if ( isset ( $chat [ $field ])) {
$newchat [ $field ] = $chat [ $field ];
}
2019-09-14 15:31:52 +02:00
}
2019-09-14 16:04:40 +02:00
$chat = $newchat ;
2019-09-14 15:31:52 +02:00
}
2020-09-27 19:36:17 +02:00
yield $this -> chats -> offsetSet ( $bot_api_id , $chat );
2020-05-03 03:33:54 +02:00
$fullChat = yield $this -> full_chats [ $bot_api_id ];
2020-09-22 11:48:12 +02:00
if ( $this -> getSettings () -> getPeer () -> getFullFetch () && ( ! $fullChat || $fullChat [ 'full' ][ 'participants_count' ] !== ( yield from $this -> getFullInfo ( $bot_api_id ))[ 'full' ][ 'participants_count' ])) {
$this -> cachePwrChat ( $bot_api_id , $this -> getSettings () -> getPeer () -> getFullFetch (), true );
2016-12-26 18:23:46 +01:00
}
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
}
2020-05-09 00:47:12 +02:00
$this -> cacheChatUsername ( $bot_api_id , $chat );
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
break ;
}
}
2020-04-28 02:41:06 +02:00
2020-10-06 11:55:19 +02:00
private function cacheChatUsername ( $id , array $chat ) : void
2020-04-28 02:41:06 +02:00
{
2020-05-09 00:47:12 +02:00
if ( $id && ! empty ( $chat [ 'username' ])) {
2020-06-16 17:52:55 +02:00
$this -> usernames [ \strtolower ( $chat [ 'username' ])] = $id ;
2020-04-28 02:41:06 +02:00
}
}
2020-10-01 21:36:07 +02:00
private function cachePwrChat ( $id , $full_fetch , $send ) : void
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
{
2020-01-31 19:29:43 +01:00
\danog\MadelineProto\Tools :: callFork (( function () use ( $id , $full_fetch , $send ) : \Generator {
2019-06-04 14:55:58 +02:00
try {
2020-01-31 19:29:43 +01:00
yield from $this -> getPwrChat ( $id , $full_fetch , $send );
2019-06-04 14:55:58 +02:00
} catch ( \danog\MadelineProto\Exception $e ) {
2020-04-05 14:57:33 +02:00
$this -> logger -> logger ( 'While caching: ' . $e -> getMessage (), \danog\MadelineProto\Logger :: WARNING );
2019-06-04 14:55:58 +02:00
} catch ( \danog\MadelineProto\RPCErrorException $e ) {
2020-04-05 14:57:33 +02:00
$this -> logger -> logger ( 'While caching: ' . $e -> getMessage (), \danog\MadelineProto\Logger :: WARNING );
2019-06-04 14:55:58 +02:00
}
2019-06-03 20:51:10 +02:00
})());
2016-12-26 18:23:46 +01:00
}
2019-12-27 20:29:22 +01:00
/**
* Check if peer is present in internal peer database .
*
* @ param mixed $id Peer
*
2020-10-01 21:36:07 +02:00
* @ return \Generator
*
* @ psalm - return \Generator < int | mixed , \Amp\Promise | array , mixed , bool >
2019-12-27 20:29:22 +01:00
*/
public function peerIsset ( $id ) : \Generator
2016-12-30 16:36:44 +01:00
{
2016-12-30 16:32:25 +01:00
try {
2020-05-03 03:33:54 +02:00
$info = yield from $this -> getInfo ( $id );
$chatId = $info [ 'bot_api_id' ];
return ( yield $this -> chats [ $chatId ]) !== null ;
2018-03-11 18:36:32 +01:00
} catch ( \danog\MadelineProto\Exception $e ) {
return false ;
2017-03-11 19:54:51 +01:00
} catch ( \danog\MadelineProto\RPCErrorException $e ) {
2018-03-09 17:39:36 +01:00
if ( $e -> rpc === 'CHAT_FORBIDDEN' ) {
return true ;
}
if ( $e -> rpc === 'CHANNEL_PRIVATE' ) {
return true ;
}
2017-03-11 19:54:51 +01:00
return false ;
2016-12-30 16:32:25 +01:00
}
}
2019-12-28 16:07:09 +01:00
/**
* Check if all peer entities are in db .
*
* @ param array $entities Entity list
*
* @ internal
*
* @ return \Generator < bool >
*/
public function entitiesPeerIsset ( array $entities ) : \Generator
2016-12-30 16:36:44 +01:00
{
2016-12-30 16:32:25 +01:00
try {
foreach ( $entities as $entity ) {
2017-01-27 13:19:16 +01:00
if ( $entity [ '_' ] === 'messageEntityMentionName' || $entity [ '_' ] === 'inputMessageEntityMentionName' ) {
2020-01-31 19:29:43 +01:00
if ( ! ( yield from $this -> peerIsset ( $entity [ 'user_id' ]))) {
2016-12-30 16:36:44 +01:00
return false ;
}
2016-12-30 16:32:25 +01:00
}
}
} catch ( \danog\MadelineProto\Exception $e ) {
return false ;
}
return true ;
}
2019-12-28 16:07:09 +01:00
/**
* Check if fwd peer is set .
*
* @ param array $fwd Forward info
*
* @ internal
*
* @ return \Generator
*/
public function fwdPeerIsset ( array $fwd ) : \Generator
2016-12-30 16:36:44 +01:00
{
2016-12-30 16:32:25 +01:00
try {
2020-01-31 19:29:43 +01:00
if ( isset ( $fwd [ 'user_id' ]) && ! ( yield from $this -> peerIsset ( $fwd [ 'user_id' ]))) {
2016-12-30 16:36:44 +01:00
return false ;
}
2020-01-31 19:29:43 +01:00
if ( isset ( $fwd [ 'channel_id' ]) && ! ( yield from $this -> peerIsset ( $this -> toSupergroup ( $fwd [ 'channel_id' ])))) {
2016-12-30 16:36:44 +01:00
return false ;
}
2016-12-30 16:32:25 +01:00
} catch ( \danog\MadelineProto\Exception $e ) {
return false ;
}
return true ;
}
2019-12-27 20:29:22 +01:00
/**
* Get folder ID from object .
*
* @ param mixed $id Object
*
* @ return ? int
*/
2019-12-28 16:45:00 +01:00
public static function getFolderId ( $id ) : ? int
2019-06-22 18:22:38 +02:00
{
2019-09-02 17:08:36 +02:00
if ( ! \is_array ( $id )) {
2019-06-22 18:22:38 +02:00
return null ;
}
if ( ! isset ( $id [ 'folder_id' ])) {
return null ;
}
return $id [ 'folder_id' ];
}
2019-12-27 20:29:22 +01:00
/**
* Get bot API ID from peer object .
*
* @ param mixed $id Peer
*
* @ return int
*/
2019-12-28 17:14:59 +01:00
public function getId ( $id )
2016-12-26 18:23:46 +01:00
{
2019-09-02 17:08:36 +02:00
if ( \is_array ( $id )) {
2016-12-26 18:23:46 +01:00
switch ( $id [ '_' ]) {
2018-08-30 19:58:58 +02:00
case 'updateDialogPinned' :
case 'updateDialogUnreadMark' :
case 'updateNotifySettings' :
$id = $id [ 'peer' ];
2020-01-31 19:29:43 +01:00
// no break
2018-08-30 19:58:58 +02:00
case 'updateDraftMessage' :
case 'inputDialogPeer' :
case 'dialogPeer' :
case 'inputNotifyPeer' :
case 'notifyPeer' :
case 'dialog' :
case 'help.proxyDataPromo' :
2019-04-29 13:18:39 +02:00
case 'updateChatDefaultBannedRights' :
2019-06-22 18:22:38 +02:00
case 'folderPeer' :
case 'inputFolderPeer' :
2019-10-29 21:33:23 +01:00
return $this -> getId ( $id [ 'peer' ]);
2019-06-22 18:22:38 +02:00
case 'inputUserFromMessage' :
case 'inputPeerUserFromMessage' :
return $id [ 'user_id' ];
case 'inputChannelFromMessage' :
case 'inputPeerChannelFromMessage' :
2019-10-29 21:33:23 +01:00
return $this -> toSupergroup ( $id [ 'channel_id' ]);
2017-01-07 12:39:11 +01:00
case 'inputUserSelf' :
2016-12-26 18:23:46 +01:00
case 'inputPeerSelf' :
2018-12-28 03:32:10 +01:00
return $this -> authorization [ 'user' ][ 'id' ];
2016-12-26 18:23:46 +01:00
case 'user' :
2018-12-28 03:32:10 +01:00
return $id [ 'id' ];
2017-01-07 12:39:11 +01:00
case 'userFull' :
2018-12-28 03:32:10 +01:00
return $id [ 'user' ][ 'id' ];
2016-12-26 18:23:46 +01:00
case 'inputPeerUser' :
case 'inputUser' :
case 'peerUser' :
2019-09-13 16:55:48 +02:00
case 'messageEntityMentionName' :
case 'messageActionChatDeleteUser' :
2018-12-28 03:32:10 +01:00
return $id [ 'user_id' ];
2019-09-14 14:21:11 +02:00
case 'messageActionChatJoinedByLink' :
2019-09-13 16:55:48 +02:00
return $id [ 'inviter_id' ];
2016-12-26 18:23:46 +01:00
case 'chat' :
2019-06-13 17:04:48 +02:00
case 'chatForbidden' :
2017-01-07 12:39:11 +01:00
case 'chatFull' :
2018-12-28 03:32:10 +01:00
return - $id [ 'id' ];
2018-02-24 17:54:13 +01:00
case 'inputPeerChat' :
2016-12-26 18:23:46 +01:00
case 'peerChat' :
2018-12-28 03:32:10 +01:00
return - $id [ 'chat_id' ];
2019-06-13 17:04:48 +02:00
case 'channelForbidden' :
2016-12-26 18:23:46 +01:00
case 'channel' :
2017-01-07 12:39:11 +01:00
case 'channelFull' :
2019-10-29 21:33:23 +01:00
return $this -> toSupergroup ( $id [ 'id' ]);
2016-12-26 18:23:46 +01:00
case 'inputPeerChannel' :
case 'inputChannel' :
case 'peerChannel' :
2019-10-29 21:33:23 +01:00
return $this -> toSupergroup ( $id [ 'channel_id' ]);
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
case 'message' :
2018-03-28 00:46:06 +02:00
case 'messageService' :
2020-10-06 22:02:04 +02:00
if ( ! isset ( $id [ 'from_id' ]) // No other option
// It's a channel/chat, 100% what we need
2020-10-01 18:02:54 +02:00
|| $id [ 'peer_id' ][ '_' ] !== 'peerUser'
2020-10-06 22:02:04 +02:00
// It is a user, and it's not ourselves
2020-10-01 18:02:54 +02:00
|| $id [ 'peer_id' ][ 'user_id' ] !== $this -> authorization [ 'user' ][ 'id' ]
) {
return $this -> getId ( $id [ 'peer_id' ]);
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
}
2020-10-01 18:02:54 +02:00
return $this -> getId ( $id [ 'from_id' ]);
2018-04-18 17:16:33 +02:00
case 'updateChannelReadMessagesContents' :
case 'updateChannelAvailableMessages' :
case 'updateChannel' :
case 'updateChannelWebPage' :
case 'updateChannelMessageViews' :
case 'updateReadChannelInbox' :
case 'updateReadChannelOutbox' :
case 'updateDeleteChannelMessages' :
case 'updateChannelPinnedMessage' :
2019-06-02 16:23:49 +02:00
case 'updateChannelTooLong' :
2019-10-29 21:33:23 +01:00
return $this -> toSupergroup ( $id [ 'channel_id' ]);
2018-04-18 17:16:33 +02:00
case 'updateChatParticipants' :
2018-08-30 19:58:58 +02:00
$id = $id [ 'participants' ];
2020-01-31 19:29:43 +01:00
// no break
2018-04-18 17:16:33 +02:00
case 'updateChatUserTyping' :
case 'updateChatParticipantAdd' :
case 'updateChatParticipantDelete' :
case 'updateChatParticipantAdmin' :
case 'updateChatAdmins' :
2019-04-29 13:18:39 +02:00
case 'updateChatPinnedMessage' :
2018-12-28 03:32:10 +01:00
return - $id [ 'chat_id' ];
2018-04-18 17:16:33 +02:00
case 'updateUserTyping' :
case 'updateUserStatus' :
case 'updateUserName' :
case 'updateUserPhoto' :
case 'updateUserPhone' :
case 'updateUserBlocked' :
case 'updateContactRegistered' :
case 'updateContactLink' :
case 'updateBotInlineQuery' :
case 'updateInlineBotCallbackQuery' :
case 'updateBotInlineSend' :
case 'updateBotCallbackQuery' :
case 'updateBotPrecheckoutQuery' :
case 'updateBotShippingQuery' :
2019-04-29 13:18:39 +02:00
case 'updateUserPinnedMessage' :
2020-10-04 13:37:27 +02:00
case 'contact' :
2018-12-28 03:32:10 +01:00
return $id [ 'user_id' ];
2018-04-18 17:16:33 +02:00
case 'updatePhoneCall' :
2020-10-04 16:27:22 +02:00
return $id [ 'phone_call' ] -> getOtherID ();
2018-04-18 17:16:33 +02:00
case 'updateReadHistoryInbox' :
case 'updateReadHistoryOutbox' :
2019-10-29 21:33:23 +01:00
return $this -> getId ( $id [ 'peer' ]);
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
case 'updateNewMessage' :
case 'updateNewChannelMessage' :
2018-04-18 17:16:33 +02:00
case 'updateEditMessage' :
case 'updateEditChannelMessage' :
2019-10-29 21:33:23 +01:00
return $this -> getId ( $id [ 'message' ]);
2016-12-26 18:23:46 +01:00
default :
2020-04-05 14:57:33 +02:00
throw new \danog\MadelineProto\Exception ( 'Invalid constructor given ' . \var_export ( $id , true ));
2016-12-26 18:23:46 +01:00
}
2016-12-26 20:24:24 +01:00
}
2019-09-02 17:08:36 +02:00
if ( \is_string ( $id )) {
if ( \strpos ( $id , '#' ) !== false ) {
2020-01-31 19:29:43 +01:00
if ( \preg_match ( '/^channel#(\\d*)/' , $id , $matches )) {
2019-10-29 21:33:23 +01:00
return $this -> toSupergroup ( $matches [ 1 ]);
2018-12-28 03:32:10 +01:00
}
2020-01-31 19:29:43 +01:00
if ( \preg_match ( '/^chat#(\\d*)/' , $id , $matches )) {
2020-04-05 14:57:33 +02:00
$id = '-' . $matches [ 1 ];
2018-12-28 03:32:10 +01:00
}
2020-01-31 19:29:43 +01:00
if ( \preg_match ( '/^user#(\\d*)/' , $id , $matches )) {
2018-12-28 03:32:10 +01:00
return $matches [ 1 ];
}
2017-04-21 13:13:24 +02:00
}
2016-12-26 18:23:46 +01:00
}
2019-09-02 17:08:36 +02:00
if ( \is_numeric ( $id )) {
if ( \is_string ( $id )) {
2018-04-08 19:44:01 +02:00
$id = \danog\MadelineProto\Magic :: $bigint ? ( float ) $id : ( int ) $id ;
2017-03-31 17:36:55 +02:00
}
2018-12-28 03:32:10 +01:00
return $id ;
}
return false ;
}
2019-12-27 20:29:22 +01:00
/**
* Get info about peer , returns an Info object .
*
* @ param mixed $id Peer
* @ param boolean $recursive Internal
*
* @ see https :// docs . madelineproto . xyz / Info . html
*
2020-10-01 21:36:07 +02:00
* @ return \Generator Info object
*
2020-10-18 14:46:34 +02:00
* @ template TConstructor
* @ psalm - param $id array { _ : TConstructor } | mixed
2020-10-18 15:02:37 +02:00
*
2020-10-18 14:46:34 +02:00
* @ return ((( mixed | string )[] | mixed | string )[] | int | mixed | string )[]
*
2020-10-04 14:55:05 +02:00
* @ psalm - return \Generator < int | mixed , \Amp\Promise | \Amp\Promise < string >| array , mixed , array {
2020-10-18 14:46:34 +02:00
* TConstructor : array
2020-10-04 14:55:05 +02:00
* 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 }},
* InputNotifyPeer : array { _ : string , peer : array { _ : string , user_id ? : mixed , access_hash ? : mixed , min ? : mixed , chat_id ? : mixed , channel_id ? : mixed }},
* bot_api_id : int | string ,
* user_id ? : int ,
* chat_id ? : int ,
* channel_id ? : int ,
2020-10-15 19:07:37 +02:00
* InputUser ? : array { _ : string , user_id ? : int , access_hash ? : mixed , min ? : bool },
* InputChannel ? : array { _ : string , channel_id : int , access_hash : mixed , min : bool },
2020-10-04 14:55:05 +02:00
* type : string
* } >
2019-12-27 20:29:22 +01:00
*/
public function getInfo ( $id , $recursive = true ) : \Generator
2018-12-28 03:32:10 +01:00
{
2019-09-02 17:08:36 +02:00
if ( \is_array ( $id )) {
2018-12-28 03:32:10 +01:00
switch ( $id [ '_' ]) {
case 'updateEncryption' :
2019-10-29 21:33:23 +01:00
return $this -> getSecretChat ( $id [ 'chat' ][ 'id' ]);
2019-08-25 20:40:42 +02:00
case 'inputEncryptedChat' :
2018-12-28 03:32:10 +01:00
case 'updateEncryptedChatTyping' :
case 'updateEncryptedMessagesRead' :
2019-10-29 21:33:23 +01:00
return $this -> getSecretChat ( $id [ 'chat_id' ]);
2019-06-21 17:57:13 +02:00
case 'updateNewEncryptedMessage' :
$id = $id [ 'message' ];
2020-01-31 19:29:43 +01:00
// no break
2018-12-28 03:32:10 +01:00
case 'encryptedMessage' :
case 'encryptedMessageService' :
$id = $id [ 'chat_id' ];
if ( ! isset ( $this -> secret_chats [ $id ])) {
throw new \danog\MadelineProto\Exception ( \danog\MadelineProto\Lang :: $current_lang [ 'sec_peer_not_in_db' ]);
}
return $this -> secret_chats [ $id ];
}
}
2019-10-29 21:33:23 +01:00
$folder_id = $this -> getFolderId ( $id );
$try_id = $this -> getId ( $id );
2019-06-04 14:55:58 +02:00
if ( $try_id !== false ) {
$id = $try_id ;
}
2019-04-29 16:42:08 +02:00
$tried_simple = false ;
2019-09-02 17:08:36 +02:00
if ( \is_numeric ( $id )) {
2020-05-03 03:33:54 +02:00
if ( ! yield $this -> chats [ $id ]) {
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
try {
2020-01-31 19:29:43 +01:00
$this -> logger -> logger ( " Try fetching { $id } with access hash 0 " );
2019-04-29 16:42:08 +02:00
$this -> caching_simple [ $id ] = true ;
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
if ( $id < 0 ) {
2019-10-29 21:33:23 +01:00
if ( $this -> isSupergroup ( $id )) {
2020-10-18 14:46:34 +02:00
yield from $this -> methodCallAsyncRead ( 'channels.getChannels' , [ 'id' => [[ 'access_hash' => 0 , 'channel_id' => $this -> fromSupergroup ( $id ), '_' => 'inputChannel' ]]]);
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
} else {
2020-10-18 14:46:34 +02:00
yield from $this -> methodCallAsyncRead ( 'messages.getFullChat' , [ 'chat_id' => - $id ]);
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
}
} else {
2020-10-18 14:46:34 +02:00
yield from $this -> methodCallAsyncRead ( 'users.getUsers' , [ 'id' => [[ 'access_hash' => 0 , 'user_id' => $id , '_' => 'inputUser' ]]]);
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
}
} catch ( \danog\MadelineProto\Exception $e ) {
$this -> logger -> logger ( $e -> getMessage (), \danog\MadelineProto\Logger :: WARNING );
} catch ( \danog\MadelineProto\RPCErrorException $e ) {
$this -> logger -> logger ( $e -> getMessage (), \danog\MadelineProto\Logger :: WARNING );
2019-04-29 16:42:08 +02:00
} finally {
2019-06-04 14:55:58 +02:00
if ( isset ( $this -> caching_simple [ $id ])) {
unset ( $this -> caching_simple [ $id ]);
}
2019-04-29 16:42:08 +02:00
$tried_simple = true ;
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
}
2017-09-25 00:26:06 +02:00
}
2020-05-03 03:33:54 +02:00
if ( yield $this -> chats [ $id ]) {
2020-08-31 00:39:25 +02:00
if ((( yield $this -> chats [ $id ])[ 'min' ] ? ? false ) && yield $this -> minDatabase -> hasPeer ( $id ) && ! isset ( $this -> caching_full_info [ $id ])) {
2019-09-14 16:59:34 +02:00
$this -> caching_full_info [ $id ] = true ;
2020-01-31 19:29:43 +01:00
$this -> logger -> logger ( " Only have min peer for { $id } in database, trying to fetch full info " );
2019-09-14 14:21:11 +02:00
try {
if ( $id < 0 ) {
2020-10-18 14:46:34 +02:00
yield from $this -> methodCallAsyncRead ( 'channels.getChannels' , [ 'id' => [ $this -> genAll ( yield $this -> chats [ $id ], $folder_id )[ 'InputChannel' ]]]);
2019-09-14 14:21:11 +02:00
} else {
2020-10-18 14:46:34 +02:00
yield from $this -> methodCallAsyncRead ( 'users.getUsers' , [ 'id' => [ $this -> genAll ( yield $this -> chats [ $id ], $folder_id )[ 'InputUser' ]]]);
2019-09-14 14:21:11 +02:00
}
} catch ( \danog\MadelineProto\Exception $e ) {
$this -> logger -> logger ( $e -> getMessage (), \danog\MadelineProto\Logger :: WARNING );
} catch ( \danog\MadelineProto\RPCErrorException $e ) {
$this -> logger -> logger ( $e -> getMessage (), \danog\MadelineProto\Logger :: WARNING );
2019-09-14 16:59:34 +02:00
} finally {
unset ( $this -> caching_full_info [ $id ]);
2019-09-14 14:21:11 +02:00
}
}
2018-03-09 17:39:13 +01:00
try {
2020-05-03 03:33:54 +02:00
return $this -> genAll ( yield $this -> chats [ $id ], $folder_id );
2018-03-09 17:39:13 +01:00
} catch ( \danog\MadelineProto\Exception $e ) {
if ( $e -> getMessage () === 'This peer is not present in the internal peer database' ) {
2020-05-03 03:33:54 +02:00
yield $this -> chats -> offsetUnset ( $id ); /** @uses DbArray::offsetUnset() */
2018-03-09 17:39:36 +01:00
} else {
throw $e ;
}
2018-03-09 17:39:13 +01:00
}
2016-12-26 18:23:46 +01:00
}
2020-09-22 11:48:12 +02:00
if ( $this -> settings -> getPwr () -> getRequests () && $recursive ) {
2019-05-12 13:45:52 +02:00
$dbres = [];
try {
2020-04-05 14:57:33 +02:00
$dbres = \json_decode ( yield from $this -> datacenter -> fileGetContents ( 'https://id.pwrtelegram.xyz/db/getusername?id=' . $id ), true );
2019-05-12 13:45:52 +02:00
} catch ( \Throwable $e ) {
$this -> logger -> logger ( $e );
}
2017-05-16 15:12:04 +02:00
if ( isset ( $dbres [ 'ok' ]) && $dbres [ 'ok' ]) {
2020-04-05 14:57:33 +02:00
yield from $this -> resolveUsername ( '@' . $dbres [ 'result' ]);
2020-01-31 19:29:43 +01:00
return yield from $this -> getInfo ( $id , false );
2017-05-03 15:15:14 +02:00
}
2017-01-27 22:05:24 +01:00
}
2019-04-29 16:42:08 +02:00
if ( $tried_simple && isset ( $this -> caching_possible_username [ $id ])) {
2020-01-31 19:29:43 +01:00
$this -> logger -> logger ( " No access hash with { $id } , trying to fetch by username... " );
2019-04-29 16:42:08 +02:00
$user = $this -> caching_possible_username [ $id ];
unset ( $this -> caching_possible_username [ $id ]);
2020-01-31 19:29:43 +01:00
return yield from $this -> getInfo ( $user );
2019-04-29 16:42:08 +02:00
}
2017-05-16 15:12:04 +02:00
throw new \danog\MadelineProto\Exception ( 'This peer is not present in the internal peer database' );
2016-12-26 18:23:46 +01:00
}
2020-01-31 19:29:43 +01:00
if ( \preg_match ( '@(?:t|telegram)\\.(?:me|dog)/(joinchat/)?([a-z0-9_-]*)@i' , $id , $matches )) {
2018-03-08 12:28:03 +01:00
if ( $matches [ 1 ] === '' ) {
$id = $matches [ 2 ];
} else {
2020-10-18 14:46:34 +02:00
$invite = yield from $this -> methodCallAsyncRead ( 'messages.checkChatInvite' , [ 'hash' => $matches [ 2 ]]);
2018-03-08 12:28:03 +01:00
if ( isset ( $invite [ 'chat' ])) {
2020-01-31 19:29:43 +01:00
return yield from $this -> getInfo ( $invite [ 'chat' ]);
2018-03-08 12:28:03 +01:00
}
2019-09-02 17:08:36 +02:00
throw new \danog\MadelineProto\Exception ( 'You have not joined this chat' );
2018-03-08 12:28:03 +01:00
}
}
2019-09-02 17:08:36 +02:00
$id = \strtolower ( \str_replace ( '@' , '' , $id ));
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
if ( $id === 'me' ) {
2020-01-31 19:29:43 +01:00
return yield from $this -> getInfo ( $this -> authorization [ 'user' ][ 'id' ]);
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
}
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
if ( $id === 'support' ) {
if ( ! $this -> supportUser ) {
2020-09-22 11:48:12 +02:00
yield from $this -> methodCallAsyncRead ( 'help.getSupport' , [], $this -> settings -> getDefaultDcParams ());
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
}
2020-01-31 19:29:43 +01:00
return yield from $this -> getInfo ( $this -> supportUser );
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
}
2020-05-03 03:33:54 +02:00
if ( $bot_api_id = yield $this -> usernames [ $id ]) {
$chat = yield $this -> chats [ $bot_api_id ];
2020-04-28 02:41:06 +02:00
if ( empty ( $chat [ 'username' ]) || \strtolower ( $chat [ 'username' ]) !== $id ) {
2020-05-03 03:33:54 +02:00
yield $this -> usernames -> offsetUnset ( $id ); /** @uses DbArray::offsetUnset() */
2020-04-27 02:21:18 +02:00
}
2019-09-02 17:08:36 +02:00
if ( isset ( $chat [ 'username' ]) && \strtolower ( $chat [ 'username' ]) === $id ) {
2019-09-14 16:59:34 +02:00
if ( $chat [ 'min' ] ? ? false && ! isset ( $this -> caching_full_info [ $bot_api_id ])) {
$this -> caching_full_info [ $bot_api_id ] = true ;
2020-01-31 19:29:43 +01:00
$this -> logger -> logger ( " Only have min peer for { $bot_api_id } in database, trying to fetch full info " );
2019-09-14 15:31:52 +02:00
try {
if ( $bot_api_id < 0 ) {
2020-10-18 14:46:34 +02:00
yield from $this -> methodCallAsyncRead ( 'channels.getChannels' , [ 'id' => [ $this -> genAll ( yield $this -> chats [ $bot_api_id ], $folder_id )[ 'InputChannel' ]]]);
2019-09-14 14:21:11 +02:00
} else {
2020-10-18 14:46:34 +02:00
yield from $this -> methodCallAsyncRead ( 'users.getUsers' , [ 'id' => [ $this -> genAll ( yield $this -> chats [ $bot_api_id ], $folder_id )[ 'InputUser' ]]]);
2019-09-14 14:21:11 +02:00
}
2019-09-14 15:31:52 +02:00
} catch ( \danog\MadelineProto\Exception $e ) {
$this -> logger -> logger ( $e -> getMessage (), \danog\MadelineProto\Logger :: WARNING );
} catch ( \danog\MadelineProto\RPCErrorException $e ) {
$this -> logger -> logger ( $e -> getMessage (), \danog\MadelineProto\Logger :: WARNING );
2019-09-14 16:59:34 +02:00
} finally {
unset ( $this -> caching_full_info [ $bot_api_id ]);
2019-09-14 14:21:11 +02:00
}
2019-09-14 15:39:42 +02:00
}
2020-05-03 03:33:54 +02:00
return $this -> genAll ( yield $this -> chats [ $bot_api_id ], $folder_id );
2016-12-26 18:23:46 +01:00
}
}
2020-04-28 02:41:06 +02:00
2016-12-26 18:23:46 +01:00
if ( $recursive ) {
2020-01-31 19:29:43 +01:00
yield from $this -> resolveUsername ( $id );
return yield from $this -> getInfo ( $id , false );
2016-12-26 18:23:46 +01:00
}
2017-05-16 15:12:04 +02:00
throw new \danog\MadelineProto\Exception ( 'This peer is not present in the internal peer database' );
2016-12-26 18:23:46 +01:00
}
2020-10-01 21:36:07 +02:00
/**
2020-10-18 14:46:34 +02:00
* @ template TConstructor
* @ psalm - param $constructor array { _ : TConstructor }
2020-10-18 15:02:37 +02:00
*
2020-10-01 21:36:07 +02:00
* @ return ((( mixed | string )[] | mixed | string )[] | int | mixed | string )[]
*
2020-10-03 15:36:03 +02:00
* @ psalm - return array {
2020-10-18 14:46:34 +02:00
* TConstructor : array
2020-10-03 17:41:21 +02:00
* 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 },
2020-10-03 15:36:03 +02:00
* 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 }},
* InputNotifyPeer : array { _ : string , peer : array { _ : string , user_id ? : mixed , access_hash ? : mixed , min ? : mixed , chat_id ? : mixed , channel_id ? : mixed }},
* bot_api_id : int | string ,
* user_id ? : int ,
* chat_id ? : int ,
* channel_id ? : int ,
2020-10-03 17:41:21 +02:00
* InputUser ? : { _ : string , user_id ? : int , access_hash ? : mixed , min ? : bool },
* InputChannel ? : { _ : string , channel_id : int , access_hash : mixed , min : bool },
2020-10-03 15:36:03 +02:00
* type : string
* }
2020-10-01 21:36:07 +02:00
*/
private function genAll ( $constructor , $folder_id = null ) : array
2016-12-26 20:24:24 +01:00
{
2019-11-01 12:45:15 +01:00
$res = [ $this -> TL -> getConstructors () -> findByPredicate ( $constructor [ '_' ])[ 'type' ] => $constructor ];
2016-12-26 18:23:46 +01:00
switch ( $constructor [ '_' ]) {
2017-01-14 12:53:50 +01:00
case 'user' :
2020-01-16 20:19:03 +01:00
if ( $constructor [ 'self' ] ? ? false ) {
2016-12-31 12:32:02 +01:00
$res [ 'InputPeer' ] = [ '_' => 'inputPeerSelf' ];
$res [ 'InputUser' ] = [ '_' => 'inputUserSelf' ];
2017-01-14 12:53:50 +01:00
} elseif ( isset ( $constructor [ 'access_hash' ])) {
2019-09-13 16:55:48 +02:00
$res [ 'InputPeer' ] = [ '_' => 'inputPeerUser' , 'user_id' => $constructor [ 'id' ], 'access_hash' => $constructor [ 'access_hash' ], 'min' => $constructor [ 'min' ]];
$res [ 'InputUser' ] = [ '_' => 'inputUser' , 'user_id' => $constructor [ 'id' ], 'access_hash' => $constructor [ 'access_hash' ], 'min' => $constructor [ 'min' ]];
2017-05-04 19:59:29 +02:00
} else {
throw new \danog\MadelineProto\Exception ( 'This peer is not present in the internal peer database' );
2016-12-31 12:32:02 +01:00
}
2017-01-14 12:53:50 +01:00
$res [ 'Peer' ] = [ '_' => 'peerUser' , 'user_id' => $constructor [ 'id' ]];
2018-08-30 19:58:58 +02:00
$res [ 'DialogPeer' ] = [ '_' => 'dialogPeer' , 'peer' => $res [ 'Peer' ]];
$res [ 'NotifyPeer' ] = [ '_' => 'notifyPeer' , 'peer' => $res [ 'Peer' ]];
$res [ 'InputDialogPeer' ] = [ '_' => 'inputDialogPeer' , 'peer' => $res [ 'InputPeer' ]];
$res [ 'InputNotifyPeer' ] = [ '_' => 'inputNotifyPeer' , 'peer' => $res [ 'InputPeer' ]];
2017-01-14 12:53:50 +01:00
$res [ 'user_id' ] = $constructor [ 'id' ];
$res [ 'bot_api_id' ] = $constructor [ 'id' ];
2020-01-31 19:29:43 +01:00
$res [ 'type' ] = $constructor [ 'bot' ] ? ? false ? 'bot' : 'user' ;
2016-12-26 18:23:46 +01:00
break ;
2017-01-14 12:53:50 +01:00
case 'chat' :
2017-01-15 02:10:44 +01:00
case 'chatForbidden' :
2017-01-14 12:53:50 +01:00
$res [ 'InputPeer' ] = [ '_' => 'inputPeerChat' , 'chat_id' => $constructor [ 'id' ]];
2018-08-30 22:49:58 +02:00
$res [ 'Peer' ] = [ '_' => 'peerChat' , 'chat_id' => $constructor [ 'id' ]];
2018-08-30 19:58:58 +02:00
$res [ 'DialogPeer' ] = [ '_' => 'dialogPeer' , 'peer' => $res [ 'Peer' ]];
$res [ 'NotifyPeer' ] = [ '_' => 'notifyPeer' , 'peer' => $res [ 'Peer' ]];
$res [ 'InputDialogPeer' ] = [ '_' => 'inputDialogPeer' , 'peer' => $res [ 'InputPeer' ]];
$res [ 'InputNotifyPeer' ] = [ '_' => 'inputNotifyPeer' , 'peer' => $res [ 'InputPeer' ]];
2017-01-14 12:53:50 +01:00
$res [ 'chat_id' ] = $constructor [ 'id' ];
$res [ 'bot_api_id' ] = - $constructor [ 'id' ];
$res [ 'type' ] = 'chat' ;
2016-12-26 18:23:46 +01:00
break ;
2017-01-14 12:53:50 +01:00
case 'channel' :
2017-05-04 19:59:29 +02:00
if ( ! isset ( $constructor [ 'access_hash' ])) {
throw new \danog\MadelineProto\Exception ( 'This peer is not present in the internal peer database' );
2016-12-31 12:32:02 +01:00
}
2019-09-13 16:55:48 +02:00
$res [ 'InputPeer' ] = [ '_' => 'inputPeerChannel' , 'channel_id' => $constructor [ 'id' ], 'access_hash' => $constructor [ 'access_hash' ], 'min' => $constructor [ 'min' ]];
2018-08-30 22:49:58 +02:00
$res [ 'Peer' ] = [ '_' => 'peerChannel' , 'channel_id' => $constructor [ 'id' ]];
2018-08-30 19:58:58 +02:00
$res [ 'DialogPeer' ] = [ '_' => 'dialogPeer' , 'peer' => $res [ 'Peer' ]];
$res [ 'NotifyPeer' ] = [ '_' => 'notifyPeer' , 'peer' => $res [ 'Peer' ]];
$res [ 'InputDialogPeer' ] = [ '_' => 'inputDialogPeer' , 'peer' => $res [ 'InputPeer' ]];
$res [ 'InputNotifyPeer' ] = [ '_' => 'inputNotifyPeer' , 'peer' => $res [ 'InputPeer' ]];
2019-09-13 16:55:48 +02:00
$res [ 'InputChannel' ] = [ '_' => 'inputChannel' , 'channel_id' => $constructor [ 'id' ], 'access_hash' => $constructor [ 'access_hash' ], 'min' => $constructor [ 'min' ]];
2017-01-14 12:53:50 +01:00
$res [ 'channel_id' ] = $constructor [ 'id' ];
2019-10-29 21:33:23 +01:00
$res [ 'bot_api_id' ] = $this -> toSupergroup ( $constructor [ 'id' ]);
2020-01-31 19:29:43 +01:00
$res [ 'type' ] = $constructor [ 'megagroup' ] ? ? false ? 'supergroup' : 'channel' ;
2016-12-26 18:23:46 +01:00
break ;
2017-04-21 13:13:24 +02:00
case 'channelForbidden' :
2019-06-07 02:48:25 +02:00
throw new \danog\MadelineProto\Exception ( 'This peer is not present in the internal peer database' );
2016-12-26 18:23:46 +01:00
default :
2020-04-05 14:57:33 +02:00
throw new \danog\MadelineProto\Exception ( 'Invalid constructor given ' . \var_export ( $constructor , true ));
2016-12-26 18:23:46 +01:00
}
2019-06-22 18:22:38 +02:00
if ( $folder_id ) {
$res [ 'FolderPeer' ] = [ '_' => 'folderPeer' , 'peer' => $res [ 'Peer' ], 'folder_id' => $folder_id ];
$res [ 'InputFolderPeer' ] = [ '_' => 'inputFolderPeer' , 'peer' => $res [ 'InputPeer' ], 'folder_id' => $folder_id ];
}
2016-12-30 16:32:25 +01:00
return $res ;
2016-12-26 18:23:46 +01:00
}
2019-12-28 16:07:09 +01:00
/**
* When were full info for this chat last cached .
*
* @ param mixed $id Chat ID
*
2020-05-03 03:33:54 +02:00
* @ return \Generator < integer >
2019-12-28 16:07:09 +01:00
*/
2020-05-03 03:33:54 +02:00
public function fullChatLastUpdated ( $id ) : \Generator
2017-02-11 15:16:57 +01:00
{
2020-05-03 03:33:54 +02:00
return ( yield $this -> full_chats [ $id ])[ 'last_update' ] ? ? 0 ;
2017-02-11 15:16:57 +01:00
}
2019-12-27 20:29:22 +01:00
/**
* Get full info about peer , returns an FullInfo object .
*
* @ param mixed $id Peer
*
* @ see https :// docs . madelineproto . xyz / FullInfo . html
*
2020-10-01 21:36:07 +02:00
* @ return \Generator FullInfo object
*
* @ psalm - return \Generator < int | mixed , \Amp\Promise | array , mixed , array >
2019-12-27 20:29:22 +01:00
*/
public function getFullInfo ( $id ) : \Generator
2017-01-14 12:54:50 +01:00
{
2020-01-31 19:29:43 +01:00
$partial = ( yield from $this -> getInfo ( $id ));
2020-09-22 11:48:12 +02:00
if ( \time () - ( yield from $this -> fullChatLastUpdated ( $partial [ 'bot_api_id' ])) < $this -> getSettings () -> getPeer () -> getFullInfoCacheTime ()) {
2020-05-03 03:33:54 +02:00
return \array_merge ( $partial , yield $this -> full_chats [ $partial [ 'bot_api_id' ]]);
2017-07-26 08:30:48 +02:00
}
2020-10-01 21:36:07 +02:00
$full = null ;
2017-01-14 12:53:50 +01:00
switch ( $partial [ 'type' ]) {
case 'user' :
case 'bot' :
2020-10-18 14:46:34 +02:00
$full = yield from $this -> methodCallAsyncRead ( 'users.getFullUser' , [ 'id' => $partial [ 'InputUser' ]]);
2018-02-24 17:54:13 +01:00
break ;
2017-01-14 12:53:50 +01:00
case 'chat' :
2020-10-18 14:46:34 +02:00
$full = ( yield from $this -> methodCallAsyncRead ( 'messages.getFullChat' , $partial ))[ 'full_chat' ];
2018-02-24 17:54:13 +01:00
break ;
2017-01-14 12:53:50 +01:00
case 'channel' :
case 'supergroup' :
2020-10-18 14:46:34 +02:00
$full = ( yield from $this -> methodCallAsyncRead ( 'channels.getFullChannel' , [ 'channel' => $partial [ 'InputChannel' ]]))[ 'full_chat' ];
2018-02-24 17:54:13 +01:00
break ;
2017-01-14 12:53:50 +01:00
}
2017-07-26 08:30:48 +02:00
$res = [];
$res [ 'full' ] = $full ;
2019-09-02 17:08:36 +02:00
$res [ 'last_update' ] = \time ();
2017-07-26 08:30:48 +02:00
$this -> full_chats [ $partial [ 'bot_api_id' ]] = $res ;
2020-01-31 19:29:43 +01:00
$partial = ( yield from $this -> getInfo ( $id ));
2019-09-02 17:08:36 +02:00
return \array_merge ( $partial , $res );
2017-01-14 12:53:50 +01:00
}
2019-12-27 20:29:22 +01:00
/**
* Get full info about peer ( including full list of channel members ), returns a Chat object .
*
* @ param mixed $id Peer
*
* @ see https :// docs . madelineproto . xyz / Chat . html
*
2020-10-18 14:46:34 +02:00
* @ return \Generator Chat object
2019-12-27 20:29:22 +01:00
*/
2020-02-09 16:24:57 +01:00
public function getPwrChat ( $id , bool $fullfetch = true , bool $send = true ) : \Generator
2017-01-14 12:54:50 +01:00
{
2020-01-31 19:29:43 +01:00
$full = $fullfetch ? yield from $this -> getFullInfo ( $id ) : ( yield from $this -> getInfo ( $id ));
2017-01-14 12:53:50 +01:00
$res = [ 'id' => $full [ 'bot_api_id' ], 'type' => $full [ 'type' ]];
switch ( $full [ 'type' ]) {
case 'user' :
case 'bot' :
2017-07-26 18:38:10 +02:00
foreach ([ 'first_name' , 'last_name' , 'username' , 'verified' , 'restricted' , 'restriction_reason' , 'status' , 'bot_inline_placeholder' , 'access_hash' , 'phone' , 'lang_code' , 'bot_nochats' ] as $key ) {
2017-01-14 12:54:50 +01:00
if ( isset ( $full [ 'User' ][ $key ])) {
$res [ $key ] = $full [ 'User' ][ $key ];
}
}
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
foreach ([ 'about' , 'bot_info' , 'phone_calls_available' , 'phone_calls_private' , 'common_chats_count' , 'can_pin_message' , 'pinned_msg_id' , 'notify_settings' ] as $key ) {
if ( isset ( $full [ 'full' ][ $key ])) {
$res [ $key ] = $full [ 'full' ][ $key ];
}
2017-04-06 22:15:59 +02:00
}
2017-01-14 12:54:50 +01:00
if ( isset ( $full [ 'full' ][ 'profile_photo' ][ 'sizes' ])) {
2020-01-16 20:19:03 +01:00
$res [ 'photo' ] = $full [ 'full' ][ 'profile_photo' ];
2017-01-14 12:53:50 +01:00
}
break ;
case 'chat' :
foreach ([ 'title' , 'participants_count' , 'admin' , 'admins_enabled' ] as $key ) {
2017-01-14 12:54:50 +01:00
if ( isset ( $full [ 'Chat' ][ $key ])) {
$res [ $key ] = $full [ 'Chat' ][ $key ];
}
2017-01-14 12:53:50 +01:00
}
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
foreach ([ 'bot_info' , 'pinned_msg_id' , 'notify_settings' ] as $key ) {
if ( isset ( $full [ 'full' ][ $key ])) {
$res [ $key ] = $full [ 'full' ][ $key ];
}
}
2017-04-06 22:16:20 +02:00
if ( isset ( $res [ 'admins_enabled' ])) {
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
$res [ 'all_members_are_administrators' ] = ! $res [ 'admins_enabled' ];
2017-04-06 22:16:20 +02:00
}
2017-01-14 12:54:50 +01:00
if ( isset ( $full [ 'full' ][ 'chat_photo' ][ 'sizes' ])) {
2020-01-16 20:19:03 +01:00
$res [ 'photo' ] = $full [ 'full' ][ 'chat_photo' ];
2017-01-14 12:54:50 +01:00
}
if ( isset ( $full [ 'full' ][ 'exported_invite' ][ 'link' ])) {
$res [ 'invite' ] = $full [ 'full' ][ 'exported_invite' ][ 'link' ];
}
if ( isset ( $full [ 'full' ][ 'participants' ][ 'participants' ])) {
$res [ 'participants' ] = $full [ 'full' ][ 'participants' ][ 'participants' ];
}
2017-01-14 12:53:50 +01:00
break ;
case 'channel' :
case 'supergroup' :
foreach ([ 'title' , 'democracy' , 'restricted' , 'restriction_reason' , 'access_hash' , 'username' , 'signatures' ] as $key ) {
2017-01-14 12:54:50 +01:00
if ( isset ( $full [ 'Chat' ][ $key ])) {
$res [ $key ] = $full [ 'Chat' ][ $key ];
}
2017-01-14 12:53:50 +01:00
}
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
foreach ([ 'read_inbox_max_id' , 'read_outbox_max_id' , 'hidden_prehistory' , 'bot_info' , 'notify_settings' , 'can_set_stickers' , 'stickerset' , 'can_view_participants' , 'can_set_username' , 'participants_count' , 'admins_count' , 'kicked_count' , 'banned_count' , 'migrated_from_chat_id' , 'migrated_from_max_id' , 'pinned_msg_id' , 'about' , 'hidden_prehistory' , 'available_min_id' , 'can_view_stats' , 'online_count' ] as $key ) {
2017-01-14 12:54:50 +01:00
if ( isset ( $full [ 'full' ][ $key ])) {
$res [ $key ] = $full [ 'full' ][ $key ];
}
2017-01-14 12:53:50 +01:00
}
2017-01-14 12:54:50 +01:00
if ( isset ( $full [ 'full' ][ 'chat_photo' ][ 'sizes' ])) {
2020-01-16 20:19:03 +01:00
$res [ 'photo' ] = $full [ 'full' ][ 'chat_photo' ];
2017-01-14 12:54:50 +01:00
}
if ( isset ( $full [ 'full' ][ 'exported_invite' ][ 'link' ])) {
$res [ 'invite' ] = $full [ 'full' ][ 'exported_invite' ][ 'link' ];
}
if ( isset ( $full [ 'full' ][ 'participants' ][ 'participants' ])) {
$res [ 'participants' ] = $full [ 'full' ][ 'participants' ][ 'participants' ];
}
2017-01-14 12:53:50 +01:00
break ;
}
2017-11-10 16:19:58 +01:00
if ( isset ( $res [ 'participants' ]) && $fullfetch ) {
2017-01-14 12:53:50 +01:00
foreach ( $res [ 'participants' ] as $key => $participant ) {
2017-01-17 21:49:53 +01:00
$newres = [];
2020-01-31 19:29:43 +01:00
$newres [ 'user' ] = ( yield from $this -> getPwrChat ( $participant [ 'user_id' ], false , true ));
2017-01-14 12:54:50 +01:00
if ( isset ( $participant [ 'inviter_id' ])) {
2020-01-31 19:29:43 +01:00
$newres [ 'inviter' ] = ( yield from $this -> getPwrChat ( $participant [ 'inviter_id' ], false , true ));
2017-01-14 12:54:50 +01:00
}
2017-07-26 18:38:10 +02:00
if ( isset ( $participant [ 'promoted_by' ])) {
2020-01-31 19:29:43 +01:00
$newres [ 'promoted_by' ] = ( yield from $this -> getPwrChat ( $participant [ 'promoted_by' ], false , true ));
2017-07-26 18:38:10 +02:00
}
if ( isset ( $participant [ 'kicked_by' ])) {
2020-01-31 19:29:43 +01:00
$newres [ 'kicked_by' ] = ( yield from $this -> getPwrChat ( $participant [ 'kicked_by' ], false , true ));
2017-07-26 18:38:10 +02:00
}
2017-01-14 12:54:50 +01:00
if ( isset ( $participant [ 'date' ])) {
$newres [ 'date' ] = $participant [ 'date' ];
}
2017-07-26 18:38:10 +02:00
if ( isset ( $participant [ 'admin_rights' ])) {
$newres [ 'admin_rights' ] = $participant [ 'admin_rights' ];
}
if ( isset ( $participant [ 'banned_rights' ])) {
$newres [ 'banned_rights' ] = $participant [ 'banned_rights' ];
}
if ( isset ( $participant [ 'can_edit' ])) {
$newres [ 'can_edit' ] = $participant [ 'can_edit' ];
}
if ( isset ( $participant [ 'left' ])) {
$newres [ 'left' ] = $participant [ 'left' ];
}
2017-01-14 12:53:50 +01:00
switch ( $participant [ '_' ]) {
case 'chatParticipant' :
2018-02-24 17:54:13 +01:00
$newres [ 'role' ] = 'user' ;
break ;
2017-01-14 12:53:50 +01:00
case 'chatParticipantAdmin' :
2018-02-24 17:54:13 +01:00
$newres [ 'role' ] = 'admin' ;
break ;
2017-01-14 12:53:50 +01:00
case 'chatParticipantCreator' :
2018-02-24 17:54:13 +01:00
$newres [ 'role' ] = 'creator' ;
break ;
2017-01-14 12:53:50 +01:00
}
$res [ 'participants' ][ $key ] = $newres ;
}
}
2019-09-02 17:08:36 +02:00
if ( ! isset ( $res [ 'participants' ]) && $fullfetch && \in_array ( $res [ 'type' ], [ 'supergroup' , 'channel' ])) {
2018-03-10 03:56:33 +01:00
$total_count = ( isset ( $res [ 'participants_count' ]) ? $res [ 'participants_count' ] : 0 ) + ( isset ( $res [ 'admins_count' ]) ? $res [ 'admins_count' ] : 0 ) + ( isset ( $res [ 'kicked_count' ]) ? $res [ 'kicked_count' ] : 0 ) + ( isset ( $res [ 'banned_count' ]) ? $res [ 'banned_count' ] : 0 );
2017-01-14 12:53:50 +01:00
$res [ 'participants' ] = [];
2018-03-11 15:29:27 +01:00
$filters = [ 'channelParticipantsAdmins' , 'channelParticipantsBots' ];
2020-10-18 14:46:34 +02:00
$promises = [];
2017-07-27 00:48:19 +02:00
foreach ( $filters as $filter ) {
2020-10-18 14:46:34 +02:00
$promises [] = $this -> fetchParticipants ( $full [ 'InputChannel' ], $filter , '' , $total_count , $res );
2018-03-10 03:56:33 +01:00
}
2020-10-18 14:46:34 +02:00
yield Tools :: all ( $promises );
2018-03-10 03:56:33 +01:00
$q = '' ;
$filters = [ 'channelParticipantsSearch' , 'channelParticipantsKicked' , 'channelParticipantsBanned' ];
2020-10-18 14:46:34 +02:00
$promises = [];
2018-03-10 03:56:33 +01:00
foreach ( $filters as $filter ) {
2020-10-18 14:46:34 +02:00
$promises [] = $this -> recurseAlphabetSearchParticipants ( $full [ 'InputChannel' ], $filter , $q , $total_count , $res , 0 );
2018-03-10 03:56:33 +01:00
}
2020-10-18 14:46:34 +02:00
yield Tools :: all ( $promises );
2020-04-05 14:57:33 +02:00
$this -> logger -> logger ( 'Fetched ' . \count ( $res [ 'participants' ]) . " out of { $total_count } " );
2019-09-02 17:08:36 +02:00
$res [ 'participants' ] = \array_values ( $res [ 'participants' ]);
2018-03-10 03:56:33 +01:00
}
if ( ! $fullfetch ) {
unset ( $res [ 'participants' ]);
}
if ( $fullfetch || $send ) {
2019-10-29 21:33:23 +01:00
$this -> storeDb ( $res );
2018-03-10 03:56:33 +01:00
}
2020-02-09 16:24:57 +01:00
if ( isset ( $res [ 'photo' ])) {
$photo = [];
foreach ([
'small' => $res [ 'photo' ][ 'sizes' ][ 0 ],
2020-10-01 18:02:54 +02:00
'big' => Tools :: maxSize ( $res [ 'photo' ][ 'sizes' ]),
2020-02-09 16:24:57 +01:00
] as $type => $size ) {
$fileId = new FileId ;
$fileId -> setId ( $res [ 'photo' ][ 'id' ] ? ? 0 );
$fileId -> setAccessHash ( $res [ 'photo' ][ 'access_hash' ] ? ? 0 );
$fileId -> setFileReference ( $res [ 'photo' ][ 'file_reference' ] ? ? '' );
$fileId -> setDcId ( $res [ 'photo' ][ 'dc_id' ]);
$fileId -> setType ( PROFILE_PHOTO );
$fileId -> setLocalId ( $size [ 'location' ][ 'local_id' ]);
$fileId -> setVolumeId ( $size [ 'location' ][ 'volume_id' ]);
$photoSize = new PhotoSizeSourceDialogPhoto ;
$photoSize -> setDialogId ( $res [ 'id' ]);
$photoSize -> setDialogPhotoSmall ( $type === 'small' );
$photoSize -> setDialogAccessHash ( $res [ 'access_hash' ] ? ? 0 );
$fileId -> setPhotoSizeSource ( $photoSize );
$photo [ $type . '_file_id' ] = ( string ) $fileId ;
$photo [ $type . '_file_unique_id' ] = $fileId -> getUniqueBotAPI ();
}
$res [ 'photo' ] += $photo ;
}
2018-03-10 03:56:33 +01:00
return $res ;
}
2020-10-18 14:46:34 +02:00
private function recurseAlphabetSearchParticipants ( $channel , $filter , $q , $total_count , & $res , int $depth ) : \Generator
2018-03-10 03:56:57 +01:00
{
2020-01-31 19:29:43 +01:00
if ( ! ( yield from $this -> fetchParticipants ( $channel , $filter , $q , $total_count , $res ))) {
2020-10-18 14:46:34 +02:00
return [];
2018-03-10 03:56:57 +01:00
}
2020-10-18 14:46:34 +02:00
$promises = [];
2019-09-02 17:08:36 +02:00
for ( $x = 'a' ; $x !== 'aa' && $total_count > \count ( $res [ 'participants' ]); $x ++ ) {
2020-10-18 14:46:34 +02:00
$promises [] = $this -> recurseAlphabetSearchParticipants ( $channel , $filter , $q . $x , $total_count , $res , $depth + 1 );
}
if ( $depth > 2 ) {
return $promises ;
}
2020-10-18 15:23:12 +02:00
$yielded = [ ... yield Tools :: all ( $promises )];
2020-10-18 14:46:34 +02:00
while ( $yielded ) {
$newYielded = [];
2020-10-18 15:23:12 +02:00
foreach ( \array_chunk ( $yielded , 10 ) as $promises ) {
$newYielded = \array_merge ( $newYielded , ... ( yield Tools :: all ( $promises )));
2020-10-18 14:46:34 +02:00
}
$yielded = $newYielded ;
2018-03-10 03:56:33 +01:00
}
2020-10-18 14:46:34 +02:00
return [];
2018-03-10 03:56:33 +01:00
}
2020-01-31 19:29:43 +01:00
private function fetchParticipants ( $channel , $filter , $q , $total_count , & $res ) : \Generator
2018-03-10 03:56:57 +01:00
{
$offset = 0 ;
$limit = 200 ;
$has_more = false ;
2018-03-11 15:29:27 +01:00
$cached = false ;
2018-08-28 20:55:49 +02:00
$last_count = - 1 ;
2018-03-11 15:29:27 +01:00
do {
try {
2020-06-07 20:56:54 +02:00
$gres = yield from $this -> methodCallAsyncRead ( 'channels.getParticipants' , [ 'channel' => $channel , 'filter' => [ '_' => $filter , 'q' => $q ], 'offset' => $offset , 'limit' => $limit , 'hash' => $hash = yield from $this -> getParticipantsHash ( $channel , $filter , $q , $offset , $limit )], [ 'datacenter' => $this -> datacenter -> curdc , 'heavy' => true ]);
2018-03-11 15:29:27 +01:00
} catch ( \danog\MadelineProto\RPCErrorException $e ) {
if ( $e -> rpc === 'CHAT_ADMIN_REQUIRED' ) {
2019-06-01 22:04:37 +02:00
$this -> logger -> logger ( $e -> rpc );
2018-03-11 15:29:27 +01:00
return $has_more ;
}
2019-09-02 17:08:36 +02:00
throw $e ;
2018-03-11 15:29:27 +01:00
}
2020-05-03 03:33:54 +02:00
if ( $cached = ( $gres [ '_' ] === 'channels.channelParticipantsNotModified' )) {
2020-10-18 14:46:34 +02:00
$gres = yield $this -> fetchParticipantsCache ( $channel , $filter , $q , $offset , $limit );
2018-03-10 03:56:57 +01:00
} else {
2020-10-18 14:46:34 +02:00
$this -> storeParticipantsCache ( $gres , $channel , $filter , $q , $offset , $limit );
2018-03-10 03:56:57 +01:00
}
2018-08-28 20:55:49 +02:00
if ( $last_count !== - 1 && $last_count !== $gres [ 'count' ]) {
$has_more = true ;
} else {
$last_count = $gres [ 'count' ];
}
2018-03-10 03:56:57 +01:00
foreach ( $gres [ 'participants' ] as $participant ) {
$newres = [];
2020-01-31 19:29:43 +01:00
$newres [ 'user' ] = ( yield from $this -> getPwrChat ( $participant [ 'user_id' ], false , true ));
2018-03-10 03:56:57 +01:00
if ( isset ( $participant [ 'inviter_id' ])) {
2020-01-31 19:29:43 +01:00
$newres [ 'inviter' ] = ( yield from $this -> getPwrChat ( $participant [ 'inviter_id' ], false , true ));
2017-07-27 00:28:31 +02:00
}
2018-03-10 03:56:57 +01:00
if ( isset ( $participant [ 'kicked_by' ])) {
2020-01-31 19:29:43 +01:00
$newres [ 'kicked_by' ] = ( yield from $this -> getPwrChat ( $participant [ 'kicked_by' ], false , true ));
2018-03-09 17:39:36 +01:00
}
2018-03-10 03:56:57 +01:00
if ( isset ( $participant [ 'promoted_by' ])) {
2020-01-31 19:29:43 +01:00
$newres [ 'promoted_by' ] = ( yield from $this -> getPwrChat ( $participant [ 'promoted_by' ], false , true ));
2018-03-10 03:56:57 +01:00
}
if ( isset ( $participant [ 'date' ])) {
$newres [ 'date' ] = $participant [ 'date' ];
}
2019-09-17 22:42:38 +02:00
if ( isset ( $participant [ 'rank' ])) {
$newres [ 'rank' ] = $participant [ 'rank' ];
}
2020-04-05 14:57:33 +02:00
if ( isset ( $participant [ 'admin_rights' ])) {
$newres [ 'admin_rights' ] = $participant [ 'admin_rights' ];
}
if ( isset ( $participant [ 'banned_rights' ])) {
$newres [ 'banned_rights' ] = $participant [ 'banned_rights' ];
}
2018-03-10 03:56:57 +01:00
switch ( $participant [ '_' ]) {
2018-08-30 19:58:58 +02:00
case 'channelParticipantSelf' :
$newres [ 'role' ] = 'user' ;
break ;
case 'channelParticipant' :
$newres [ 'role' ] = 'user' ;
break ;
case 'channelParticipantCreator' :
$newres [ 'role' ] = 'creator' ;
break ;
case 'channelParticipantAdmin' :
$newres [ 'role' ] = 'admin' ;
break ;
case 'channelParticipantBanned' :
$newres [ 'role' ] = 'banned' ;
break ;
}
2018-03-10 03:56:57 +01:00
$res [ 'participants' ][ $participant [ 'user_id' ]] = $newres ;
}
2020-04-05 14:57:33 +02:00
$this -> logger -> logger ( 'Fetched ' . \count ( $gres [ 'participants' ]) . " channel participants with filter { $filter } , query { $q } , offset { $offset } , limit { $limit } , hash { $hash } : " . ( $cached ? 'cached' : 'not cached' ) . ', ' . ( $offset + \count ( $gres [ 'participants' ])) . ' participants out of ' . $gres [ 'count' ] . ', in total fetched ' . \count ( $res [ 'participants' ]) . ' out of ' . $total_count );
2019-09-02 17:08:36 +02:00
$offset += \count ( $gres [ 'participants' ]);
} while ( \count ( $gres [ 'participants' ]));
2019-06-04 14:55:58 +02:00
if ( $offset === $limit ) {
return true ;
}
2018-03-10 03:56:57 +01:00
return $has_more ;
2017-01-14 12:53:50 +01:00
}
2020-10-18 14:46:34 +02:00
/**
* Key for participatns cache .
*
* @ param integer $channelId
* @ param string $filter
* @ param string $q
* @ param integer $offset
* @ param integer $limit
* @ return string
*/
private function participantsKey ( int $channelId , string $filter , string $q , int $offset , int $limit ) : string
{
return " $channelId ' $filter ' $q ' $offset ' $limit " ;
}
private function fetchParticipantsCache ( $channel , $filter , $q , $offset , $limit ) : Promise
2018-03-11 15:29:50 +01:00
{
2020-10-18 14:46:34 +02:00
return $this -> channelParticipants [ $this -> participantsKey ( $channel [ 'channel_id' ], $filter , $q , $offset , $limit )];
2018-03-11 15:29:27 +01:00
}
2020-10-18 15:04:43 +02:00
private function storeParticipantsCache ( $gres , $channel , $filter , $q , $offset , $limit ) : void
2018-03-11 15:29:50 +01:00
{
2018-03-11 15:29:27 +01:00
unset ( $gres [ 'users' ]);
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
$ids = [];
foreach ( $gres [ 'participants' ] as $participant ) {
$ids [] = $participant [ 'user_id' ];
2018-03-08 22:19:03 +01:00
}
2019-09-02 17:08:36 +02:00
\sort ( $ids , SORT_NUMERIC );
2019-10-29 23:02:47 +01:00
$gres [ 'hash' ] = \danog\MadelineProto\Tools :: genVectorHash ( $ids );
2020-10-18 14:46:34 +02:00
$this -> channelParticipants [ $this -> participantsKey ( $channel [ 'channel_id' ], $filter , $q , $offset , $limit )] = $gres ;
2018-03-11 15:29:27 +01:00
}
2020-06-07 20:56:54 +02:00
private function getParticipantsHash ( $channel , $filter , $q , $offset , $limit ) : \Generator
2018-03-11 15:29:27 +01:00
{
2020-10-18 14:46:34 +02:00
return ( yield $this -> channelParticipants [ $this -> participantsKey ( $channel [ 'channel_id' ], $filter , $q , $offset , $limit )])[ 'hash' ] ? ? 0 ;
2018-03-08 22:19:03 +01:00
}
2020-01-31 19:29:43 +01:00
private function storeDb ( $res , $force = false ) : \Generator
2017-01-14 12:54:50 +01:00
{
2020-09-22 11:48:12 +02:00
if ( ! $this -> settings -> getPwr () -> getDbToken () || $this -> settings -> getConnection () -> getTestMode ()) {
2017-01-14 12:53:50 +01:00
return ;
}
if ( ! empty ( $res )) {
2017-01-14 12:54:50 +01:00
if ( isset ( $res [ 'participants' ])) {
unset ( $res [ 'participants' ]);
}
$this -> qres [] = $res ;
2017-01-14 12:53:50 +01:00
}
2019-09-02 17:08:36 +02:00
if ( $this -> last_stored > \time () && ! $force ) {
2018-04-08 19:53:30 +02:00
//$this->logger->logger("========== WILL SERIALIZE IN ".($this->last_stored - time())." =============");
2017-01-14 12:53:50 +01:00
return false ;
}
2017-01-14 12:54:50 +01:00
if ( empty ( $this -> qres )) {
return false ;
}
2017-01-14 12:53:50 +01:00
try {
2019-09-02 17:08:36 +02:00
$payload = \json_encode ( $this -> qres );
2018-03-14 15:29:38 +01:00
//$path = '/tmp/ids'.hash('sha256', $payload);
//file_put_contents($path, $payload);
2017-03-24 21:01:08 +01:00
$id = isset ( $this -> authorization [ 'user' ][ 'username' ]) ? $this -> authorization [ 'user' ][ 'username' ] : $this -> authorization [ 'user' ][ 'id' ];
2020-09-22 11:48:12 +02:00
$request = new Request ( 'https://id.pwrtelegram.xyz/db' . $this -> settings -> getPwr () -> getDbToken () . '/addnewmadeline?d=pls&from=' . $id , 'POST' );
2019-12-13 13:29:53 +01:00
$request -> setHeader ( 'content-type' , 'application/json' );
$request -> setBody ( $payload );
2020-01-31 19:29:43 +01:00
$result = yield ( yield $this -> datacenter -> getHTTPClient () -> request ( $request )) -> getBody () -> buffer ();
$this -> logger -> logger ( " ============ { $result } ============= " , \danog\MadelineProto\Logger :: VERBOSE );
2018-03-11 15:29:27 +01:00
$this -> qres = [];
2019-09-02 17:08:36 +02:00
$this -> last_stored = \time () + 10 ;
2017-01-14 12:54:50 +01:00
} catch ( \danog\MadelineProto\Exception $e ) {
2020-04-05 14:57:33 +02:00
$this -> logger -> logger ( '======= COULD NOT STORE IN DB DUE TO ' . $e -> getMessage () . ' =============' , \danog\MadelineProto\Logger :: VERBOSE );
2017-01-14 12:54:50 +01:00
}
2017-01-14 12:53:50 +01:00
}
2019-12-28 16:07:09 +01:00
/**
* Resolve username ( use getInfo instead ) .
*
* @ param string $username Username
*
* @ return \Generator
*/
public function resolveUsername ( string $username ) : \Generator
2016-12-26 18:23:46 +01:00
{
2020-09-24 11:45:20 +02:00
$username = \str_replace ( '@' , '' , $username );
if ( ! $username ) {
return false ;
}
2018-02-18 18:26:14 +01:00
try {
2019-04-29 16:42:08 +02:00
$this -> caching_simple_username [ $username ] = true ;
2020-10-18 14:46:34 +02:00
$res = yield from $this -> methodCallAsyncRead ( 'contacts.resolveUsername' , [ 'username' => $username ]);
2018-02-18 18:26:34 +01:00
} catch ( \danog\MadelineProto\RPCErrorException $e ) {
2020-04-05 14:57:33 +02:00
$this -> logger -> logger ( 'Username resolution failed with error ' . $e -> getMessage (), \danog\MadelineProto\Logger :: ERROR );
2019-09-02 17:08:36 +02:00
if ( \strpos ( $e -> rpc , 'FLOOD_WAIT_' ) === 0 || $e -> rpc === 'AUTH_KEY_UNREGISTERED' || $e -> rpc === 'USERNAME_INVALID' ) {
2018-03-20 16:52:26 +01:00
throw $e ;
}
2018-02-18 18:26:34 +01:00
return false ;
2019-04-29 16:42:08 +02:00
} finally {
2019-06-04 14:55:58 +02:00
if ( isset ( $this -> caching_simple_username [ $username ])) {
unset ( $this -> caching_simple_username [ $username ]);
}
2018-02-18 18:26:34 +01:00
}
2017-01-27 13:19:16 +01:00
if ( $res [ '_' ] === 'contacts.resolvedPeer' ) {
2020-05-03 03:33:54 +02:00
foreach ( $res [ 'chats' ] as $chat ) {
yield from $this -> addChat ( $chat );
}
foreach ( $res [ 'users' ] as $user ) {
yield from $this -> addUser ( $user );
}
2016-12-26 18:23:46 +01:00
return $res ;
}
2018-02-18 18:26:14 +01:00
return false ;
2016-12-23 12:19:13 +01:00
}
2018-02-24 17:54:39 +01:00
}