DM shows player name; add party rename
- ChatGetChannelsHandler: for Direct channels, look up the other member's display name from identity DB and return it as the channel name (per-caller, no DB schema change) - ChatDmOpenHandler: same — returns recipient display name in the DTO for both new and existing DM channels - New ChatPartyRenameHandler (chat.party.rename): updates the party channel name, returns updated DTO - Chat.gd: rename_party() calls the new handler and upserts locally - chat_overlay.gd: "Rename" button in party action bar opens a dialog to set a new party name 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:
@@ -227,6 +227,21 @@ func respond_party_invite(channel_id: String, accept: bool) -> void:
|
||||
)
|
||||
|
||||
|
||||
## Rename the caller's current party channel.
|
||||
func rename_party(name: String) -> void:
|
||||
Network.request(
|
||||
"chat.party.rename",
|
||||
{ "name": name },
|
||||
func(_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(_c: String, _m: String) -> void: pass
|
||||
)
|
||||
|
||||
|
||||
## Leave the current party channel.
|
||||
func leave_party() -> void:
|
||||
Network.request(
|
||||
|
||||
@@ -471,6 +471,13 @@ func _build_party_tab() -> Control:
|
||||
party_name_lbl.add_theme_color_override("font_color", SOURCE_COLORS["party"])
|
||||
ab_inner.add_child(party_name_lbl)
|
||||
|
||||
var rename_btn := Button.new()
|
||||
rename_btn.text = "Rename"
|
||||
rename_btn.add_theme_font_size_override("font_size", 11)
|
||||
rename_btn.flat = true
|
||||
rename_btn.pressed.connect(_on_party_rename_pressed)
|
||||
ab_inner.add_child(rename_btn)
|
||||
|
||||
var leave_btn := Button.new()
|
||||
leave_btn.text = "Leave"
|
||||
leave_btn.add_theme_color_override("font_color", DANGER_COLOR)
|
||||
@@ -1199,6 +1206,35 @@ func _on_party_invite_received(channel_id: String, inviter_name: String) -> void
|
||||
dialog.queue_free())
|
||||
|
||||
|
||||
func _on_party_rename_pressed() -> void:
|
||||
var party_chan := Chat.get_party_channel()
|
||||
if party_chan.is_empty():
|
||||
return
|
||||
|
||||
var dialog := AcceptDialog.new()
|
||||
dialog.title = "Rename Party"
|
||||
dialog.min_size = Vector2(280, 100)
|
||||
|
||||
var vbox := VBoxContainer.new()
|
||||
vbox.add_theme_constant_override("separation", 8)
|
||||
var input := LineEdit.new()
|
||||
input.placeholder_text = "Party name"
|
||||
input.text = party_chan.get("name", "")
|
||||
input.max_length = 64
|
||||
vbox.add_child(input)
|
||||
dialog.add_child(vbox)
|
||||
|
||||
add_child(dialog)
|
||||
dialog.popup_centered()
|
||||
|
||||
dialog.confirmed.connect(func() -> void:
|
||||
var n := input.text.strip_edges()
|
||||
if not n.is_empty():
|
||||
Chat.rename_party(n)
|
||||
dialog.queue_free())
|
||||
dialog.canceled.connect(func() -> void: dialog.queue_free())
|
||||
|
||||
|
||||
func _on_party_leave_pressed() -> void:
|
||||
Chat.leave_party()
|
||||
if _current_tab == Tab.PARTY:
|
||||
|
||||
@@ -76,6 +76,9 @@ public sealed record PartyInviteRespondRequest(Guid ChannelId, bool Accept);
|
||||
/// <summary>Leave the caller's current party channel.</summary>
|
||||
public sealed record PartyLeaveRequest; // identity from connection
|
||||
|
||||
/// <summary>Rename the caller's current party channel.</summary>
|
||||
public sealed record PartyRenameRequest(string Name);
|
||||
|
||||
// ── Response / DTO types (server → client) ────────────────────────────────────
|
||||
|
||||
public sealed record SendMessageResponse(ChatMessageDto Message);
|
||||
@@ -112,6 +115,8 @@ public sealed record PartyInviteRespondResponse(bool Accepted, ChatChannelDto? C
|
||||
|
||||
public sealed record PartyLeaveResponse;
|
||||
|
||||
public sealed record PartyRenameResponse(ChatChannelDto Channel);
|
||||
|
||||
// ── DTOs ────────────────────────────────────────────────────────────────────
|
||||
|
||||
public sealed record ChatChannelDto(
|
||||
|
||||
@@ -16,21 +16,24 @@ using SOR.Shared.Networking;
|
||||
/// </summary>
|
||||
internal sealed class ChatDmOpenHandler : ChatHandlerBase, IMessageHandler
|
||||
{
|
||||
private readonly IMessageSerializer _serializer;
|
||||
private readonly ChatDbContext _chatDb;
|
||||
private readonly IMessageSerializer _serializer;
|
||||
private readonly ChatDbContext _chatDb;
|
||||
private readonly SorIdentityDbContext _identityDb;
|
||||
|
||||
public ChatDmOpenHandler(
|
||||
IMessageSerializer serializer,
|
||||
ChatDbContext chatDb)
|
||||
IMessageSerializer serializer,
|
||||
ChatDbContext chatDb,
|
||||
SorIdentityDbContext identityDb)
|
||||
{
|
||||
_serializer = serializer;
|
||||
_chatDb = chatDb;
|
||||
_identityDb = identityDb;
|
||||
}
|
||||
|
||||
public string MessageType => "chat.dm_open";
|
||||
|
||||
private static ChatChannelDto ToDto(ChatChannel c) =>
|
||||
new(c.Id, c.Name, c.ChannelType.ToString(), c.CreatedAt);
|
||||
private static ChatChannelDto ToDto(ChatChannel c, string? nameOverride = null) =>
|
||||
new(c.Id, nameOverride ?? c.Name, c.ChannelType.ToString(), c.CreatedAt);
|
||||
|
||||
public async Task<IServerMessage?> HandleAsync(
|
||||
IClientMessage message,
|
||||
@@ -48,6 +51,11 @@ internal sealed class ChatDmOpenHandler : ChatHandlerBase, IMessageHandler
|
||||
if (blocked)
|
||||
return ServerMessage.Error(message.Seq, "BLOCKED", "Cannot open a DM with this user.");
|
||||
|
||||
// ── Resolve recipient display name (used as channel name) ─────────────
|
||||
var recipientUser = await _identityDb.Users.FindAsync(
|
||||
new object[] { req.RecipientAccountId }, cancellationToken);
|
||||
var recipientName = recipientUser?.DisplayName ?? req.RecipientAccountId.ToString();
|
||||
|
||||
// ── Find existing DM channel ──────────────────────────────────────────
|
||||
// A DM channel exists if both accounts are active members of the same Direct channel.
|
||||
var existingChannelId = await _chatDb.Members
|
||||
@@ -69,14 +77,14 @@ internal sealed class ChatDmOpenHandler : ChatHandlerBase, IMessageHandler
|
||||
var existing = await _chatDb.Channels.FindAsync(
|
||||
new object[] { existingChannelId }, cancellationToken);
|
||||
return ServerMessage.Reply("chat.dm_open.ack", message.Seq,
|
||||
new DmOpenResponse(ToDto(existing!)));
|
||||
new DmOpenResponse(ToDto(existing!, recipientName)));
|
||||
}
|
||||
|
||||
// ── Create new DM channel ─────────────────────────────────────────────
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
var channel = new ChatChannel
|
||||
{
|
||||
Name = "dm",
|
||||
Name = "dm", // internal; name is resolved dynamically per caller
|
||||
ChannelType = ChatChannelType.Direct,
|
||||
CreatedAt = now,
|
||||
};
|
||||
@@ -88,6 +96,6 @@ internal sealed class ChatDmOpenHandler : ChatHandlerBase, IMessageHandler
|
||||
await _chatDb.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return ServerMessage.Reply("chat.dm_open.ack", message.Seq,
|
||||
new DmOpenResponse(ToDto(channel)));
|
||||
new DmOpenResponse(ToDto(channel, recipientName)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,19 +2,25 @@ namespace SOR.Chat.Handlers;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Database.Enums;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
using SOR.Networking.Abstractions.Transport;
|
||||
using SOR.Shared.Networking;
|
||||
|
||||
/// <summary>
|
||||
/// chat.get_channels — returns all channels the caller is currently a member of.
|
||||
/// For Direct channels, the channel name is replaced with the other member's display name.
|
||||
/// </summary>
|
||||
internal sealed class ChatGetChannelsHandler : ChatHandlerBase, IMessageHandler
|
||||
{
|
||||
private readonly ChatDbContext _chatDb;
|
||||
private readonly ChatDbContext _chatDb;
|
||||
private readonly SorIdentityDbContext _identityDb;
|
||||
|
||||
public ChatGetChannelsHandler(ChatDbContext chatDb)
|
||||
=> _chatDb = chatDb;
|
||||
public ChatGetChannelsHandler(ChatDbContext chatDb, SorIdentityDbContext identityDb)
|
||||
{
|
||||
_chatDb = chatDb;
|
||||
_identityDb = identityDb;
|
||||
}
|
||||
|
||||
public string MessageType => "chat.get_channels";
|
||||
|
||||
@@ -30,14 +36,48 @@ internal sealed class ChatGetChannelsHandler : ChatHandlerBase, IMessageHandler
|
||||
.Where(m => m.AccountId == accountId && m.LeftAt == null)
|
||||
.Select(m => m.Channel)
|
||||
.OrderBy(c => c.CreatedAt)
|
||||
.Select(c => new ChatChannelDto(
|
||||
c.Id,
|
||||
c.Name,
|
||||
c.ChannelType.ToString(),
|
||||
c.CreatedAt))
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
// For Direct channels, resolve the other member's display name.
|
||||
var directIds = channels
|
||||
.Where(c => c.ChannelType == ChatChannelType.Direct)
|
||||
.Select(c => c.Id)
|
||||
.ToList();
|
||||
|
||||
Dictionary<Guid, Guid> channelToOther = [];
|
||||
Dictionary<Guid, string> otherNames = [];
|
||||
|
||||
if (directIds.Count > 0)
|
||||
{
|
||||
var otherMembers = await _chatDb.Members
|
||||
.Where(m => directIds.Contains(m.ChannelId)
|
||||
&& m.AccountId != accountId
|
||||
&& m.LeftAt == null)
|
||||
.Select(m => new { m.ChannelId, m.AccountId })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
channelToOther = otherMembers.ToDictionary(x => x.ChannelId, x => x.AccountId);
|
||||
|
||||
var otherIds = otherMembers.Select(x => x.AccountId).ToList();
|
||||
otherNames = await _identityDb.Users
|
||||
.Where(u => otherIds.Contains(u.Id))
|
||||
.Select(u => new { u.Id, u.DisplayName })
|
||||
.ToDictionaryAsync(
|
||||
u => u.Id,
|
||||
u => u.DisplayName ?? u.Id.ToString(),
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
var dtos = channels.Select(c =>
|
||||
{
|
||||
var name = c.Name;
|
||||
if (c.ChannelType == ChatChannelType.Direct
|
||||
&& channelToOther.TryGetValue(c.Id, out var otherId))
|
||||
name = otherNames.GetValueOrDefault(otherId, name);
|
||||
return new ChatChannelDto(c.Id, name, c.ChannelType.ToString(), c.CreatedAt);
|
||||
}).ToList();
|
||||
|
||||
return ServerMessage.Reply("chat.get_channels.ack", message.Seq,
|
||||
new GetChannelsResponse(channels));
|
||||
new GetChannelsResponse(dtos));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
namespace SOR.Chat.Handlers;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Database.Enums;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
using SOR.Networking.Abstractions.Transport;
|
||||
using SOR.Shared.Networking;
|
||||
|
||||
/// <summary>
|
||||
/// chat.party.rename — renames the caller's current party channel.
|
||||
/// Fails if the caller is not in a party.
|
||||
/// </summary>
|
||||
internal sealed class ChatPartyRenameHandler : IMessageHandler
|
||||
{
|
||||
private readonly IMessageSerializer _serializer;
|
||||
private readonly ChatDbContext _chatDb;
|
||||
|
||||
public ChatPartyRenameHandler(IMessageSerializer serializer, ChatDbContext chatDb)
|
||||
{
|
||||
_serializer = serializer;
|
||||
_chatDb = chatDb;
|
||||
}
|
||||
|
||||
public string MessageType => "chat.party.rename";
|
||||
|
||||
public async Task<IServerMessage?> HandleAsync(
|
||||
IClientMessage message,
|
||||
AuthenticatedConnection connection,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var req = _serializer.DeserializePayload<PartyRenameRequest>(message.Payload);
|
||||
var accountId = Guid.Parse(connection.UserId);
|
||||
|
||||
var name = req.Name.Trim();
|
||||
if (name.Length == 0 || name.Length > 64)
|
||||
return ServerMessage.Error(message.Seq, "INVALID_NAME", "Party name must be 1–64 characters.");
|
||||
|
||||
var partyChannel = await _chatDb.Members
|
||||
.Where(m => m.AccountId == accountId && m.LeftAt == null)
|
||||
.Join(_chatDb.Channels.Where(c => c.ChannelType == ChatChannelType.Party),
|
||||
m => m.ChannelId, c => c.Id, (_, c) => c)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
if (partyChannel is null)
|
||||
return ServerMessage.Error(message.Seq, "NOT_IN_PARTY", "You are not in a party.");
|
||||
|
||||
partyChannel.Name = name;
|
||||
await _chatDb.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return ServerMessage.Reply("chat.party.rename.ack", message.Seq,
|
||||
new PartyRenameResponse(new ChatChannelDto(
|
||||
partyChannel.Id,
|
||||
partyChannel.Name,
|
||||
partyChannel.ChannelType.ToString(),
|
||||
partyChannel.CreatedAt)));
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@ public static class ServiceRegistration
|
||||
services.AddTransient<IMessageHandler, ChatPartyInviteHandler>();
|
||||
services.AddTransient<IMessageHandler, ChatPartyInviteRespondHandler>();
|
||||
services.AddTransient<IMessageHandler, ChatPartyLeaveHandler>();
|
||||
services.AddTransient<IMessageHandler, ChatPartyRenameHandler>();
|
||||
services.AddHostedService<ChatLifecycleHostedService>();
|
||||
|
||||
return services;
|
||||
|
||||
Reference in New Issue
Block a user