Skip to content

Commit fa055a7

Browse files
committed
Add a missing context
1 parent 2607067 commit fa055a7

File tree

9 files changed

+85
-4
lines changed

9 files changed

+85
-4
lines changed

src/TL_file_ref_map_schema.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,17 @@
534534
],
535535
"type": "TypedOpOp"
536536
},
537+
{
538+
"id": "-38562396",
539+
"predicate": "bytesLiteralOp",
540+
"params": [
541+
{
542+
"name": "value",
543+
"type": "bytes"
544+
}
545+
],
546+
"type": "TypedOpOp"
547+
},
537548
{
538549
"id": "937457937",
539550
"predicate": "boolLiteralOp",

src/TL_file_ref_map_schema.tl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ vectorOp#f8fb8f72 values:Vector<TypedOp> = TypedOpOp;
6969
intLiteralOp#cbfabe7c value:int = TypedOpOp;
7070
longLiteralOp#d08b8d3a value:long = TypedOpOp;
7171
stringLiteralOp#2b56ea8e value:string = TypedOpOp;
72+
bytesLiteralOp#fdb395a4 value:bytes = TypedOpOp;
7273
boolLiteralOp#37e07911 value:Bool = TypedOpOp;
7374
doubleLiteralOp#3651e3bf value:double = TypedOpOp;
7475
themeFormatLiteralOp#8e4f9208 = TypedOpOp;

src/file_ref_map.dat

1.57 KB
Binary file not shown.

src/file_ref_map.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tools/FileRefExtractor/BuildMode/Ast.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ private function stringifySchema(string $constructor, array $params, string $cTy
143143
if ($constructor !== 'fileSourceBotApp'
144144
&& $constructor !== 'fileSourceTheme'
145145
&& $constructor !== 'fileSourceWallPaper'
146+
&& $constructor !== 'fileSourceSavedMusic'
146147
) {
147148
Assert::notContains($name, 'access_hash', "$constructor cannot contain an access hash");
148149
}

tools/FileRefExtractor/FileRefGenerator.php

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,28 @@ public static function generate(int|string $layer, string $inputSchema, string $
217217
);
218218
$locations['help.getPremiumPromo'][] = new CopyMethodCallOp('help.getPremiumPromo', 'fileSourcePremiumPromo');
219219

220+
$locations['help.getAppUpdate'][] = new Noop("Don't handle file references from ephemeral app update info");
221+
$locations['help.getRecentMeUrls'][] = new Noop("Don't handle file references from recent t.me URLs");
222+
223+
$stickerMethods = [
224+
'messages.getAttachedStickers' => true,
225+
];
226+
foreach ([
227+
'messages.FeaturedStickers',
228+
'messages.StickerSet',
229+
'messages.ArchivedStickers',
230+
'messages.Stickers',
231+
'messages.StickerSetInstallResult',
232+
'messages.FoundStickerSets',
233+
'messages.MyStickers',
234+
'messages.FavedStickers',
235+
'messages.FoundStickers',
236+
] as $stickerType) {
237+
foreach ($TL->getMethodsOfType($stickerType) as $method => $_) {
238+
$stickerMethods[$method] = true;
239+
}
240+
}
241+
220242
$starMethods = [];
221243
foreach ($TL->getMethodsOfType('payments.StarsStatus') as $method => $_) {
222244
$starMethods[$method] = true;
@@ -370,13 +392,40 @@ public static function generate(int|string $layer, string $inputSchema, string $
370392

371393
$locations['messages.getWebPagePreview'][] = new Noop("No locations are added for the method call, as it doesn't use persistent IDs as input; the location is instead extracted from the persistent IDs in the returned WebPage object");
372394

395+
foreach (['users.getSavedMusic', 'users.getSavedMusicByID'] as $m) {
396+
$locations['document'][] = new CallOp(
397+
'users.getSavedMusicByID',
398+
[
399+
'id' => new GetInputUserOp(new Path([[$m, 'id']], true)),
400+
'documents' => new ArrayOp(
401+
new ConstructorOp(
402+
'inputDocument',
403+
[
404+
'id' => new CopyOp([['document', 'id']]),
405+
'access_hash' => new CopyOp([['document', 'access_hash']]),
406+
'file_reference' => new PrimitiveLiteralOp('bytes', ''),
407+
],
408+
),
409+
),
410+
],
411+
'fileSourceSavedMusic'
412+
);
413+
}
414+
373415
// Ignore these for now
374-
foreach (['payments.ResaleStarGifts', 'payments.StarGiftUpgradePreview', 'StarGift'] as $type) {
416+
foreach (['payments.ResaleStarGifts', 'payments.StarGiftUpgradePreview', 'StarGift', 'StarGiftCollection', 'payments.StarGiftCollections'] as $type) {
375417
foreach ($TL->getConstructorsOfType($type) as $constructor => $_) {
418+
if ($constructor === 'payments.starGiftCollectionsNotModified') {
419+
continue;
420+
}
376421
$locations[$constructor][] = new Noop('Contexts for star gifts are not yet implemented');
377422
}
378423
}
379424

425+
$locations['messages.getCustomEmojiDocuments'][] = new Noop("Do not store file references in this context");
426+
427+
$locations['account.uploadTheme'][] = new Noop('A freshly uploaded theme file will obtain a context only once it is created via account.createTheme');
428+
380429
$recurse = static function (Closure $onStackEnd, string $type, array &$stack, array &$stackTypes) use ($TL, &$recurse): void {
381430
if ($type === 'Update' || $type === 'Updates') {
382431
$onStackEnd($stack);
@@ -504,9 +553,10 @@ public static function generate(int|string $layer, string $inputSchema, string $
504553
$stack = [[$constructor, 'file_reference']];
505554
$stackTypes = [$type => 1];
506555
$recurse(
507-
static function (array $stack) use ($locations, $TL, $tmp, &$validated, $storyMethods, $starMethods): void {
556+
static function (array $stack) use ($locations, $TL, $tmp, &$validated, $storyMethods, $starMethods, $stickerMethods): void {
508557
$slice = [];
509558
$hadAny = false;
559+
$hadAnyWithNoFlags = false;
510560
$skippedDueToFlags = [];
511561
$top = end($stack)[0];
512562
for ($x = \count($stack)-1; $x >= 0; $x--) {
@@ -525,12 +575,16 @@ static function (array $stack) use ($locations, $TL, $tmp, &$validated, $storyMe
525575
$skippedDueToFlags []= $op;
526576
continue;
527577
}
578+
$hadAnyWithNoFlags = true;
528579
}
529580
$slice[] = $pair;
530581
}
531582
if (!$hadAny) {
532583
throw new AssertionError("Uncovered path: " . json_encode($stack));
533584
}
585+
if ($hadAnyWithNoFlags) {
586+
return;
587+
}
534588
if ($skippedDueToFlags) {
535589
if ($top === 'updateStory'
536590
|| $top === 'peerStories'
@@ -545,6 +599,11 @@ static function (array $stack) use ($locations, $TL, $tmp, &$validated, $storyMe
545599
|| $top === 'channels.getFullChannel'
546600
|| $top === 'users.getFullUser'
547601
// The three above are related to botInfo, ignore as we already store a context for the chat info.
602+
603+
|| isset($stickerMethods[$top])
604+
|| $top === 'messages.getRecentStickers'
605+
|| $top === 'updateNewStickerSet'
606+
// The above are covered by the GetInputStickerSet document context
548607
) {
549608
return;
550609
}

tools/FileRefExtractor/Ops/GetInputStickerSet.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public function __construct(
3232

3333
public function normalize(array $stack, string $current, bool $ignoreFlag): ?\danog\MadelineProto\FileRefExtractor\TypedOp
3434
{
35+
if ($ignoreFlag) {
36+
return null;
37+
}
3538
$path = $this->path->normalize($stack, $current, $ignoreFlag);
3639
if ($path === null) {
3740
return null;

tools/FileRefExtractor/Ops/PrimitiveLiteralOp.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
{
2727
public function __construct(private readonly string $type, private readonly mixed $value)
2828
{
29-
Assert::inArray($type, ['int', 'long', 'string', 'bool', 'float'], "Invalid type '$type' for LiteralOp");
29+
Assert::inArray($type, ['int', 'long', 'string', 'bool', 'float', 'bytes'], "Invalid type '$type' for LiteralOp");
3030
}
3131

3232
public function normalize(array $stack, string $current, bool $ignoreFlag): ?\danog\MadelineProto\FileRefExtractor\TypedOp
@@ -50,6 +50,7 @@ public function build(TLContext $tl): array
5050
'string' => 'stringLiteralOp',
5151
'bool' => 'boolLiteralOp',
5252
'double' => 'doubleLiteralOp',
53+
'bytes' => 'bytesLiteralOp',
5354
},
5455
'value' => $this->value,
5556
],

tools/FileRefExtractor/Path.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ public function buildPath(TLContext $tl, string $extractor): string
165165
$type = "flags.$flag?$type";
166166
}
167167
$name = $tl->buildMode->curKey;
168+
if (\in_array($this->path[0][0], ['users.getSavedMusic', 'users.getSavedMusicByID'], true)
169+
&& $this->path[0][1] === 'id'
170+
) {
171+
$name = 'user_id';
172+
}
168173
Assert::notNull($name);
169174
if (isset($tl->buildMode->stored[$name])) {
170175
throw new AssertionError("Need custom name (already have $name) for ".json_encode($this->path));

0 commit comments

Comments
 (0)