Browse Source

Send error messages for unbridged messages

Tulir Asokan 4 years ago
parent
commit
3fd82b4b0f
1 changed files with 8 additions and 1 deletions
  1. 8 1
      mautrix_instagram/portal.py

+ 8 - 1
mautrix_instagram/portal.py

@@ -127,6 +127,12 @@ class Portal(DBPortal, BasePortal):
             except Exception:
             except Exception:
                 self.log.exception("Failed to send delivery receipt for %s", event_id)
                 self.log.exception("Failed to send delivery receipt for %s", event_id)
 
 
+    async def _send_bridge_error(self, msg: str) -> None:
+        if self.config["bridge.delivery_error_reports"]:
+            await self._send_message(self.main_intent, TextMessageEventContent(
+                msgtype=MessageType.NOTICE,
+                body=f"\u26a0 Your message may not have been bridged: {msg}"))
+
     async def _upsert_reaction(self, existing: DBReaction, intent: IntentAPI, mxid: EventID,
     async def _upsert_reaction(self, existing: DBReaction, intent: IntentAPI, mxid: EventID,
                                message: DBMessage, sender: Union['u.User', 'p.Puppet'],
                                message: DBMessage, sender: Union['u.User', 'p.Puppet'],
                                reaction: str) -> None:
                                reaction: str) -> None:
@@ -185,12 +191,13 @@ class Portal(DBPortal, BasePortal):
                                                      upload_id=upload_resp.upload_id,
                                                      upload_id=upload_resp.upload_id,
                                                      allow_full_aspect_ratio="1")
                                                      allow_full_aspect_ratio="1")
             else:
             else:
-                # TODO add link to media for unsupported file types
+                await self._send_bridge_error("Non-image files are currently not supported")
                 return
                 return
         else:
         else:
             return
             return
         if resp.status != "ok":
         if resp.status != "ok":
             self.log.warning(f"Failed to handle {event_id}: {resp}")
             self.log.warning(f"Failed to handle {event_id}: {resp}")
+            await self._send_bridge_error(resp.payload.message)
         else:
         else:
             self._msgid_dedup.appendleft(resp.payload.item_id)
             self._msgid_dedup.appendleft(resp.payload.item_id)
             await DBMessage(mxid=event_id, mx_room=self.mxid, item_id=resp.payload.item_id,
             await DBMessage(mxid=event_id, mx_room=self.mxid, item_id=resp.payload.item_id,