mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-07-12 17:12:23 +03:00
Apply seq if all updates were applied
Instead of only checking if *any* update *with pts* was applied. Should fix #4602.
This commit is contained in:
parent
ae9c798e2c
commit
b2809e0b57
|
@ -460,30 +460,14 @@ class MessageBox:
|
|||
return pts.pts - pts.pts_count if pts else 0
|
||||
|
||||
reset_deadlines = set() # temporary buffer
|
||||
any_pts_applied = [False] # using a list to pass "by reference"
|
||||
|
||||
result.extend(filter(None, (
|
||||
self.apply_pts_info(u, reset_deadlines=reset_deadlines, any_pts_applied=any_pts_applied)
|
||||
self.apply_pts_info(u, reset_deadlines=reset_deadlines)
|
||||
# Telegram can send updates out of order (e.g. ReadChannelInbox first
|
||||
# and then NewChannelMessage, both with the same pts, but the count is
|
||||
# 0 and 1 respectively), so we sort them first.
|
||||
for u in sorted(updates, key=_sort_gaps))))
|
||||
|
||||
# > If the updates were applied, local *Updates* state must be updated
|
||||
# > with `seq` (unless it's 0) and `date` from the constructor.
|
||||
#
|
||||
# By "were applied", we assume it means "some other pts was applied".
|
||||
# Updates which can be applied in any order, such as `UpdateChat`,
|
||||
# should not cause `seq` to be updated (or upcoming updates such as
|
||||
# `UpdateChatParticipant` could be missed).
|
||||
if any_pts_applied[0]:
|
||||
if __debug__:
|
||||
self._trace('Updating seq as local pts was updated too')
|
||||
if date != epoch():
|
||||
self.date = date
|
||||
if seq != NO_SEQ:
|
||||
self.seq = seq
|
||||
|
||||
self.reset_deadlines(reset_deadlines, next_updates_deadline())
|
||||
|
||||
if self.possible_gaps:
|
||||
|
@ -510,6 +494,16 @@ class MessageBox:
|
|||
|
||||
real_result.extend(u for u in result if not u._self_outgoing)
|
||||
|
||||
if result and not self.possible_gaps:
|
||||
# > If the updates were applied, local *Updates* state must be updated
|
||||
# > with `seq` (unless it's 0) and `date` from the constructor.
|
||||
if __debug__:
|
||||
self._trace('Updating seq as all updates were applied')
|
||||
if date != epoch():
|
||||
self.date = date
|
||||
if seq != NO_SEQ:
|
||||
self.seq = seq
|
||||
|
||||
return (users, chats)
|
||||
|
||||
# Tries to apply the input update if its `PtsInfo` follows the correct order.
|
||||
|
@ -522,7 +516,6 @@ class MessageBox:
|
|||
update,
|
||||
*,
|
||||
reset_deadlines,
|
||||
any_pts_applied=[True], # mutable default is fine as it's write-only
|
||||
):
|
||||
# This update means we need to call getChannelDifference to get the updates from the channel
|
||||
if isinstance(update, tl.UpdateChannelTooLong):
|
||||
|
@ -574,7 +567,6 @@ class MessageBox:
|
|||
return None
|
||||
else:
|
||||
# Apply
|
||||
any_pts_applied[0] = True
|
||||
if __debug__:
|
||||
self._trace('Applying update pts since local pts %r = %r: %s', local_pts, pts, update)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user