Explorar o código

backfill: gate sending dummy, pre-backfill events on msc2716 support

Signed-off-by: Sumner Evans <sumner@beeper.com>
Sumner Evans %!s(int64=2) %!d(string=hai) anos
pai
achega
c16a2124f7
Modificáronse 2 ficheiros con 18 adicións e 4 borrados
  1. 11 3
      mautrix_instagram/portal.py
  2. 7 1
      mautrix_instagram/user.py

+ 11 - 3
mautrix_instagram/portal.py

@@ -1860,7 +1860,11 @@ class Portal(DBPortal, BasePortal):
     async def backfill(self, source: u.User, backfill_request: Backfill) -> None:
         try:
             last_message_ig_timestamp = await self._backfill(source, backfill_request)
-            if last_message_ig_timestamp is not None:
+            if (
+                last_message_ig_timestamp is not None
+                and not self.bridge.homeserver_software.is_hungry
+                and self.config["bridge.backfill.msc2716"]
+            ):
                 await self.send_post_backfill_dummy(last_message_ig_timestamp)
         finally:
             # Always sleep after the backfill request is finished processing, even if it errors.
@@ -2147,8 +2151,10 @@ class Portal(DBPortal, BasePortal):
         if not batch_messages:
             return None
 
-        if not self.bridge.homeserver_software.is_hungry and (
-            forward or self.next_batch_id is None
+        if (
+            not self.bridge.homeserver_software.is_hungry
+            and self.config["bridge.backfill.msc2716"]
+            and (forward or self.next_batch_id is None)
         ):
             self.log.debug("Sending dummy event to avoid forward extremity errors")
             await self.az.intent.send_message_event(
@@ -2269,6 +2275,8 @@ class Portal(DBPortal, BasePortal):
         last_message_ig_timestamp: int,
         base_insertion_event_id: EventID | None = None,
     ):
+        if not self.config["bridge.backfill.msc2716"]:
+            return
         assert self.mxid
 
         if not base_insertion_event_id:

+ 7 - 1
mautrix_instagram/user.py

@@ -299,6 +299,9 @@ class User(DBUser, BaseUser):
             self._thread_sync_task = asyncio.create_task(self.backfill_threads())
 
     async def _handle_backfill_requests_loop(self) -> None:
+        if not self.config["bridge.backfill.enable"] or not self.config["bridge.backfill.msc2716"]:
+            return
+
         while True:
             await self._sync_lock.wait("backfill request")
             req = await Backfill.get_next(self.mxid)
@@ -608,7 +611,10 @@ class User(DBUser, BaseUser):
                 last_message=last_message,
                 mark_read=mark_read,
             )
-            if not self.bridge.homeserver_software.is_hungry:
+            if (
+                not self.bridge.homeserver_software.is_hungry
+                and self.config["bridge.backfill.msc2716"]
+            ):
                 await portal.send_post_backfill_dummy(
                     forward_messages[0].timestamp, base_insertion_event_id=base_insertion_event_id
                 )