Add Conversation to the sync magic module

This commit is contained in:
Lonami Exo 2018-08-05 11:05:01 +02:00
parent 48113851a8
commit cc067b2569
2 changed files with 8 additions and 2 deletions

View File

@ -18,7 +18,7 @@ from async_generator import isasyncgenfunction
from .client.telegramclient import TelegramClient from .client.telegramclient import TelegramClient
from .tl.custom import ( from .tl.custom import (
Draft, Dialog, MessageButton, Forward, Message, InlineResult Draft, Dialog, MessageButton, Forward, Message, InlineResult, Conversation
) )
from .tl.custom.chatgetter import ChatGetter from .tl.custom.chatgetter import ChatGetter
from .tl.custom.sendergetter import SenderGetter from .tl.custom.sendergetter import SenderGetter
@ -83,4 +83,4 @@ def syncify(*types):
syncify(TelegramClient, Draft, Dialog, MessageButton, syncify(TelegramClient, Draft, Dialog, MessageButton,
ChatGetter, SenderGetter, Forward, Message, InlineResult) ChatGetter, SenderGetter, Forward, Message, InlineResult, Conversation)

View File

@ -420,6 +420,9 @@ class Conversation(ChatGetter):
except asyncio.CancelledError: except asyncio.CancelledError:
pass pass
def __enter__(self):
return self._client.loop.run_until_complete(self.__aenter__())
async def __aenter__(self): async def __aenter__(self):
self._client._conversations[self._id] = self self._client._conversations[self._id] = self
self._input_chat = \ self._input_chat = \
@ -439,5 +442,8 @@ class Conversation(ChatGetter):
return self return self
def __exit__(self, *args):
return self._client.loop.run_until_complete(self.__aexit__(*args))
async def __aexit__(self, *args): async def __aexit__(self, *args):
del self._client._conversations[self._id] del self._client._conversations[self._id]