1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-30 09:58:59 +01:00

Revert back strategy of DiscordReason and VoipController

This commit is contained in:
Mahdi 2023-09-02 15:57:46 +03:30
parent 899054337e
commit b72a55ea75
2 changed files with 20 additions and 14 deletions

View File

@ -26,28 +26,29 @@ use JsonSerializable;
/**
* Why was the call discarded?
*/
enum DiscardReason: string implements JsonSerializable
enum DiscardReason implements JsonSerializable
{
/** The phone call was discarded because the user is busy in another call */
case BUSY = 'phoneCallDiscardReasonBusy';
/** The phone call was discarded because the user is busy in another call */
case HANGUP = 'phoneCallDiscardReasonHangup';
/** The phone call was disconnected */
case DISCONNECTED = 'phoneCallDiscardReasonDisconnect';
/** We missed the call */
case MISSED = 'phoneCallDiscardReasonMissed';
case MISSED;
/** The phone call was disconnected */
case DISCONNECTED;
/** The phone call ended normally */
case HANGUP;
/** The phone call was discarded because the user is busy in another call */
case BUSY;
/**
* @throws AssertionError
* @internal
* @throws AssertionError
*/
public static function fromString(?string $name): ?DiscardReason
{
if ($name === null) {
return null;
}
$newName = \strtoupper(\substr($name, 22));
foreach (DiscardReason::cases() as $case) {
if ($case->value === $name) {
if ($case->name === $newName) {
return $case;
}
}

View File

@ -343,7 +343,12 @@ final class VoIPController
$this->log(\sprintf(Lang::$current_lang['call_discarding'], $this->public->callID), Logger::VERBOSE);
try {
$this->API->methodCallAsyncRead('phone.discardCall', ['peer' => $this->call, 'duration' => \time() - $this->public->date, 'connection_id' => 0, 'reason' => ['_' => $reason]]);
$this->API->methodCallAsyncRead('phone.discardCall', ['peer' => $this->call, 'duration' => \time() - $this->public->date, 'connection_id' => 0, 'reason' => ['_' => match ($reason) {
DiscardReason::BUSY => 'phoneCallDiscardReasonBusy',
DiscardReason::HANGUP => 'phoneCallDiscardReasonHangup',
DiscardReason::DISCONNECTED => 'phoneCallDiscardReasonDisconnect',
DiscardReason::MISSED => 'phoneCallDiscardReasonMissed'
}]]);
} catch (RPCErrorException $e) {
if (!\in_array($e->rpc, ['CALL_ALREADY_DECLINED', 'CALL_ALREADY_ACCEPTED'], true)) {
throw $e;