Various bugfixes

This commit is contained in:
Daniil Gentili 2019-06-21 17:57:13 +02:00
parent 03c3419240
commit df4e667bd7
5 changed files with 14 additions and 12 deletions

View File

@ -19,9 +19,9 @@
namespace danog\MadelineProto\Loop\Update;
use Amp\Loop;
use danog\MadelineProto\Exception;
use danog\MadelineProto\Loop\Impl\ResumableSignalLoop;
use danog\MadelineProto\RPCErrorException;
use danog\MadelineProto\Exception;
/**
* Update loop.
@ -148,13 +148,13 @@ class UpdateLoop extends ResumableSignalLoop
$difference = yield $API->method_call_async_read('updates.getDifference', ['pts' => $state->pts(), 'date' => $state->date(), 'qts' => $state->qts()], ['datacenter' => $API->settings['connection_settings']['default_dc']]);
$API->logger->logger('Got '.$difference['_'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
switch ($difference['_']) {
case 'updates.differenceEmpty':
$state->update($difference);
unset($difference);
break 2;
case 'updates.difference':
$state->qts($difference['state']['qts']);
foreach ($difference['new_encrypted_messages'] as &$encrypted) {
$encrypted = ['_' => 'updateNewEncryptedMessage', 'message' => $encrypted];
}
@ -165,6 +165,7 @@ class UpdateLoop extends ResumableSignalLoop
unset($difference);
break 2;
case 'updates.differenceSlice':
$state->qts($difference['state']['qts']);
foreach ($difference['new_encrypted_messages'] as &$encrypted) {
$encrypted = ['_' => 'updateNewEncryptedMessage', 'message' => $encrypted];
}

View File

@ -120,9 +120,9 @@ trait Files
}
$result = yield all($promises);
foreach ($result as $key => $result) {
foreach ($result as $kkey => $result) {
if (!$result) {
throw new \danog\MadelineProto\Exception('Upload of part '.$key.' failed');
throw new \danog\MadelineProto\Exception('Upload of part '.$kkey.' failed');
}
}

View File

@ -302,7 +302,6 @@ trait PeerHandler
case 'updateNewChannelMessage':
case 'updateEditMessage':
case 'updateEditChannelMessage':
case 'updateNewEncryptedMessage':
return $this->get_id($id['message']);
default:
throw new \danog\MadelineProto\Exception('Invalid constructor given '.var_export($id, true));
@ -341,6 +340,8 @@ trait PeerHandler
case 'updateEncryptedChatTyping':
case 'updateEncryptedMessagesRead':
return $this->get_secret_chat($id['chat_id']);
case 'updateNewEncryptedMessage':
$id = $id['message'];
case 'encryptedMessage':
case 'encryptedMessageService':
$id = $id['chat_id'];

View File

@ -39,7 +39,7 @@ class RPCErrorException extends \Exception
public function __toString()
{
$result = sprintf(\danog\MadelineProto\Lang::$current_lang['rpc_tg_error'], $this->getMess(), $this->rpc, $this->file, $this->line.PHP_EOL, \danog\MadelineProto\Magic::$revision.PHP_EOL.PHP_EOL).PHP_EOL.$this->getTLTrace().PHP_EOL;
$result = sprintf(\danog\MadelineProto\Lang::$current_lang['rpc_tg_error'], $this->getMess()." ({$this->code})", $this->rpc, $this->file, $this->line.PHP_EOL, \danog\MadelineProto\Magic::$revision.PHP_EOL.PHP_EOL).PHP_EOL.$this->getTLTrace().PHP_EOL;
if (php_sapi_name() !== 'cli') {
$result = str_replace(PHP_EOL, '<br>'.PHP_EOL, $result);
}

View File

@ -224,12 +224,12 @@ trait TL
throw new Exception('Invalid callback object provided!');
}
$new = [
TLCallback::METHOD_BEFORE_CALLBACK => $object->getMethodBeforeCallbacks(),
TLCallback::METHOD_CALLBACK => $object->getMethodCallbacks(),
TLCallback::CONSTRUCTOR_BEFORE_CALLBACK => $object->getConstructorBeforeCallbacks(),
TLCallback::CONSTRUCTOR_CALLBACK => $object->getConstructorCallbacks(),
TLCallback::METHOD_BEFORE_CALLBACK => $object->getMethodBeforeCallbacks(),
TLCallback::METHOD_CALLBACK => $object->getMethodCallbacks(),
TLCallback::CONSTRUCTOR_BEFORE_CALLBACK => $object->getConstructorBeforeCallbacks(),
TLCallback::CONSTRUCTOR_CALLBACK => $object->getConstructorCallbacks(),
TLCallback::CONSTRUCTOR_SERIALIZE_CALLBACK => $object->getConstructorSerializeCallbacks(),
TLCallback::TYPE_MISMATCH_CALLBACK => $object->getTypeMismatchCallbacks(),
TLCallback::TYPE_MISMATCH_CALLBACK => $object->getTypeMismatchCallbacks(),
];
foreach ($new as $type => $values) {
foreach ($values as $match => $callback) {
@ -449,7 +449,7 @@ trait TL
$method = 'messages.importChatInvite';
$arguments['hash'] = $matches[2];
}
} elseif ($method === 'messages.sendMessage' && isset($arguments['peer']['_']) && $arguments['peer']['_'] === 'inputEncryptedChat') {
} elseif ($method === 'messages.sendMessage' && isset($arguments['peer']['_']) && in_array($arguments['peer']['_'], ['inputEncryptedChat', 'updateEncryption', 'updateEncryptedChatTyping', 'updateEncryptedMessagesRead', 'updateNewEncryptedMessage', 'encryptedMessage', 'encryptedMessageService'])) {
$method = 'messages.sendEncrypted';
$arguments = ['peer' => $arguments['peer'], 'message' => $arguments];
if (!isset($arguments['message']['_'])) {