Fix handling messages with PhotoEmpty. Fixes #494

This commit is contained in:
Tulir Asokan
2020-07-06 12:41:04 +03:00
parent 29cc98a7f5
commit bbfcc9d7d8
2 changed files with 7 additions and 3 deletions
+2 -3
View File
@@ -208,9 +208,8 @@ class BasePortal(ABC):
def _get_largest_photo_size(photo: Union[Photo, Document]
) -> Tuple[Optional[InputPhotoFileLocation],
Optional[TypePhotoSize]]:
if not photo:
return None, None
if isinstance(photo, Document) and not photo.thumbs:
if not photo or isinstance(photo, PhotoEmpty) or (isinstance(photo, Document)
and not photo.thumbs):
return None, None
largest = max(photo.thumbs if isinstance(photo, Document) else photo.sizes,
+5
View File
@@ -74,6 +74,11 @@ class PortalTelegram(BasePortal, ABC):
async def handle_telegram_photo(self, source: 'AbstractUser', intent: IntentAPI, evt: Message,
relates_to: RelatesTo = None) -> Optional[EventID]:
loc, largest_size = self._get_largest_photo_size(evt.media.photo)
if loc is None:
content = TextMessageEventContent(msgtype=MessageType.TEXT,
body="Failed to bridge image",
external_url=self._get_external_url(evt))
return await self._send_message(intent, content, timestamp=evt.date)
file = await util.transfer_file_to_matrix(source.client, intent, loc,
encrypt=self.encrypted)
if not file: