Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions gateway/platforms/bluebubbles.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import logging
import os
import re
import time
import uuid
from datetime import datetime
from typing import Any, Dict, List, Optional
Expand Down Expand Up @@ -129,6 +130,8 @@ def __init__(self, config: PlatformConfig):
self._private_api_enabled: Optional[bool] = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reuse gateway.platforms.helpers.MessageDeduplicator rather than adding a second local TTL map. The shared helper already enforces a maximum cache size in addition to TTL pruning.

self._helper_connected: bool = False
self._guid_cache: Dict[str, str] = {}
self._seen_message_guids: Dict[str, float] = {} # guid -> timestamp
self._DEDUP_TTL = 30.0 # seconds

# ------------------------------------------------------------------
# API helpers
Expand Down Expand Up @@ -819,6 +822,22 @@ async def _handle_webhook(self, request):
}:
return web.Response(text="ok")

# Dedup: BB fires multiple webhooks per message (status updates, etc.)
msg_guid = self._value(
record.get("guid"),
record.get("messageGuid"),
record.get("id"),
)
now = time.time()
self._seen_message_guids = {
k: v for k, v in self._seen_message_guids.items()
if now - v < self._DEDUP_TTL
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suppresses every same-GUID event, but the adapter explicitly accepts updated-message events. Use a replay fingerprint that distinguishes exact retries from meaningful same-GUID lifecycle updates such as edits or attachment completion.

if msg_guid and msg_guid in self._seen_message_guids:
return web.Response(text="ok")
if msg_guid:
self._seen_message_guids[msg_guid] = now

text = (
self._value(
record.get("text"), record.get("message"), record.get("body")
Expand Down