feat: add nearby social interactions

This commit is contained in:
ANG-Server
2026-07-21 22:19:41 +08:00
parent 0bab768b14
commit 9dee47492c
43 changed files with 1499 additions and 77 deletions

View File

@@ -979,6 +979,12 @@ func _on_data_received(message: String) -> void:
_handle_chat_error(data)
"chat_render":
_handle_chat_render(data)
"dm_message":
_handle_direct_message(data)
"dm_read":
_emit_event(EventNames.SOCIAL_NOTIFICATION_RECEIVED, {"type": "dm_read", "data": data})
"notification_created", "friendship_changed", "friend_presence_changed":
_emit_event(EventNames.SOCIAL_NOTIFICATION_RECEIVED, {"type": message_type, "data": data})
"friend_list":
_handle_friend_list(data)
"friend_added":
@@ -1301,6 +1307,41 @@ func _handle_chat_render(data: Dictionary) -> void:
"is_private": is_private
})
func _handle_direct_message(data: Dictionary) -> void:
var message_variant: Variant = data.get("message", {})
if not (message_variant is Dictionary):
return
var message: Dictionary = message_variant
var sender_variant: Variant = message.get("sender", {})
var sender: Dictionary = sender_variant if sender_variant is Dictionary else {}
var sender_id := str(message.get("senderId", "")).strip_edges()
var recipient_id := str(message.get("recipientId", "")).strip_edges()
var from_user := str(sender.get("nickname", sender.get("username", "玩家"))).strip_edges()
var is_self := sender_id == _current_user_id()
var payload := {
"from": from_user,
"fromUserId": sender_id,
"txt": str(message.get("content", "")),
"timestamp": message.get("createdAt", Time.get_unix_time_from_system()),
"scope": "private",
"toUserId": recipient_id,
"toUsername": "",
"privateContext": "dm",
"bubble": false,
}
if is_self and _consume_pending_self_message(str(payload.get("txt", "")), "private", recipient_id):
return
_handle_chat_render(payload)
_emit_event(EventNames.SOCIAL_NOTIFICATION_RECEIVED, {"type": "dm_message", "data": data})
func _current_user_id() -> String:
var authManager := get_node_or_null("/root/AuthManager")
if authManager != null and authManager.has_method("get_current_user"):
var user_variant: Variant = authManager.call("get_current_user")
if user_variant is Dictionary:
return str((user_variant as Dictionary).get("id", ""))
return ""
# 解析聊天消息时间戳(兼容 unix 秒 / ISO 8601 字符串)
func _parse_chat_timestamp_to_unix(timestamp_raw: Variant) -> float:
if typeof(timestamp_raw) == TYPE_INT or typeof(timestamp_raw) == TYPE_FLOAT:
@@ -1511,12 +1552,14 @@ func _normalize_friend_requests(requests_variant: Variant) -> Array[Dictionary]:
if not (request_variant is Dictionary):
continue
var request: Dictionary = request_variant
var user_id := str(request.get("userId", request.get("user_id", ""))).strip_edges()
var requester_variant: Variant = request.get("requester", {})
var requester: Dictionary = requester_variant if requester_variant is Dictionary else {}
var user_id := str(request.get("userId", request.get("user_id", requester.get("id", "")))).strip_edges()
if user_id.is_empty():
continue
requests.append({
"user_id": user_id,
"username": str(request.get("username", "玩家")).strip_edges(),
"username": str(request.get("username", requester.get("nickname", requester.get("username", "玩家")))).strip_edges(),
"created_at": str(request.get("createdAt", request.get("created_at", ""))).strip_edges()
})
return requests