Explorar o código

Fix redaction checkpoints. Fixes #25

Also remove unnecessary Exception wrapping
Tulir Asokan %!s(int64=3) %!d(string=hai) anos
pai
achega
2268da7ca6
Modificáronse 2 ficheiros con 18 adicións e 20 borrados
  1. 2 2
      mautrix_instagram/matrix.py
  2. 16 18
      mautrix_instagram/portal.py

+ 2 - 2
mautrix_instagram/matrix.py

@@ -68,9 +68,9 @@ class MatrixHandler(BaseMatrixHandler):
             user.send_remote_checkpoint(
                 MessageSendCheckpointStatus.PERM_FAILURE,
                 event_id,
-                self.mxid,
+                room_id,
                 EventType.ROOM_REDACTION,
-                error=Exception(f"Redaction event {event_id} is in non-portal room {room_id}"),
+                error=Exception("Ignoring redaction event in non-portal room"),
             )
             return
 

+ 16 - 18
mautrix_instagram/portal.py

@@ -134,8 +134,8 @@ class Portal(DBPortal, BasePortal):
             except Exception:
                 self.log.exception("Failed to send delivery receipt for %s", event_id)
 
-    async def _send_bridge_error(self, sender: 'u.User', err: Exception, event_id: EventID,
-                                 event_type: EventType,
+    async def _send_bridge_error(self, sender: 'u.User', err: Union[Exception, str],
+                                 event_id: EventID, event_type: EventType,
                                  message_type: Optional[MessageType] = None,
                                  msg: Optional[str] = None, confirmed: bool = False) -> None:
         sender.send_remote_checkpoint(
@@ -194,7 +194,7 @@ class Portal(DBPortal, BasePortal):
         if not sender.is_connected:
             await self._send_bridge_error(
                 sender,
-                Exception("You're not connected to Instagram"),
+                "You're not connected to Instagram",
                 event_id,
                 EventType.ROOM_MESSAGE,
                 message_type=message.msgtype,
@@ -240,7 +240,7 @@ class Portal(DBPortal, BasePortal):
             else:
                 await self._send_bridge_error(
                     sender,
-                    Exception("Non-image files are currently not supported"),
+                    "Non-image files are currently not supported",
                     event_id,
                     EventType.ROOM_MESSAGE,
                     message_type=message.msgtype,
@@ -256,7 +256,7 @@ class Portal(DBPortal, BasePortal):
             self.log.warning(f"Failed to handle {event_id}: {resp}")
             await self._send_bridge_error(
                 sender,
-                Exception(resp.payload.message),
+                resp.payload.message,
                 event_id,
                 EventType.ROOM_MESSAGE,
                 message_type=message.msgtype,
@@ -324,13 +324,11 @@ class Portal(DBPortal, BasePortal):
 
     async def handle_matrix_redaction(self, sender: 'u.User', event_id: EventID,
                                       redaction_event_id: EventID) -> None:
-        if not self.mxid:
-            return
-        elif not sender.is_connected:
+        if not sender.is_connected:
             await self._send_bridge_error(
                 sender,
-                Exception("You're not connected to Instagram"),
-                event_id,
+                "You're not connected to Instagram",
+                redaction_event_id,
                 EventType.ROOM_REDACTION,
                 confirmed=True,
             )
@@ -347,15 +345,15 @@ class Portal(DBPortal, BasePortal):
                 await self._send_bridge_error(
                     sender,
                     e,
-                    event_id,
+                    redaction_event_id,
                     EventType.ROOM_REDACTION,
                     confirmed=True,
-                    msg=f"Remvoving reaction {reaction.reaction} from {event_id} failed.",
+                    msg=f"Removing reaction {reaction.reaction} from {event_id} failed.",
                 )
             else:
                 sender.send_remote_checkpoint(
                     status=MessageSendCheckpointStatus.SUCCESS,
-                    event_id=event_id,
+                    event_id=redaction_event_id,
                     room_id=self.mxid,
                     event_type=EventType.ROOM_REDACTION,
                 )
@@ -374,15 +372,15 @@ class Portal(DBPortal, BasePortal):
                 await self._send_bridge_error(
                     sender,
                     e,
-                    event_id,
+                    redaction_event_id,
                     EventType.ROOM_REDACTION,
                     confirmed=True,
-                    msg=f"Remvoving message {event_id} failed.",
+                    msg=f"Removing message {event_id} failed.",
                 )
             else:
                 sender.send_remote_checkpoint(
                     status=MessageSendCheckpointStatus.SUCCESS,
-                    event_id=event_id,
+                    event_id=redaction_event_id,
                     room_id=self.mxid,
                     event_type=EventType.ROOM_REDACTION,
                 )
@@ -392,10 +390,10 @@ class Portal(DBPortal, BasePortal):
 
         sender.send_remote_checkpoint(
             MessageSendCheckpointStatus.PERM_FAILURE,
-            event_id,
+            redaction_event_id,
             self.mxid,
             EventType.ROOM_REDACTION,
-            error=Exception(f"No message or reaction found for redaction of {event_id}"),
+            error=Exception("No message or reaction found for redaction"),
         )
 
     async def handle_matrix_typing(self, users: Set[UserID]) -> None: