fix: Bug 8 — excluded_rooms bei DDP-Subscription berücksichtigen

- _excluded_room_ids Attribut in init
- _sync_room_map_with_membership() lädt excluded_room_ids aus RoomMap
- Beide subscribe-Loops (connect + _reconnect_ddp) filtern excluded_rooms
- Defense in depth: Router-Filter bleibt als 2. Verteidigungslinie

Rainer-Quality-Loop: freigegeben (1 Iteration)
This commit is contained in:
Bernd (Hermes)
2026-07-12 16:55:34 +02:00
parent 7fd7c871ab
commit 1e81c2abc4
+36 -8
View File
@@ -499,6 +499,9 @@ class RocketChatAdapter(BasePlatformAdapter):
# that room (on the assumption that the response IS the button answer).
# No timers, no cleanup — just a simple set.
self._rooms_with_pending_questions: set = set()
# B8: Room IDs excluded from DDP subscription (from room-map.json).
# Populated by _sync_room_map_with_membership() at connect time.
self._excluded_room_ids: set = set()
# Health-check state
self._last_server_activity = 0.0 # ts of last DDP ping/pong or message
self._health_check_timer: Optional[threading.Timer] = None
@@ -624,6 +627,15 @@ class RocketChatAdapter(BasePlatformAdapter):
logger.warning("[rocketchat] M13: Konnte room-map.json nicht laden: %s — GC übersprungen", e)
return
# B8: excluded_room_ids für DDP-Subscription-Filter speichern
self._excluded_room_ids = room_map.excluded_room_ids
if self._excluded_room_ids:
logger.info(
"[rocketchat] B8: %d excluded rooms geladen: %s",
len(self._excluded_room_ids),
", ".join(sorted(self._excluded_room_ids)),
)
map_room_ids = set(room_map.rooms.keys())
logger.info(
"[rocketchat] M13: room-map.json enthält %d Räume",
@@ -806,11 +818,19 @@ class RocketChatAdapter(BasePlatformAdapter):
# ── Ende M13 ───────────────────────────────────────────────────
for room in self._rooms:
sub_id = self.ddp.subscribe_room(room["id"])
rid = room["id"]
# B8: excluded_rooms nicht subscriben
if rid in self._excluded_room_ids:
logger.info(
"[rocketchat] Room '%s' (%s) excluded — not subscribing",
room["name"], rid,
)
continue
sub_id = self.ddp.subscribe_room(rid)
if sub_id:
self._subscribed_rooms.add(room["id"])
self._room_info[room["id"]] = {"name": room["name"], "type": room["type"]}
logger.info("[rocketchat] Subscribed to %s (%s)", room["name"], room["id"])
self._subscribed_rooms.add(rid)
self._room_info[rid] = {"name": room["name"], "type": room["type"]}
logger.info("[rocketchat] Subscribed to %s (%s)", room["name"], rid)
logger.info("[rocketchat] Total subscribed rooms: %d", len(self._subscribed_rooms))
# Build user→rooms map for virtual chat_id translation.
# Each Rocket.Chat user gets a synthetic "user:<username>" chat_id that
@@ -943,14 +963,22 @@ class RocketChatAdapter(BasePlatformAdapter):
# 4. M13 GC
self._sync_room_map_with_membership()
# 5. Nur aktuelle Mitglieder-Räume subscriben
# 5. Nur aktuelle Mitglieder-Räume subscriben (excluded_rooms ausgenommen)
self._subscribed_rooms.clear()
self._room_info.clear()
for room in self._rooms:
sub_id = self.ddp.subscribe_room(room["id"])
rid = room["id"]
# B8: excluded_rooms nicht subscriben
if rid in self._excluded_room_ids:
logger.info(
"[rocketchat] _reconnect_ddp: Room '%s' (%s) excluded — not subscribing",
room["name"], rid,
)
continue
sub_id = self.ddp.subscribe_room(rid)
if sub_id:
self._subscribed_rooms.add(room["id"])
self._room_info[room["id"]] = {"name": room["name"], "type": room["type"]}
self._subscribed_rooms.add(rid)
self._room_info[rid] = {"name": room["name"], "type": room["type"]}
logger.info("[rocketchat] _reconnect_ddp: %d rooms subscribed", len(self._subscribed_rooms))
# 6. Archivar subscribed_room_ids aktualisieren