Skip to content

Commit 37d6130

Browse files
committed
Refactor
1 parent 6b45d14 commit 37d6130

14 files changed

Lines changed: 188 additions & 153 deletions

docs

Submodule docs updated 796 files

src/TL_filerefs.tl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ extractAndStore from:Path to:string = FieldExtractor;
2828
extractStickerSetFromDocumentAttributesAndStore from:Path to:string = FieldExtractor;
2929

3030
extractPeerIdFromPeerAndStore from:Path to:string = FieldExtractor;
31+
extractPeerIdFromInputPeerAndStore from:Path to:string = FieldExtractor;
32+
33+
extractChannelIdFromChannelAndStore from:Path to:string = FieldExtractor;
34+
extractChannelIdFromInputChannelAndStore from:Path to:string = FieldExtractor;
35+
36+
extractUserIdFromUserAndStore from:Path to:string = FieldExtractor;
37+
extractUserIdFromInputUserAndStore from:Path to:string = FieldExtractor;
3138

3239
// Typed constructors, the type is specified to simplify codegen,
3340
// but isn't strictly necessary as it can be inferred from the TypedOpOp.

tools/FileRefExtractor/BuildMode/Ast.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
use AssertionError;
2222
use danog\MadelineProto\FileRefExtractor\BuildMode;
23-
use danog\MadelineProto\FileRefExtractor\ExtractorType;
2423
use danog\MadelineProto\FileRefExtractor\TLContext;
2524
use danog\MadelineProto\Magic;
2625
use danog\MadelineProto\MTProto;

tools/FileRefExtractor/Ops/CopyMethodCallOp.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
namespace danog\MadelineProto\FileRefExtractor\Ops;
2020

2121
use danog\MadelineProto\FileRefExtractor\ActionOp;
22+
use danog\MadelineProto\FileRefExtractor\Path;
2223
use danog\MadelineProto\FileRefExtractor\TLContext;
2324
use Webmozart\Assert\Assert;
2425

@@ -42,7 +43,7 @@ public function build(TLContext $tl): void
4243
$args = [];
4344
foreach ($method['params'] as $arg) {
4445
if (isset($arg['pow'])) {
45-
$args[$arg['name']] = new CopyOp([[$this->method, $arg['name'], CopyOp::FLAG_PASSTHROUGH]]);
46+
$args[$arg['name']] = new CopyOp([[$this->method, $arg['name'], Path::FLAG_PASSTHROUGH]]);
4647
} else {
4748
$args[$arg['name']] = new CopyOp([[$this->method, $arg['name']]]);
4849
}
@@ -52,6 +53,7 @@ public function build(TLContext $tl): void
5253
$args,
5354
$this->stored_constructor
5455
);
56+
$result = $result->normalize([], $this->method, false);
5557

5658
$result->build($tl);
5759
}

tools/FileRefExtractor/Ops/CopyOp.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,45 @@
1818

1919
namespace danog\MadelineProto\FileRefExtractor\Ops;
2020

21-
use danog\MadelineProto\FileRefExtractor\FieldExtractorOp;
21+
use danog\MadelineProto\FileRefExtractor\FieldTransformationOp;
22+
use danog\MadelineProto\FileRefExtractor\Path;
2223
use danog\MadelineProto\FileRefExtractor\TLContext;
2324
use danog\MadelineProto\FileRefExtractor\TypedOp;
24-
use Webmozart\Assert\Assert;
2525

