@@ -26,6 +26,7 @@ def __init__(self):
2626 "sender" : types .InputPeerChannel (33 , 303 ),
2727 }
2828 self .album = []
29+ self .build_updates = None # callable(request) -> updates echoing its random_ids
2930
3031 async def resolve (self , identifier , client ):
3132 assert client is self
@@ -39,6 +40,10 @@ async def __call__(self, request):
3940 bytes (request ) # Exercise the real SDK serializer, not a fake TL schema.
4041 if self .error :
4142 raise self .error
43+ if self .build_updates :
44+ return types .Updates (
45+ self .build_updates (request ), [], [], datetime .now (timezone .utc ), 1
46+ )
4247 return self .result
4348
4449 async def forward_messages (self , * args , ** kwargs ):
@@ -91,7 +96,10 @@ async def test_legacy_album_and_explicit_batch_are_unchanged(client, message_id,
9196)
9297async def test_routed_forward_uses_native_request (client , route ):
9398 result = await messages .forward_message ("source" , [10 , 12 ], "destination" , ** route )
94- assert result == "2 messages forwarded from source to destination."
99+ assert result == (
100+ "2 messages forwarded from source to destination. "
101+ "Destination message IDs: not returned by Telegram."
102+ )
95103 assert client .legacy == []
96104 assert client .reads == []
97105 assert len (client .requests ) == 1
@@ -252,3 +260,49 @@ async def test_discovery_readonly_account_fanout(client, monkeypatch):
252260 result = await messages .get_send_as ("destination" )
253261 assert "[first]" in result and "[second]" in result
254262 assert len (client .requests ) == 2
263+
264+
265+ @pytest .mark .asyncio
266+ async def test_native_forward_reports_request_correlated_destination_ids (client ):
267+ def updates (request ):
268+ first , second = request .random_id
269+ return [
270+ types .UpdateMessageID (id = 999 , random_id = first ^ second ^ 1 ), # unrelated request
271+ types .UpdateMessageID (id = 701 , random_id = second ), # out of order
272+ types .UpdateNewMessage ( # never inferred from
273+ message = types .Message (id = 555 , peer_id = types .PeerUser (22 ), message = "other" ),
274+ pts = 1 ,
275+ pts_count = 1 ,
276+ ),
277+ types .UpdateMessageID (id = 700 , random_id = first ),
278+ ]
279+
280+ client .build_updates = updates
281+ result = await messages .forward_message ("source" , [10 , 12 ], "destination" , topic_id = 7 )
282+ assert result == (
283+ "2 messages forwarded from source to destination. Destination message IDs: [700, 701]."
284+ )
285+ assert client .legacy == []
286+
287+
288+ @pytest .mark .asyncio
289+ async def test_native_forward_reports_only_ids_telegram_returned (client ):
290+ def updates (request ):
291+ return [types .UpdateMessageID (id = 701 , random_id = request .random_id [1 ])]
292+
293+ client .build_updates = updates
294+ result = await messages .forward_message ("source" , [10 , 12 ], "destination" , silent = True )
295+ assert result .endswith ("Destination message IDs: [701]." )
296+
297+
298+ @pytest .mark .asyncio
299+ async def test_native_forward_states_when_no_ids_were_returned (client ):
300+ def updates (request ):
301+ return [types .UpdateMessageID (id = 999 , random_id = request .random_id [0 ] ^ 1 )]
302+
303+ client .build_updates = updates
304+ result = await messages .forward_message ("source" , 10 , "destination" , drop_author = True )
305+ assert result == (
306+ "Message 10 forwarded from source to destination. "
307+ "Destination message IDs: not returned by Telegram."
308+ )
0 commit comments