1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-23 10:31:13 +01:00
This commit is contained in:
Daniil Gentili 2023-08-14 16:10:20 +02:00
parent 9aa1e3ba6e
commit f4db68954a
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
9 changed files with 53 additions and 32 deletions

View File

@ -699,8 +699,8 @@ Want to add your own open-source project to this list? [Click here!](https://doc
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.updatePinnedMessage.html" name="messages.updatePinnedMessage">Pin a message: messages.updatePinnedMessage</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/channels.updatePinnedForumTopic.html" name="channels.updatePinnedForumTopic">Pin or unpin forum topics: channels.updatePinnedForumTopic</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.toggleDialogPin.html" name="messages.toggleDialogPin">Pin/unpin a dialog: messages.toggleDialogPin</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#callplay-int-id-string-file-void" name="callPlay">Play file in call: callPlay</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#callplayonhold-int-id-string-files-void" name="callPlayOnHold">Play files on hold in call: callPlayOnHold</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#callplay-int-id-danog-madelineproto-localfile-danog-madelineproto-remoteurl-danog-madelineproto-ipc-wrapper-readablestream-string-file-void" name="callPlay">Play file in call: callPlay</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#callplayonhold-int-id-string-localfile-remoteurl-amp-bytestream-readablestream-files-void" name="callPlayOnHold">Play files on hold in call: callPlayOnHold</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/channels.getMessages.html" name="channels.getMessages">Please use the event handler: channels.getMessages</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.getHistory.html" name="messages.getHistory">Please use the event handler: messages.getHistory</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.getMessages.html" name="messages.getMessages">Please use the event handler: messages.getMessages</a>
@ -900,7 +900,7 @@ Want to add your own open-source project to this list? [Click here!](https://doc
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.searchSentMedia.html" name="messages.searchSentMedia">View and search recently sent media. : messages.searchSentMedia</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.sendVote.html" name="messages.sendVote">Vote in a poll: messages.sendVote</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/account.updateDeviceLocked.html" name="account.updateDeviceLocked">When client-side passcode lock feature is enabled, will not show message texts in incoming PUSH notifications: account.updateDeviceLocked</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#fullchatlastupdated-mixed-id-int" name="fullChatLastUpdated">When were full info for this chat last cached: fullChatLastUpdated</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#fullchatlastupdated-mixed-id-int" name="fullChatLastUpdated">When was full info for this chat last cached: fullChatLastUpdated</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/account.getContactSignUpNotification.html" name="account.getContactSignUpNotification">Whether the user will receive notifications when contacts sign up: account.getContactSignUpNotification</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#isaltervista-bool" name="isAltervista">Whether this is altervista: isAltervista</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#isipc-bool" name="isIpc">Whether we're an IPC client instance: isIpc</a>

View File

@ -32,8 +32,6 @@ use function Amp\Future\await;
*/
trait DbPropertiesTrait
{
public ?string $tmpDbPrefix = null;
/**
* Initialize database instance.
*
@ -45,12 +43,8 @@ trait DbPropertiesTrait
throw new LogicException(static::class.' must have $dbProperties');
}
$dbSettings = $API->settings->getDb();
$prefix = $API->getSelf()['id'] ?? null;
if (!$prefix) {
$API->tmpDbPrefix ??= 'tmp_'.\str_replace('0', '', \spl_object_hash($API));
$prefix = $API->tmpDbPrefix;
}
$prefix = $API->getDbPrefix();
$className = \explode('\\', static::class);
$className = \end($className);
@ -60,7 +54,7 @@ trait DbPropertiesTrait
if ($reset) {
unset($this->{$property});
} else {
$table = ($type['global'] ?? false) ? '' : $prefix.'_';
$table = ($type['global'] ?? false) ? ($API->isTestMode() ? 'test_' : 'prod_') : $prefix.'_';
$table .= $type['table'] ?? "{$className}_{$property}";
$promises[$property] = async(DbPropertiesFactory::get(...), $dbSettings, $table, $type, $this->{$property} ?? null);
}

View File

@ -283,13 +283,13 @@ abstract class InternalDoc
/**
* Play file in call.
*/
public function callPlay(int $id, \danog\MadelineProto\LocalFile|\danog\MadelineProto\RemoteUrl|\danog\MadelineProto\Ipc\Wrapper\ReadableStream|string $file): void
public function callPlay(int $id, \danog\MadelineProto\LocalFile|\danog\MadelineProto\RemoteUrl|\Amp\ByteStream\ReadableStream $file): void
{
$this->wrapper->getAPI()->callPlay($id, $file);
}
/**
* Play files on hold in call.
* @param array<string|LocalFile|RemoteUrl|ReadableStream> $files
* @param array<LocalFile|RemoteUrl|ReadableStream> $files
*/
public function callPlayOnHold(int $id, array $files): void
{

View File

@ -574,6 +574,20 @@ final class MTProto implements TLCallback, LoggerGetter
{
return $this->wrapper->getSession()->getSessionDirectoryPath();
}
private ?string $tmpDbPrefix = null;
/** @internal */
public function getDbPrefix(): string
{
$prefix = $this->getSelf()['id'] ?? null;
if (!$prefix) {
$this->tmpDbPrefix ??= 'tmp_'.\spl_object_id($this);
$prefix = $this->tmpDbPrefix;
}
return (string) $prefix;
}
/**
* Sleep function.
*
@ -836,6 +850,12 @@ final class MTProto implements TLCallback, LoggerGetter
$this->chats,
$this->full_chats,
);
DbPropertiesFactory::get(
$this->settings->getDb(),
$this->getDbPrefix().'_MTProto_usernames',
['innerMadelineProto' => true],
$this->usernames
)->clear();
}
}

View File

@ -195,9 +195,11 @@ final class MinDatabase implements TLCallback
}
$this->API->logger->logger("Added origin ({$data['_']}) to ".\count($cache).' peer locations', Logger::ULTRA_VERBOSE);
}
private function flush(int $id): void
private function flush(int $id): void
{
if (!isset($this->pendingDb[$id])) return;
if (!isset($this->pendingDb[$id])) {
return;
}
$pending = $this->pendingDb[$id];
unset($this->pendingDb[$id]);
if ($this->API->peerDatabase->get($id)['min'] ?? true) {
@ -239,8 +241,8 @@ final class MinDatabase implements TLCallback
*/
public function clearPeer(int $id): void
{
unset($this->db[$id]);
unset($this->pendingDb[$id]);
unset($this->db[$id], $this->pendingDb[$id]);
}
public function __debugInfo()
{

View File

@ -143,10 +143,15 @@ final class PeerDatabase implements TLCallback
{
foreach ($chats as $id => $chat) {
$this->db[$id] = $chat;
foreach ($this->getUsernames($chat) as $username) {
$this->usernames[$username] = $id;
if ($this->API->settings->getDb()->getEnableUsernameDb()) {
foreach (self::getUsernames($chat) as $username) {
$this->usernames[$username] = $id;
}
}
}
if (!$this->API->settings->getDb()->getEnableFullPeerDb()) {
return;
}
foreach ($fullChats as $id => $chat) {
$this->fullDb[$id] = $chat;
}
@ -247,8 +252,8 @@ final class PeerDatabase implements TLCallback
if (!$this->API->settings->getDb()->getEnableUsernameDb()) {
return;
}
$new = $this->getUsernames($new);
$old = $old ? $this->getUsernames($old) : [];
$new = self::getUsernames($new);
$old = $old ? self::getUsernames($old) : [];
$diffToRemove = \array_diff($old, $new);
$diffToAdd = \array_diff($new, $old);
if (!$diffToAdd && !$diffToRemove) {
@ -370,7 +375,7 @@ final class PeerDatabase implements TLCallback
} catch (RPCErrorException $e) {
$this->API->logger->logger("An error occurred while trying to fetch the missing access_hash for user {$user['id']}: {$e->getMessage()}", Logger::FATAL_ERROR);
}
foreach ($this->getUsernames($user) as $username) {
foreach (self::getUsernames($user) as $username) {
if (($this->resolveUsername($username)) === $user['id']) {
return;
}
@ -476,7 +481,7 @@ final class PeerDatabase implements TLCallback
} catch (RPCErrorException $e) {
$this->API->logger->logger("An error occurred while trying to fetch the missing access_hash for channel {$bot_api_id}: {$e->getMessage()}", Logger::FATAL_ERROR);
}
foreach ($this->getUsernames($chat) as $username) {
foreach (self::getUsernames($chat) as $username) {
if (($this->resolveUsername($username)) === $bot_api_id) {
return;
}

View File

@ -88,7 +88,7 @@ final class VoIP extends Update implements SimpleFilters
/**
* Play file.
*/
public function play(string|LocalFile|RemoteUrl|ReadableStream $file): self
public function play(LocalFile|RemoteUrl|ReadableStream $file): self
{
$this->getClient()->callPlay($this->callID, $file);
@ -98,7 +98,7 @@ final class VoIP extends Update implements SimpleFilters
/**
* Play file.
*/
public function then(string|LocalFile|RemoteUrl|ReadableStream $file): self
public function then(LocalFile|RemoteUrl|ReadableStream $file): self
{
$this->getClient()->callPlay($this->callID, $file);
@ -107,7 +107,7 @@ final class VoIP extends Update implements SimpleFilters
/**
* Files to play on hold.
* @param array<string|LocalFile|RemoteUrl|ReadableStream> $files
* @param array<LocalFile|RemoteUrl|ReadableStream> $files
*/
public function playOnHold(array $files): self
{

View File

@ -20,8 +20,8 @@ declare(strict_types=1);
namespace danog\MadelineProto\VoIP;
use Amp\ByteStream\ReadableStream;
use Amp\DeferredFuture;
use danog\MadelineProto\Ipc\Wrapper\ReadableStream;
use danog\MadelineProto\LocalFile;
use danog\MadelineProto\Logger;
use danog\MadelineProto\Magic;
@ -153,14 +153,14 @@ trait AuthKeyHandler
/**
* Play file in call.
*/
public function callPlay(int $id, string|LocalFile|RemoteUrl|ReadableStream $file): void
public function callPlay(int $id, LocalFile|RemoteUrl|ReadableStream $file): void
{
($this->calls[$id] ?? null)?->play($file);
}
/**
* Play files on hold in call.
* @param array<string|LocalFile|RemoteUrl|ReadableStream> $files
* @param array<LocalFile|RemoteUrl|ReadableStream> $files
*/
public function callPlayOnHold(int $id, array $files): void
{

View File

@ -573,7 +573,7 @@ final class VoIPController
/**
* Play file.
*/
public function play(string|LocalFile|RemoteUrl|ReadableStream $file): self
public function play(LocalFile|RemoteUrl|ReadableStream $file): self
{
$this->inputFiles[] = $file;
if ($this->playingHold) {
@ -586,7 +586,7 @@ final class VoIPController
/**
* Files to play on hold.
*
* @param array<string|LocalFile|RemoteUrl|ReadableStream> $files
* @param array<LocalFile|RemoteUrl|ReadableStream> $files
*/
public function playOnHold(array $files): self
{