mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 01:16:35 +03:00
Fix get(_input)_users in ChatAction with no service msg
This commit is contained in:
parent
0814a20ec4
commit
9a86447b6e
|
@ -381,7 +381,8 @@ class ChatAction(EventBuilder):
|
|||
if not self._user_ids:
|
||||
return []
|
||||
|
||||
if self._users is None or len(self._users) != len(self._user_ids):
|
||||
# Note: we access the property first so that it fills if needed
|
||||
if (self.users is None or len(self._users) != len(self._user_ids)) and self.action_message:
|
||||
await self.action_message._reload_message()
|
||||
self._users = [
|
||||
u for u in self.action_message.action_entities
|
||||
|
@ -397,19 +398,31 @@ class ChatAction(EventBuilder):
|
|||
if self._input_users is None and self._user_ids:
|
||||
self._input_users = []
|
||||
for user_id in self._user_ids:
|
||||
# First try to get it from our entities
|
||||
try:
|
||||
self._input_users.append(utils.get_input_peer(self._entities[user_id]))
|
||||
continue
|
||||
except (KeyError, TypeError) as e:
|
||||
pass
|
||||
|
||||
# If missing, try from the entity cache
|
||||
try:
|
||||
self._input_users.append(self._client._entity_cache[user_id])
|
||||
continue
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
return self._input_users or []
|
||||
|
||||
async def get_input_users(self):
|
||||
"""
|
||||
Returns `input_users` but will make an API call if necessary.
|
||||
"""
|
||||
self._input_users = None
|
||||
if self._input_users is None:
|
||||
await self.action_message._reload_message()
|
||||
if not self._user_ids:
|
||||
return []
|
||||
|
||||
# Note: we access the property first so that it fills if needed
|
||||
if (self.input_users is None or len(self._input_users) != len(self._user_ids)) and self.action_message:
|
||||
self._input_users = [
|
||||
utils.get_input_peer(u)
|
||||
for u in self.action_message.action_entities
|
||||
|
|
0
tests/telethon/crypto/__init__.py
Normal file
0
tests/telethon/crypto/__init__.py
Normal file
0
tests/telethon/events/__init__.py
Normal file
0
tests/telethon/events/__init__.py
Normal file
67
tests/telethon/events/test_chataction.py
Normal file
67
tests/telethon/events/test_chataction.py
Normal file
|
@ -0,0 +1,67 @@
|
|||
import pytest
|
||||
|
||||
from telethon import TelegramClient, events, types, utils
|
||||
|
||||
|
||||
def get_client():
|
||||
return TelegramClient(None, 1, '1')
|
||||
|
||||
|
||||
def get_user_456():
|
||||
return types.User(
|
||||
id=456,
|
||||
access_hash=789,
|
||||
first_name='User 123'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_input_users_no_action_message_no_entities():
|
||||
event = events.ChatAction.build(types.UpdateChatParticipantDelete(
|
||||
chat_id=123,
|
||||
user_id=456,
|
||||
version=1
|
||||
))
|
||||
event._set_client(get_client())
|
||||
|
||||
assert await event.get_input_users() == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_input_users_no_action_message():
|
||||
user = get_user_456()
|
||||
event = events.ChatAction.build(types.UpdateChatParticipantDelete(
|
||||
chat_id=123,
|
||||
user_id=456,
|
||||
version=1
|
||||
))
|
||||
event._set_client(get_client())
|
||||
event._entities[user.id] = user
|
||||
|
||||
assert await event.get_input_users() == [utils.get_input_peer(user)]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_users_no_action_message_no_entities():
|
||||
event = events.ChatAction.build(types.UpdateChatParticipantDelete(
|
||||
chat_id=123,
|
||||
user_id=456,
|
||||
version=1
|
||||
))
|
||||
event._set_client(get_client())
|
||||
|
||||
assert await event.get_users() == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_users_no_action_message():
|
||||
user = get_user_456()
|
||||
event = events.ChatAction.build(types.UpdateChatParticipantDelete(
|
||||
chat_id=123,
|
||||
user_id=456,
|
||||
version=1
|
||||
))
|
||||
event._set_client(get_client())
|
||||
event._entities[user.id] = user
|
||||
|
||||
assert await event.get_users() == [user]
|
0
tests/telethon/extensions/__init__.py
Normal file
0
tests/telethon/extensions/__init__.py
Normal file
Loading…
Reference in New Issue
Block a user