该提交新增了完整的BlueBubbles渠道插件,支持通过BlueBubbles Server集成iMessage功能,包含以下核心能力: 1. 支持私聊和群聊会话管理,自动区分会话类型 2. 完整的消息收发支持,包括文本、图片、语音、文件、视频消息 3. 支持消息反应、已读回执、消息编辑与撤回 4. 内置去重、防抖处理机制 5. 支持Webhook和WebSocket两种事件接收方式 6. 完善的权限与安全校验机制 7. 历史消息同步与抓包功能 8. TTS语音合成与发送支持 9. 群组管理能力,包括重命名、修改头像、增减成员等
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
import hashlib
|
|
import time
|
|
from collections import OrderedDict
|
|
|
|
|
|
class InboundDedupeStore:
|
|
def __init__(self, max_entries: int = 2048, ttl_seconds: int = 300):
|
|
self._store: OrderedDict[str, float] = OrderedDict()
|
|
self.max_entries = max_entries
|
|
self.ttl_seconds = ttl_seconds
|
|
|
|
@staticmethod
|
|
def _hash(guid: str, account_id: str) -> str:
|
|
return hashlib.sha256(f"{account_id}:{guid}".encode()).hexdigest()
|
|
|
|
def is_duplicate(self, guid: str, account_id: str) -> bool:
|
|
key = self._hash(guid, account_id)
|
|
now = time.time()
|
|
self._evict_expired(now)
|
|
if key in self._store:
|
|
return True
|
|
self._store[key] = now
|
|
while len(self._store) > self.max_entries:
|
|
self._store.popitem(last=False)
|
|
return False
|
|
|
|
def _evict_expired(self, now: float):
|
|
deadline = now - self.ttl_seconds
|
|
while self._store:
|
|
_key, ts = next(iter(self._store.items()))
|
|
if ts < deadline:
|
|
self._store.popitem(last=False)
|
|
else:
|
|
break
|
|
|
|
def clear(self):
|
|
self._store.clear()
|
|
|
|
def __len__(self) -> int:
|
|
return len(self._store)
|