Browse Source

Fix some potential bugs

Tulir Asokan 4 years ago
parent
commit
61ac264aa3
2 changed files with 4 additions and 3 deletions
  1. 0 1
      mauigpapi/types/thread_item.py
  2. 4 2
      mautrix_instagram/portal.py

+ 0 - 1
mauigpapi/types/thread_item.py

@@ -251,7 +251,6 @@ class ReelMediaShareItem(MediaShareItem, SerializableAttrs['ReelMediaShareItem']
     # These three are apparently sometimes not present
     # These three are apparently sometimes not present
     # TODO enum?
     # TODO enum?
     caption_position: Optional[int] = None
     caption_position: Optional[int] = None
-    caption: Optional[Caption] = None
     is_reel_media: Optional[bool] = None
     is_reel_media: Optional[bool] = None
     timezone_offset: Optional[int] = None
     timezone_offset: Optional[int] = None
     # likers: List[TODO]
     # likers: List[TODO]

+ 4 - 2
mautrix_instagram/portal.py

@@ -26,7 +26,7 @@ import magic
 from mauigpapi.types import (Thread, ThreadUser, ThreadItem, RegularMediaItem, MediaType,
 from mauigpapi.types import (Thread, ThreadUser, ThreadItem, RegularMediaItem, MediaType,
                              ReactionStatus, Reaction, AnimatedMediaItem, ThreadItemType,
                              ReactionStatus, Reaction, AnimatedMediaItem, ThreadItemType,
                              VoiceMediaItem, ExpiredMediaItem, MessageSyncMessage, ReelShareType,
                              VoiceMediaItem, ExpiredMediaItem, MessageSyncMessage, ReelShareType,
-                             TypingStatus, ThreadUserLastSeenAt)
+                             TypingStatus, ThreadUserLastSeenAt, MediaShareItem)
 from mautrix.appservice import AppService, IntentAPI
 from mautrix.appservice import AppService, IntentAPI
 from mautrix.bridge import BasePortal, NotificationDisabler, async_getter_lock
 from mautrix.bridge import BasePortal, NotificationDisabler, async_getter_lock
 from mautrix.types import (EventID, MessageEventContent, RoomID, EventType, MessageType, ImageInfo,
 from mautrix.types import (EventID, MessageEventContent, RoomID, EventType, MessageType, ImageInfo,
@@ -471,8 +471,10 @@ class Portal(DBPortal, BasePortal):
             prefix_content.format = Format.HTML
             prefix_content.format = Format.HTML
             prefix_content.formatted_body = prefix_html
             prefix_content.formatted_body = prefix_html
         content = TextMessageEventContent(msgtype=MessageType.TEXT, body=item.reel_share.text)
         content = TextMessageEventContent(msgtype=MessageType.TEXT, body=item.reel_share.text)
+        if not content.body and isinstance(media, MediaShareItem):
+            content.body = media.caption.text if media.caption else ""
         if not content.body:
         if not content.body:
-            content.body = (media.caption.text if media.caption else None) or "<no caption>"
+            content.body = "<no caption>"
         await self._send_message(intent, prefix_content, timestamp=item.timestamp // 1000)
         await self._send_message(intent, prefix_content, timestamp=item.timestamp // 1000)
         if isinstance(media, ExpiredMediaItem):
         if isinstance(media, ExpiredMediaItem):
             # TODO send message about expired story
             # TODO send message about expired story