From d059b12e5e2855b0dcc712c337dfa90af4806b98 Mon Sep 17 00:00:00 2001 From: bakatrouble Date: Wed, 30 Jan 2019 20:26:20 +0300 Subject: [PATCH] trying to fix initial messages loading --- aggregator/forms.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/aggregator/forms.py b/aggregator/forms.py index 91cabc6..159145c 100644 --- a/aggregator/forms.py +++ b/aggregator/forms.py @@ -17,14 +17,16 @@ class AggregationSourceForm(ModelForm): cleaned_data = super(AggregationSourceForm, self).clean() invite_link = cleaned_data.pop('invite_link') if invite_link: - with get_client() as app: - try: - upd = app.join_chat(invite_link) - chat = parse_mtproto_chat(app, upd.chats[0]) - cleaned_data['chat_id'] = chat.id - Chat.from_obj(chat, app) - except ChannelPrivate: - raise ValidationError('I was banned in this chat') + app = get_client() + app.start() + try: + upd = app.join_chat(invite_link) + except ChannelPrivate: + raise ValidationError('I was banned in this chat') + app.stop() + chat = parse_mtproto_chat(app, upd.chats[0]) + cleaned_data['chat_id'] = chat.id + Chat.from_obj(chat, app) return cleaned_data class Meta: