feat(节点跟踪): 改进用户跟踪功能并添加新用户通知

当新用户首次发送消息时,返回布尔值并通知可用节点。在handler.py中添加对新用户的处理逻辑,当检测到新用户时,向其发送当前在线的节点列表。这有助于新用户更快了解可用资源。
This commit is contained in:
Yuyao Huang (Sam)
2026-03-29 18:14:46 +08:00
parent 2a8f745b3d
commit 88b7eabe14
2 changed files with 13 additions and 3 deletions
+5 -2
View File
@@ -69,9 +69,12 @@ class NodeRegistry:
return True
return secret == self._secret
def track_user(self, user_id: str) -> None:
"""Record a user as known (has sent at least one message)."""
def track_user(self, user_id: str) -> bool:
"""Record a user as known. Returns True if this is their first message."""
if user_id in self._known_users:
return False
self._known_users.add(user_id)
return True
def _get_notifiable_users(self, node: NodeConnection) -> Set[str]:
"""Get users to notify about a node event.