Fix get_message_history not returning sender on channels (closes #110)

This commit is contained in:
Lonami Exo 2017-06-15 09:41:01 +02:00
parent fc915b2284
commit 92088383f7
2 changed files with 12 additions and 3 deletions

View File

@ -447,8 +447,10 @@ class TelegramClient(TelegramBareClient):
total_messages = getattr(result, 'count', len(result.messages))
# Iterate over all the messages and find the sender User
entities = [find_user_or_chat(msg.from_id, result.users, result.chats)
for msg in result.messages]
entities = [find_user_or_chat(m.from_id, result.users, result.chats)
if m.from_id is not None else
find_user_or_chat(m.to_id, result.users, result.chats)
for m in result.messages]
return total_messages, result.messages, entities

View File

@ -162,7 +162,14 @@ class InteractiveTelegramClient(TelegramClient):
for msg, sender in zip(
reversed(messages), reversed(senders)):
# Get the name of the sender if any
name = sender.first_name if sender else '???'
if sender:
name = getattr(sender, 'first_name', None)
if not name:
name = getattr(sender, 'title')
if not name:
name = '???'
else:
name = '???'
# Format the message content
if getattr(msg, 'media', None):