26-
final readonly class CopyOp extends FieldExtractorOp
26+
final readonly class CopyOp implements FieldTransformationOp
2727
{
28+
private Path $path;
29+
/** @param Path|list<list{0: string, 1: string, 2?: int-mask-of<self::FLAG_*>|TypedOp}> $path */
30+
public function __construct(
31+
array|Path $path,
32+
) {
33+
$this->path = $path instanceof Path ? $path : new Path($path);
34+
}
35+
36+
public function getType(TLContext $tl): string
37+
{
38+
return $this->path->getType($tl);
39+
}
40+
41+
public function normalize(array $stack, string $current, bool $ignoreFlag): ?TypedOp
42+
{
43+
$path = $this->path->normalize($stack, $current, $ignoreFlag);
44+
if ($path === null) {
45+
return null;
46+
}
47+
if ($path !== $this->path) {
48+
return new self($path);
49+
}
50+
return $this;
51+
}
2852
public function build(TLContext $tl): array
2953
{
3054
return [
3155
'_' => 'typedOp',
32-
'type' => $this->getType($tl),
56+
'type' => $this->path->getType($tl),
3357
'op' => [
3458
'_' => 'copyOp',
35-
'from' => $this->buildPath($tl),
59+
'from' => $this->path->buildPath($tl, 'extractAndStore'),
3660
],
3761
];
3862
}

tools/FileRefExtractor/Ops/ExtractFromParentOp.php

Lines changed: 0 additions & 63 deletions
This file was deleted.

tools/FileRefExtractor/Ops/GetInputChannelOp.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818

1919
namespace danog\MadelineProto\FileRefExtractor\Ops;
2020

21-
use danog\MadelineProto\FileRefExtractor\FieldExtractorOp;
2221
use danog\MadelineProto\FileRefExtractor\FieldTransformationOp;
22+
use danog\MadelineProto\FileRefExtractor\Path;
2323
use danog\MadelineProto\FileRefExtractor\TLContext;
2424
use Webmozart\Assert\Assert;
2525

2626
final readonly class GetInputChannelOp implements FieldTransformationOp
2727
{
28-
public function __construct(private readonly FieldExtractorOp $path)
29-
{
28+
public function __construct(
29+
private Path $path,
30+
) {
3031
}
3132

3233
public function normalize(array $stack, string $current, bool $ignoreFlag): ?\danog\MadelineProto\FileRefExtractor\TypedOp
@@ -48,16 +49,23 @@ public function getType(TLContext $tl): string
4849
public function build(TLContext $tl): array
4950
{
5051
$type = $this->path->getType($tl);
51-
if ($type === 'InputChannel') {
52-
return $this->path->build($tl);
53-
}
5452
if ($type === 'long') {
5553
return [
5654
'_' => 'typedOp',
5755
'type' => $this->getType($tl),
5856
'op' => [
5957
'_' => 'getInputChannelByIdOp',
60-
'path' => $this->path->build($tl),
58+
'path' => $this->path->buildPath($tl, 'extractAndStore'),
59+
],
60+
];
61+
}
62+
if ($type === 'InputChannel') {
63+
return [
64+
'_' => 'typedOp',
65+
'type' => $this->getType($tl),
66+
'op' => [
67+
'_' => 'getInputChannelByIdOp',
68+
'path' => $this->path->buildPath($tl, 'extractChannelIdFromInputChannelAndStore'),
6169
],
6270
];
6371
}
@@ -66,8 +74,8 @@ public function build(TLContext $tl): array
6674
'_' => 'typedOp',
6775
'type' => $this->getType($tl),
6876
'op' => [
69-
'_' => 'getInputChannelOp',
70-
'path' => $this->path->build($tl),
77+
'_' => 'getInputChannelByIdOp',
78+
'path' => $this->path->buildPath($tl, 'extractChannelIdFromChannelAndStore'),
7179
],
7280
];
7381
}

tools/FileRefExtractor/Ops/GetInputPeerOp.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818

1919
namespace danog\MadelineProto\FileRefExtractor\Ops;
2020

21-
use danog\MadelineProto\FileRefExtractor\FieldExtractorOp;
2221
use danog\MadelineProto\FileRefExtractor\FieldTransformationOp;
22+
use danog\MadelineProto\FileRefExtractor\Path;
2323
use danog\MadelineProto\FileRefExtractor\TLContext;
2424
use Webmozart\Assert\Assert;
2525

2626
final readonly class GetInputPeerOp implements FieldTransformationOp
2727
{
28-
public function __construct(private readonly FieldExtractorOp $path)
29-
{
28+
public function __construct(
29+
private Path $path,
30+
) {
3031
}
3132

3233
public function normalize(array $stack, string $current, bool $ignoreFlag): ?\danog\MadelineProto\FileRefExtractor\TypedOp
@@ -49,15 +50,23 @@ public function build(TLContext $tl): array
4950
{
5051
$type = $this->path->getType($tl);
5152
if ($type === 'InputPeer') {
52-
return $this->path->build($tl);
53+
return [
54+
'_' => 'typedOp',
55+
'type' => $this->getType($tl),
56+
'op' => [
57+
'_' => 'getInputPeerByIdOp',
58+
'path' => $this->path->buildPath($tl, 'extractPeerIdFromInputPeerAndStore'),
59+
],
60+
];
5361
}
5462
Assert::eq($type, 'Peer', "Expected type 'Peer' at position {$this->path->path[0][0]} but got '$type'");
63+
5564
return [
5665
'_' => 'typedOp',
5766
'type' => $this->getType($tl),
5867
'op' => [
59-
'_' => 'getInputPeerOp',
60-
'path' => $this->path->build($tl),
68+
'_' => 'getInputPeerByIdOp',
69+
'path' => $this->path->buildPath($tl, 'extractPeerIdFromPeerAndStore'),
6170
],
6271
];
6372
}

tools/FileRefExtractor/Ops/GetInputUserOp.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818

1919
namespace danog\MadelineProto\FileRefExtractor\Ops;
2020

21-
use danog\MadelineProto\FileRefExtractor\FieldExtractorOp;
2221
use danog\MadelineProto\FileRefExtractor\FieldTransformationOp;
22+
use danog\MadelineProto\FileRefExtractor\Path;
2323
use danog\MadelineProto\FileRefExtractor\TLContext;
2424
use Webmozart\Assert\Assert;
2525

2626
final readonly class GetInputUserOp implements FieldTransformationOp
2727
{
28-
public function __construct(private readonly FieldExtractorOp $path)
29-
{
28+
public function __construct(
29+
private Path $path,
30+
) {
3031
}
3132

3233
public function normalize(array $stack, string $current, bool $ignoreFlag): ?\danog\MadelineProto\FileRefExtractor\TypedOp
@@ -49,15 +50,22 @@ public function build(TLContext $tl): array
4950
{
5051
$type = $this->path->getType($tl);
5152
if ($type === 'InputUser') {
52-
return $this->path->build($tl);
53+
return [
54+
'_' => 'typedOp',
55+
'type' => $this->getType($tl),
56+
'op' => [
57+
'_' => 'getInputUserByIdOp',
58+
'path' => $this->path->buildPath($tl, 'extractUserIdFromInputUserAndStore'),
59+
],
60+
];
5361
}
5462
if ($type === 'long') {
5563
return [
5664
'_' => 'typedOp',
5765
'type' => $this->getType($tl),
5866
'op' => [
5967
'_' => 'getInputUserByIdOp',
60-
'path' => $this->path->build($tl),
68+
'path' => $this->path->buildPath($tl, 'extractAndStore'),
6169
],
6270
];
6371
}
@@ -66,8 +74,8 @@ public function build(TLContext $tl): array
6674
'_' => 'typedOp',
6775
'type' => $this->getType($tl),
6876
'op' => [
69-
'_' => 'getInputUserOp',
70-
'path' => $this->path->build($tl),
77+
'_' => 'getInputUserByIdOp',
78+
'path' => $this->path->buildPath($tl, 'extractUserIdFromUserAndStore'),
7179
],
7280
];
7381
}

0 commit comments

Comments
 (0)