Handle DestroySessionRes

Should close #1706.
This commit is contained in:
Lonami Exo 2021-02-27 15:13:53 +01:00
parent a955138021
commit 292a36f760

View File

@ -16,11 +16,11 @@ from ..errors import (
from ..extensions import BinaryReader from ..extensions import BinaryReader
from ..tl.core import RpcResult, MessageContainer, GzipPacked from ..tl.core import RpcResult, MessageContainer, GzipPacked
from ..tl.functions.auth import LogOutRequest from ..tl.functions.auth import LogOutRequest
from ..tl.functions import PingRequest from ..tl.functions import PingRequest, DestroySessionRequest
from ..tl.types import ( from ..tl.types import (
MsgsAck, Pong, BadServerSalt, BadMsgNotification, FutureSalts, MsgsAck, Pong, BadServerSalt, BadMsgNotification, FutureSalts,
MsgNewDetailedInfo, NewSessionCreated, MsgDetailedInfo, MsgsStateReq, MsgNewDetailedInfo, NewSessionCreated, MsgDetailedInfo, MsgsStateReq,
MsgsStateInfo, MsgsAllInfo, MsgResendReq, upload MsgsStateInfo, MsgsAllInfo, MsgResendReq, upload, DestroySessionOk, DestroySessionNone,
) )
from ..crypto import AuthKey from ..crypto import AuthKey
from ..helpers import retry_range from ..helpers import retry_range
@ -108,6 +108,8 @@ class MTProtoSender:
MsgsStateReq.CONSTRUCTOR_ID: self._handle_state_forgotten, MsgsStateReq.CONSTRUCTOR_ID: self._handle_state_forgotten,
MsgResendReq.CONSTRUCTOR_ID: self._handle_state_forgotten, MsgResendReq.CONSTRUCTOR_ID: self._handle_state_forgotten,
MsgsAllInfo.CONSTRUCTOR_ID: self._handle_msg_all, MsgsAllInfo.CONSTRUCTOR_ID: self._handle_msg_all,
DestroySessionOk: self._handle_destroy_session,
DestroySessionNone: self._handle_destroy_session,
} }
# Public API # Public API
@ -807,3 +809,19 @@ class MTProtoSender:
""" """
Handles :tl:`MsgsAllInfo` by doing nothing (yet). 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)