Răsfoiți Sursa

Add timestamps to reaction events from IG during backfill (#45)

* Add timestamps to reaction events from IG during backfill
* Fix backfill reaction timestamps

Co-authored-by: Scott Weber <scott@beeper.com>
Co-authored-by: Tulir Asokan <tulir@maunium.net>
Scott Weber 3 ani în urmă
părinte
comite
afc86a9da5
1 a modificat fișierele cu 7 adăugiri și 3 ștergeri
  1. 7 3
      mautrix_instagram/portal.py

+ 7 - 3
mautrix_instagram/portal.py

@@ -1237,7 +1237,9 @@ class Portal(DBPortal, BasePortal):
                 f"(type {item.item_type} -> fallback error {event_id})"
             )
         if is_backfill and item.reactions:
-            await self._handle_instagram_reactions(msg, item.reactions.emojis)
+            await self._handle_instagram_reactions(
+                msg, item.reactions.emojis, item.timestamp // 1000
+            )
 
     async def handle_instagram_remove(self, item_id: str) -> None:
         message = await DBMessage.get_by_item_id(item_id, self.receiver)
@@ -1252,7 +1254,7 @@ class Portal(DBPortal, BasePortal):
         self.log.debug(f"Redacted {message.mxid} after Instagram unsend")
 
     async def _handle_instagram_reactions(
-        self, message: DBMessage, reactions: list[Reaction]
+        self, message: DBMessage, reactions: list[Reaction], timestamp: int | None = None
     ) -> None:
         old_reactions: dict[int, DBReaction]
         old_reactions = {
@@ -1265,7 +1267,9 @@ class Portal(DBPortal, BasePortal):
                 continue
             puppet = await p.Puppet.get_by_pk(new_reaction.sender_id)
             intent = puppet.intent_for(self)
-            reaction_event_id = await intent.react(self.mxid, message.mxid, new_reaction.emoji)
+            reaction_event_id = await intent.react(
+                self.mxid, message.mxid, new_reaction.emoji, timestamp=timestamp
+            )
             await self._upsert_reaction(
                 old_reaction, intent, reaction_event_id, message, puppet, new_reaction.emoji
             )