mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 01:16:35 +03:00
Treat messages.affected* as updateDeleteMessages
This commit is contained in:
parent
f9435aa1f6
commit
e1983b80c2
|
@ -45,6 +45,11 @@ from ...tl.types import (
|
|||
UpdateShortSentMessage,
|
||||
UpdatesTooLong,
|
||||
)
|
||||
from ...tl.types.messages import (
|
||||
AffectedFoundMessages,
|
||||
AffectedHistory,
|
||||
AffectedMessages,
|
||||
)
|
||||
from ..utils import (
|
||||
CONTAINER_MAX_LENGTH,
|
||||
CONTAINER_MAX_SIZE,
|
||||
|
@ -69,6 +74,9 @@ UPDATE_IDS = {
|
|||
UpdateShortMessage.constructor_id(),
|
||||
UpdateShortSentMessage.constructor_id(),
|
||||
UpdatesTooLong.constructor_id(),
|
||||
AffectedFoundMessages.constructor_id(),
|
||||
AffectedHistory.constructor_id(),
|
||||
AffectedMessages.constructor_id(),
|
||||
}
|
||||
|
||||
HEADER_LEN = 8 + 8 # salt, client_id
|
||||
|
|
|
@ -5,7 +5,7 @@ import time
|
|||
from abc import ABC
|
||||
from asyncio import FIRST_COMPLETED, Event, Future
|
||||
from dataclasses import dataclass
|
||||
from typing import Generic, List, Optional, Protocol, Self, Tuple, TypeVar
|
||||
from typing import Generic, List, Optional, Protocol, Self, Tuple, Type, TypeVar
|
||||
|
||||
from ..crypto import AuthKey
|
||||
from ..mtproto import (
|
||||
|
@ -21,7 +21,10 @@ from ..mtproto import (
|
|||
)
|
||||
from ..tl import Request as RemoteCall
|
||||
from ..tl.abcs import Updates
|
||||
from ..tl.core import Serializable
|
||||
from ..tl.mtproto.functions import ping_delay_disconnect
|
||||
from ..tl.types import UpdateDeleteMessages, UpdateShort
|
||||
from ..tl.types.messages import AffectedFoundMessages, AffectedHistory, AffectedMessages
|
||||
|
||||
MAXIMUM_DATA = (1024 * 1024) + (8 * 1024)
|
||||
|
||||
|
@ -315,12 +318,41 @@ class Sender:
|
|||
try:
|
||||
u = Updates.from_bytes(update)
|
||||
except ValueError:
|
||||
self._logger.warning(
|
||||
"failed to deserialize incoming update; make sure the session is not in use elsewhere: %s",
|
||||
update.hex(),
|
||||
cid = struct.unpack_from("I", update)[0]
|
||||
alt_classes: Tuple[Type[Serializable], ...] = (
|
||||
AffectedFoundMessages,
|
||||
AffectedHistory,
|
||||
AffectedMessages,
|
||||
)
|
||||
else:
|
||||
updates.append(u)
|
||||
for cls in alt_classes:
|
||||
if cid == cls.constructor_id():
|
||||
affected = cls.from_bytes(update)
|
||||
# mypy struggles with the types here quite a bit
|
||||
assert isinstance(
|
||||
affected,
|
||||
(
|
||||
AffectedFoundMessages,
|
||||
AffectedHistory,
|
||||
AffectedMessages,
|
||||
),
|
||||
)
|
||||
u = UpdateShort(
|
||||
update=UpdateDeleteMessages(
|
||||
messages=[],
|
||||
pts=affected.pts,
|
||||
pts_count=affected.pts_count,
|
||||
),
|
||||
date=0,
|
||||
)
|
||||
break
|
||||
else:
|
||||
self._logger.warning(
|
||||
"failed to deserialize incoming update; make sure the session is not in use elsewhere: %s",
|
||||
update.hex(),
|
||||
)
|
||||
continue
|
||||
|
||||
updates.append(u)
|
||||
|
||||
for msg_id, ret in result.rpc_results:
|
||||
for i, req in enumerate(self._requests):
|
||||
|
|
|
@ -61,6 +61,7 @@ class Gap(ValueError):
|
|||
return "Gap()"
|
||||
|
||||
|
||||
NO_DATE = 0 # used on adapted messages.affected* from lower layers
|
||||
NO_SEQ = 0
|
||||
|
||||
NO_PTS = 0
|
||||
|
|
|
@ -13,6 +13,7 @@ from .defs import (
|
|||
ENTRY_ACCOUNT,
|
||||
ENTRY_SECRET,
|
||||
LOG_LEVEL_TRACE,
|
||||
NO_DATE,
|
||||
NO_PTS,
|
||||
NO_SEQ,
|
||||
NO_UPDATES_TIMEOUT,
|
||||
|
@ -294,9 +295,10 @@ class MessageBox:
|
|||
if any_pts_applied:
|
||||
if __debug__:
|
||||
self._trace("updating seq as local pts was updated too")
|
||||
self.date = datetime.datetime.fromtimestamp(
|
||||
combined.date, tz=datetime.timezone.utc
|
||||
)
|
||||
if combined.date != NO_DATE:
|
||||
self.date = datetime.datetime.fromtimestamp(
|
||||
combined.date, tz=datetime.timezone.utc
|
||||
)
|
||||
if combined.seq != NO_SEQ:
|
||||
self.seq = combined.seq
|
||||
|
||||
|
|
|
@ -82,9 +82,8 @@ class Reader:
|
|||
assert self._pos <= self._len
|
||||
cid = struct.unpack("<I", self._view[self._pos - 4 : self._pos])[0]
|
||||
ty = self._get_ty(cid)
|
||||
if ty is None:
|
||||
raise ValueError(f"No type found for constructor ID: {cid:x}")
|
||||
assert issubclass(ty, cls)
|
||||
if ty is None or not issubclass(ty, cls):
|
||||
raise ValueError(f"No type found for constructor ID of {cls}: {cid:x}")
|
||||
return ty._read_from(self)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user