From dc1f4c3492946dd74a953e2ba7594405b0e7c63c Mon Sep 17 00:00:00 2001 From: Alexa <53471801+Alexa-RR@users.noreply.github.com> Date: Tue, 28 Jul 2026 09:48:38 +0300 Subject: [PATCH] fix: improve thread existence check to allow new conversations without 404 --- DorkNet.Server/Controllers/Chat/ChatController.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/DorkNet.Server/Controllers/Chat/ChatController.cs b/DorkNet.Server/Controllers/Chat/ChatController.cs index 54889ba..eb6159e 100644 --- a/DorkNet.Server/Controllers/Chat/ChatController.cs +++ b/DorkNet.Server/Controllers/Chat/ChatController.cs @@ -151,7 +151,19 @@ public class ChatController( .OrderByDescending(c => c.SentAt) .Take(take) .ToListAsync(); - if (rows.Count == 0) return NotFound(); + + // An empty thread is NOT a missing thread. Starting a chat with someone + // goes POST thread/withmembers (which creates the thread) and then + // immediately GET thread/{id} — at that moment it has no messages yet. + // 404-ing on message count meant a brand-new conversation could never be + // opened: the client got "not found" for the thread it had just been + // handed. Only 404 when nothing actually records the thread. + if (rows.Count == 0) + { + var exists = await db.ChatThreads.AnyAsync(t => t.ThreadKey == key) + || await db.ChatThreadMembers.AnyAsync(m => m.ThreadKey == key); + if (!exists) return NotFound(); + } var meta = (await EnsureThreadRowsAsync(new[] { key }))[key]; var member = await db.ChatThreadMembers .FirstOrDefaultAsync(m => m.ThreadKey == key && m.PlayerId == Me);