Skip to content

Commit

Permalink
Handle DestroySessionRes
Browse files Browse the repository at this point in the history
Should close #1706.
  • Loading branch information
Lonami committed Feb 27, 2021
1 parent a955138 commit 292a36f
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions telethon/network/mtprotosender.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
from ..extensions import BinaryReader
from ..tl.core import RpcResult, MessageContainer, GzipPacked
from ..tl.functions.auth import LogOutRequest
from ..tl.functions import PingRequest
from ..tl.functions import PingRequest, DestroySessionRequest
from ..tl.types import (
MsgsAck, Pong, BadServerSalt, BadMsgNotification, FutureSalts,
MsgNewDetailedInfo, NewSessionCreated, MsgDetailedInfo, MsgsStateReq,
MsgsStateInfo, MsgsAllInfo, MsgResendReq, upload
MsgsStateInfo, MsgsAllInfo, MsgResendReq, upload, DestroySessionOk, DestroySessionNone,
)
from ..crypto import AuthKey
from ..helpers import retry_range
Expand Down Expand Up @@ -108,6 +108,8 @@ def __init__(self, auth_key, *, loggers,
MsgsStateReq.CONSTRUCTOR_ID: self._handle_state_forgotten,
MsgResendReq.CONSTRUCTOR_ID: self._handle_state_forgotten,
MsgsAllInfo.CONSTRUCTOR_ID: self._handle_msg_all,
DestroySessionOk: self._handle_destroy_session,
DestroySessionNone: self._handle_destroy_session,
}

# Public API
Expand Down Expand Up @@ -807,3 +809,19 @@ async def _handle_msg_all(self, message):
"""
Handles :tl:`MsgsAllInfo` by doing nothing (yet).
"""

async def _handle_destroy_session(self, message):
"""
Handles both :tl:`DestroySessionOk` and :tl:`DestroySessionNone`.
It behaves pretty much like handling an RPC result.
"""
for msg_id, state in self._pending_state.items():
if isinstance(state.request, DestroySessionRequest)\
and state.request.session_id == message.obj.session_id:
break
else:
return

del self._pending_state[msg_id]
if not state.future.cancelled():
state.future.set_result(message.obj)

0 comments on commit 292a36f

Please sign in to comment.