Exclude own player from chat mention suggestions

This commit is contained in:
coyotte508 2026-09-13 17:18:18 +02:00
commit 9d48f28519
2 changed files with 23 additions and 2 deletions

View file

@ -9,7 +9,14 @@
let choice = $state(0);
let dismissed = $state(false);
const query = $derived(dismissed ? null : mentionQueryAt(chat.draft, caret));
const candidates = $derived(query ? filterMentionCandidates(chat.mentions, query.query) : []);
const candidates = $derived(
query
? filterMentionCandidates(
chat.mentions.filter((player) => store.seat === undefined || player.playerIndex !== store.seat),
query.query
)
: []
);
async function chooseMention(name: string) {
if (!query) return;
const next = applyMention(chat.draft, query, name);

View file

@ -26,7 +26,13 @@ for (const width of [390, 1400]) {
e.on("chat:send", (m) => sent.push(m));
e.emit("player", { index: 0 });
e.emit("state", s);
e.emit("chat:state", { canSend: true, mentions: [{ id: "u1", name: "Full Name", playerIndex: 1 }] });
e.emit("chat:state", {
canSend: true,
mentions: [
{ id: "u0", name: "You", playerIndex: 0 },
{ id: "u1", name: "Full Name", playerIndex: 1 },
],
});
e.emit("chat:messages", [
{
_id: "000000000000000000000001",
@ -46,6 +52,14 @@ for (const width of [390, 1400]) {
},
stripSecret(s, 0)
);
await p.getByRole("textbox", { name: "Chat message" }).fill("@");
const suggestions = p.locator(".mention-choices");
assert.equal(await suggestions.getByRole("button", { name: "@You", exact: true }).count(), 0);
assert.equal(await suggestions.getByRole("button", { name: "@Full Name", exact: true }).isVisible(), true);
await p.evaluate(() => e.emit("player", { index: 1 }));
await suggestions.getByRole("button", { name: "@You", exact: true }).waitFor();
assert.equal(await suggestions.getByRole("button", { name: "@Full Name", exact: true }).count(), 0);
await p.evaluate(() => e.emit("player", { index: 0 }));
await p.getByRole("textbox", { name: "Chat message" }).fill("@F");
await p.getByRole("textbox", { name: "Chat message" }).press("Enter");
assert.equal(await p.getByRole("textbox", { name: "Chat message" }).inputValue(), '@"Full Name" ');