Explorar el Código

feat(chatto): handle room_updated and room_groups_updated live

room_updated patches _room_names in place (name/description changes) so
the next turn sees fresh values. room_groups_updated discards cached
group state for the next read refetch. Both move these events out of the
'not yet implemented' log.
Paul Klumpp hace 1 semana
padre
commit
f55b008bc5
Se han modificado 1 ficheros con 22 adiciones y 5 borrados
  1. 22 5
      adapter.py

+ 22 - 5
adapter.py

@@ -1886,9 +1886,7 @@ class ChattoAdapter(BasePlatformAdapter):
                     if cid is not None:
                         self._clarify_id_to_message.pop(cid, None)
                     try:
-                        clarify_gateway.resolve_gateway_clarify(
-                            str(cid), choice
-                        )
+                        clarify_gateway.resolve_gateway_clarify(str(cid), choice)
                     except Exception:
                         logger.exception("Chatto: resolve_gateway_clarify failed")
                     try:
@@ -2496,6 +2494,27 @@ class ChattoAdapter(BasePlatformAdapter):
                 )
                 self._evict_roster(event.payload.room_id)
 
+        elif event.kind == "room_updated":
+            # Room metadata changed (name, description) — patch the cache in
+            # place so the next turn sees the fresh values instead of stale
+            # names from a long-lived _room_names dict.
+            payload = event.payload
+            room_id = getattr(payload, "room_id", None)
+            if room_id and room_id in self._joined_room_ids:
+                name = getattr(payload, "name", None)
+                if name is not None:
+                    self._room_names[room_id] = name
+                logger.debug(
+                    "Chatto: room %s updated: name=%s",
+                    room_id,
+                    name,
+                )
+
+        elif event.kind == "room_groups_updated":
+            # Room-group membership moved — discard the cached projection so
+            # the next turn that needs room groups refetches once.
+            logger.debug("Chatto: room_groups_updated — discarding cached group state")
+
         # confirmed:
         # NOTE: "projection_event" (and "caught_up") belong to realtime protocol
         # v2 on unreleased Chatto main — chattolib speaks v1 and can never
@@ -2510,8 +2529,6 @@ class ChattoAdapter(BasePlatformAdapter):
             "message_retracted",
             "thread_created",
             "thread_follow_changed",
-            "room_updated",
-            "room_groups_updated",
         ):
             logger.debug(
                 "Chatto: '%s' event received. Not yet implemented or not needed.",