Add friends, DMs, presence, block, and party chat
- Fix social response key mismatch (incomingRequests, blocked) - Fix DmOpenResponse to return full ChatChannelDto so client can add the channel without a separate fetch - Add Party channel type to ChatChannelType enum - Add PartyInviteHandler, PartyInviteRespondHandler, PartyLeaveHandler with IClientPush invite notification to the invitee - Add party tab to chat overlay (action bar, messages, Leave button) - Wire Invite to Party in both player and friend context menus - Show accept/decline popup dialog on incoming party invite push Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -30,6 +30,13 @@ signal presence_updated
|
||||
## Emitted after notifications array changes.
|
||||
signal notifications_updated
|
||||
|
||||
## Emitted when the party channel is joined, left, or updated.
|
||||
signal party_updated
|
||||
|
||||
## Emitted when a remote player invites the local player to their party.
|
||||
## channel_id: the Party channel to accept into; inviter_name: display name of sender.
|
||||
signal party_invite_received(channel_id: String, inviter_name: String)
|
||||
|
||||
# ── State ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
## Array[Dictionary] — ChatChannelDto {id, name, channelType, createdAt}
|
||||
@@ -108,6 +115,7 @@ func _clear_state() -> void:
|
||||
_message_poll_in_flight.clear()
|
||||
channels_updated.emit()
|
||||
social_updated.emit()
|
||||
party_updated.emit()
|
||||
|
||||
# ── Public API ────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -189,6 +197,36 @@ func fetch_presence(account_ids: Array) -> void:
|
||||
)
|
||||
|
||||
|
||||
## Invite a player to the caller's party (creates the party channel if needed).
|
||||
func invite_to_party(account_id: String) -> void:
|
||||
Network.request(
|
||||
"chat.party.invite",
|
||||
{ "inviteeAccountId": account_id },
|
||||
_on_party_invite_sent_success,
|
||||
_noop_error
|
||||
)
|
||||
|
||||
|
||||
## Accept or decline an incoming party invite.
|
||||
func respond_party_invite(channel_id: String, accept: bool) -> void:
|
||||
Network.request(
|
||||
"chat.party.invite_respond",
|
||||
{ "channelId": channel_id, "accept": accept },
|
||||
_on_party_invite_respond_success,
|
||||
_noop_error
|
||||
)
|
||||
|
||||
|
||||
## Leave the current party channel.
|
||||
func leave_party() -> void:
|
||||
Network.request(
|
||||
"chat.party.leave",
|
||||
{},
|
||||
_on_party_leave_success,
|
||||
_noop_error
|
||||
)
|
||||
|
||||
|
||||
func mark_notifications_read(ids: Array) -> void:
|
||||
if ids.is_empty():
|
||||
return
|
||||
@@ -219,6 +257,14 @@ func get_dm_channels() -> Array:
|
||||
func(c: Dictionary) -> bool: return c.get("channelType", "") == "Direct"
|
||||
)
|
||||
|
||||
|
||||
## Returns the caller's current Party channel, or {} if not in one.
|
||||
func get_party_channel() -> Dictionary:
|
||||
for c: Dictionary in channels:
|
||||
if c.get("channelType", "") == "Party":
|
||||
return c
|
||||
return {}
|
||||
|
||||
# ── Private helpers ───────────────────────────────────────────────────────────
|
||||
|
||||
func _set_own_presence(status: String) -> void:
|
||||
@@ -351,8 +397,8 @@ func _on_fetch_presence_success(_t: String, p: Variant) -> void:
|
||||
func _on_fetch_social_success(_t: String, p: Variant) -> void:
|
||||
var d := p as Dictionary
|
||||
friends = d.get("friends", [])
|
||||
pending_requests = d.get("pendingRequests", [])
|
||||
blocked_users = d.get("blockedUsers", [])
|
||||
pending_requests = d.get("incomingRequests", [])
|
||||
blocked_users = d.get("blocked", [])
|
||||
social_updated.emit()
|
||||
var ids: Array = friends.map(func(f: Dictionary) -> String:
|
||||
return f.get("accountId", ""))
|
||||
@@ -369,6 +415,49 @@ func _on_fetch_notifications_success(_t: String, p: Variant) -> void:
|
||||
notifications_updated.emit()
|
||||
|
||||
|
||||
func _on_party_invite_sent_success(_t: String, p: Variant) -> void:
|
||||
var chan: Dictionary = (p as Dictionary).get("channel", {})
|
||||
if not chan.is_empty():
|
||||
_upsert_channel(chan)
|
||||
party_updated.emit()
|
||||
channels_updated.emit()
|
||||
|
||||
|
||||
func _on_party_invite_respond_success(_t: String, p: Variant) -> void:
|
||||
var d := p as Dictionary
|
||||
if not d.get("accepted", false):
|
||||
return
|
||||
var chan: Dictionary = d.get("channel", {})
|
||||
if not chan.is_empty():
|
||||
_upsert_channel(chan)
|
||||
party_updated.emit()
|
||||
channels_updated.emit()
|
||||
|
||||
|
||||
func _on_party_leave_success(_t: String, _p: Variant) -> void:
|
||||
channels = channels.filter(func(c: Dictionary) -> bool:
|
||||
return c.get("channelType", "") != "Party")
|
||||
messages.erase(_get_party_channel_id())
|
||||
party_updated.emit()
|
||||
channels_updated.emit()
|
||||
|
||||
|
||||
func _get_party_channel_id() -> String:
|
||||
for c: Dictionary in channels:
|
||||
if c.get("channelType", "") == "Party":
|
||||
return c.get("id", "")
|
||||
return ""
|
||||
|
||||
|
||||
func _upsert_channel(chan: Dictionary) -> void:
|
||||
var cid: String = chan.get("id", "")
|
||||
for i in channels.size():
|
||||
if (channels[i] as Dictionary).get("id", "") == cid:
|
||||
channels[i] = chan
|
||||
return
|
||||
channels.push_front(chan)
|
||||
|
||||
|
||||
func _noop_error(_c: String, _m: String) -> void:
|
||||
pass
|
||||
|
||||
@@ -391,3 +480,10 @@ func _on_server_push(type: String, payload: Variant) -> void:
|
||||
if not notif.is_empty():
|
||||
notifications.push_front(notif)
|
||||
notifications_updated.emit()
|
||||
|
||||
"chat.party_invite.push":
|
||||
var d := payload as Dictionary
|
||||
var cid : String = d.get("channelId", "")
|
||||
var inviter : String = d.get("inviterName", "Someone")
|
||||
if not cid.is_empty():
|
||||
party_invite_received.emit(cid, inviter)
|
||||
|
||||
@@ -16,9 +16,9 @@ extends CanvasLayer
|
||||
|
||||
# ── Tab enum ──────────────────────────────────────────────────────────────────
|
||||
|
||||
enum Tab { FRIENDS, PRESENCE, GLOBAL, LOBBY, GAME, DMS }
|
||||
enum Tab { FRIENDS, PRESENCE, GLOBAL, LOBBY, GAME, PARTY, DMS }
|
||||
|
||||
const TAB_LABELS := ["Friends", "Presence", "Global", "Lobby", "Game", "DMs"]
|
||||
const TAB_LABELS := ["Friends", "Presence", "Global", "Lobby", "Game", "Party", "DMs"]
|
||||
|
||||
# ── Colors ────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -65,6 +65,8 @@ var _lobby_list : VBoxContainer = null
|
||||
var _game_list : VBoxContainer = null
|
||||
var _dm_conv_list : VBoxContainer = null
|
||||
var _dm_msg_list : VBoxContainer = null
|
||||
var _party_msg_list : VBoxContainer = null
|
||||
var _party_action_bar : HBoxContainer = null
|
||||
|
||||
# ── State ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -90,6 +92,8 @@ func _connect_chat_signals() -> void:
|
||||
Chat.social_updated.connect(_on_social_updated)
|
||||
Chat.presence_updated.connect(_on_presence_updated)
|
||||
Chat.notifications_updated.connect(_refresh_badge)
|
||||
Chat.party_updated.connect(_on_party_updated)
|
||||
Chat.party_invite_received.connect(_on_party_invite_received)
|
||||
|
||||
|
||||
func _style_bubble() -> void:
|
||||
@@ -253,6 +257,7 @@ func _build_tab_content(tab: Tab) -> Control:
|
||||
Tab.GLOBAL: return _build_channel_tab(Tab.GLOBAL)
|
||||
Tab.LOBBY: return _build_channel_tab(Tab.LOBBY)
|
||||
Tab.GAME: return _build_channel_tab(Tab.GAME)
|
||||
Tab.PARTY: return _build_party_tab()
|
||||
Tab.DMS: return _build_dms_tab()
|
||||
return Control.new()
|
||||
|
||||
@@ -437,6 +442,67 @@ func _build_dms_tab() -> Control:
|
||||
|
||||
return hbox
|
||||
|
||||
func _build_party_tab() -> Control:
|
||||
var vbox := VBoxContainer.new()
|
||||
vbox.add_theme_constant_override("separation", 0)
|
||||
|
||||
# ── Action bar (Leave / Invite) ───────────────────────────────────────────
|
||||
_party_action_bar = HBoxContainer.new()
|
||||
_party_action_bar.add_theme_constant_override("separation", 4)
|
||||
_party_action_bar.visible = false
|
||||
|
||||
var abm := MarginContainer.new()
|
||||
abm.add_theme_constant_override("margin_left", 8)
|
||||
abm.add_theme_constant_override("margin_right", 8)
|
||||
abm.add_theme_constant_override("margin_top", 4)
|
||||
abm.add_theme_constant_override("margin_bottom", 4)
|
||||
abm.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
_party_action_bar.add_child(abm)
|
||||
|
||||
var ab_inner := HBoxContainer.new()
|
||||
ab_inner.add_theme_constant_override("separation", 6)
|
||||
abm.add_child(ab_inner)
|
||||
|
||||
var party_name_lbl := Label.new()
|
||||
party_name_lbl.name = "PartyNameLabel"
|
||||
party_name_lbl.text = "Party"
|
||||
party_name_lbl.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
party_name_lbl.add_theme_font_size_override("font_size", 12)
|
||||
party_name_lbl.add_theme_color_override("font_color", SOURCE_COLORS["party"])
|
||||
ab_inner.add_child(party_name_lbl)
|
||||
|
||||
var leave_btn := Button.new()
|
||||
leave_btn.text = "Leave"
|
||||
leave_btn.add_theme_color_override("font_color", DANGER_COLOR)
|
||||
leave_btn.add_theme_font_size_override("font_size", 11)
|
||||
leave_btn.flat = true
|
||||
leave_btn.pressed.connect(_on_party_leave_pressed)
|
||||
ab_inner.add_child(leave_btn)
|
||||
|
||||
vbox.add_child(_party_action_bar)
|
||||
vbox.add_child(_make_separator())
|
||||
|
||||
# ── Message area ──────────────────────────────────────────────────────────
|
||||
var scroll := ScrollContainer.new()
|
||||
scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||||
vbox.add_child(scroll)
|
||||
|
||||
var outer_margin := MarginContainer.new()
|
||||
outer_margin.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
outer_margin.add_theme_constant_override("margin_left", 8)
|
||||
outer_margin.add_theme_constant_override("margin_right", 8)
|
||||
outer_margin.add_theme_constant_override("margin_top", 4)
|
||||
outer_margin.add_theme_constant_override("margin_bottom", 4)
|
||||
scroll.add_child(outer_margin)
|
||||
|
||||
_party_msg_list = VBoxContainer.new()
|
||||
_party_msg_list.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
_party_msg_list.add_theme_constant_override("separation", 2)
|
||||
outer_margin.add_child(_party_msg_list)
|
||||
|
||||
return vbox
|
||||
|
||||
# ── Tab switching ─────────────────────────────────────────────────────────────
|
||||
|
||||
func _show_tab(tab: Tab) -> void:
|
||||
@@ -454,6 +520,8 @@ func _show_tab(tab: Tab) -> void:
|
||||
_input_bar.visible = false
|
||||
Tab.GLOBAL, Tab.LOBBY, Tab.GAME:
|
||||
_input_bar.visible = true
|
||||
Tab.PARTY:
|
||||
_input_bar.visible = not Chat.get_party_channel().is_empty()
|
||||
Tab.DMS:
|
||||
_input_bar.visible = not _active_dm.is_empty()
|
||||
|
||||
@@ -469,6 +537,8 @@ func _show_tab(tab: Tab) -> void:
|
||||
_activate_channel_tab("Guild", Tab.LOBBY)
|
||||
Tab.GAME:
|
||||
_activate_channel_tab("Match", Tab.GAME)
|
||||
Tab.PARTY:
|
||||
_refresh_party_tab()
|
||||
Tab.DMS:
|
||||
_refresh_dm_list()
|
||||
if not _active_dm.is_empty():
|
||||
@@ -769,6 +839,48 @@ func _refresh_dm_messages() -> void:
|
||||
if row != null:
|
||||
_dm_msg_list.add_child(row)
|
||||
|
||||
# ── Refresh: Party ────────────────────────────────────────────────────────────
|
||||
|
||||
func _refresh_party_tab() -> void:
|
||||
var party_chan := Chat.get_party_channel()
|
||||
var in_party := not party_chan.is_empty()
|
||||
|
||||
if is_instance_valid(_party_action_bar):
|
||||
_party_action_bar.visible = in_party
|
||||
if in_party:
|
||||
var name_lbl := _party_action_bar.find_child("PartyNameLabel", true, false) as Label
|
||||
if is_instance_valid(name_lbl):
|
||||
name_lbl.text = party_chan.get("name", "Party")
|
||||
|
||||
_input_bar.visible = in_party
|
||||
if in_party:
|
||||
var cid: String = party_chan.get("id", "")
|
||||
_active_channel = cid
|
||||
if cid not in Chat.messages:
|
||||
Chat.fetch_messages(cid)
|
||||
|
||||
_refresh_party_messages()
|
||||
|
||||
|
||||
func _refresh_party_messages() -> void:
|
||||
if not is_instance_valid(_party_msg_list):
|
||||
return
|
||||
|
||||
for c in _party_msg_list.get_children():
|
||||
c.queue_free()
|
||||
|
||||
var party_chan := Chat.get_party_channel()
|
||||
if party_chan.is_empty():
|
||||
_party_msg_list.add_child(_make_placeholder("You are not in a party.\nAccept an invite from a friend to join one."))
|
||||
return
|
||||
|
||||
var cid : String = party_chan.get("id", "")
|
||||
var msgs : Array = Chat.messages.get(cid, [])
|
||||
for i in range(msgs.size() - 1, -1, -1):
|
||||
var row := _make_message_row(msgs[i] as Dictionary, "party")
|
||||
if row != null:
|
||||
_party_msg_list.add_child(row)
|
||||
|
||||
# ── Badge ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
func _refresh_badge() -> void:
|
||||
@@ -852,6 +964,7 @@ func _show_friend_context_menu(friend: Dictionary) -> void:
|
||||
var menu := PopupMenu.new()
|
||||
add_child(menu)
|
||||
menu.add_item("Private Message", 0)
|
||||
menu.add_item("Invite to Party", 4)
|
||||
menu.add_item("Set Nickname", 1)
|
||||
menu.add_separator()
|
||||
menu.add_item("Block", 2)
|
||||
@@ -878,6 +991,8 @@ func _on_friend_menu_action(id: int, account_id: String, dn: String) -> void:
|
||||
Chat.block_user(account_id)
|
||||
3: # Remove Friend
|
||||
Chat.remove_friend(account_id)
|
||||
4: # Invite to Party
|
||||
Chat.invite_to_party(account_id)
|
||||
|
||||
|
||||
func _show_player_menu(account_id: String, display_name: String) -> void:
|
||||
@@ -916,8 +1031,8 @@ func _on_player_menu_action(id: int, account_id: String, _dn: String) -> void:
|
||||
match id:
|
||||
0: # Add Friend
|
||||
Chat.send_friend_request(account_id)
|
||||
1: # Invite to Party (stub — party system not yet implemented)
|
||||
pass
|
||||
1: # Invite to Party
|
||||
Chat.invite_to_party(account_id)
|
||||
2: # Private Message
|
||||
Chat.open_dm(account_id)
|
||||
_show_tab(Tab.DMS)
|
||||
@@ -979,6 +1094,7 @@ func _on_channels_updated() -> void:
|
||||
Tab.GLOBAL: _activate_channel_tab("Global", Tab.GLOBAL)
|
||||
Tab.LOBBY: _activate_channel_tab("Guild", Tab.LOBBY)
|
||||
Tab.GAME: _activate_channel_tab("Match", Tab.GAME)
|
||||
Tab.PARTY: _refresh_party_tab()
|
||||
Tab.DMS: _refresh_dm_list()
|
||||
|
||||
|
||||
@@ -997,6 +1113,9 @@ func _on_message_received(channel_id: String, _msg: Dictionary) -> void:
|
||||
Tab.GAME:
|
||||
if Chat.get_channel_by_type("Match").get("id", "") == channel_id:
|
||||
_refresh_channel_messages(Tab.GAME)
|
||||
Tab.PARTY:
|
||||
if Chat.get_party_channel().get("id", "") == channel_id:
|
||||
_refresh_party_messages()
|
||||
Tab.DMS:
|
||||
if channel_id == _active_dm:
|
||||
_refresh_dm_messages()
|
||||
@@ -1022,6 +1141,43 @@ func _on_own_presence_changed(index: int) -> void:
|
||||
const STATUS_MAP := ["Online", "Away", "Offline"]
|
||||
Chat.set_presence(STATUS_MAP[index])
|
||||
|
||||
|
||||
func _on_party_updated() -> void:
|
||||
if not _panel.visible:
|
||||
return
|
||||
if _current_tab == Tab.PARTY:
|
||||
_refresh_party_tab()
|
||||
# Keep the tab button highlighted if a party exists.
|
||||
_apply_tab_btn_style(
|
||||
_tab_buttons[Tab.PARTY],
|
||||
_current_tab == Tab.PARTY)
|
||||
|
||||
|
||||
func _on_party_invite_received(channel_id: String, inviter_name: String) -> void:
|
||||
var dialog := ConfirmationDialog.new()
|
||||
dialog.title = "Party Invite"
|
||||
dialog.dialog_text = "%s invited you to their party!" % inviter_name
|
||||
dialog.ok_button_text = "Accept"
|
||||
dialog.cancel_button_text = "Decline"
|
||||
dialog.min_size = Vector2(280, 100)
|
||||
add_child(dialog)
|
||||
dialog.popup_centered()
|
||||
|
||||
dialog.confirmed.connect(func() -> void:
|
||||
Chat.respond_party_invite(channel_id, true)
|
||||
dialog.queue_free()
|
||||
_show_tab(Tab.PARTY))
|
||||
|
||||
dialog.canceled.connect(func() -> void:
|
||||
Chat.respond_party_invite(channel_id, false)
|
||||
dialog.queue_free())
|
||||
|
||||
|
||||
func _on_party_leave_pressed() -> void:
|
||||
Chat.leave_party()
|
||||
if _current_tab == Tab.PARTY:
|
||||
_refresh_party_tab()
|
||||
|
||||
# ── Helpers ───────────────────────────────────────────────────────────────────
|
||||
|
||||
func _presence_dot(status: String) -> String:
|
||||
|
||||
Reference in New Issue
Block a user