SAAS-002 · Mobile architect chat polish
Отдельный файл отчёта для этой задачи не найден или не указан. Показан сохранённый результат задачи.
The mobile Architect Chat is improved and its new regression tests pass. I tested it with a fake DOM in Node and against the real PHP app on a local test server, not on a real iPhone. Nothing is committed or deployed, and no live service was touched.
Bugs fixed from the earlier unfinished chat.js draft:
- It cleared and disabled the textarea before reading the form, so it would have posted an empty message.
- It removed messages with identical text, so a user who wrote "yes" twice would only see it once.
What changed (console/chat.js, rewritten):
- No repeated messages: the server and the browser now identify each message the same way (role, timestamp and length). When the chat refreshes, it keeps the messages already on screen and only adds new ones. The temporary copy of a message you just sent is swapped for the saved one, so it never appears twice.
- Scrolling: only the chat area scrolls to the newest message; the page itself never moves. If the user has scrolled up to read, a new message doesn't pull them down.
- iOS keyboard:
- The text box is no longer disabled while the architect is answering, so the keyboard stays open; only the Send button is disabled.
- Tapping Send doesn't close the keyboard.
- The chat area shrinks to fit above the keyboard.
- The text box grows as you type, up to a limit.
- The keyboard shows a Send key. Enter sends, Shift+Enter adds a new line, and typing in input methods like Japanese isn't interrupted.
- Focus: the text box gets focus back after sending or after an answer arrives, but only if it had focus before. On page load it is focused only on desktop, so phones don't pop up the keyboard.
- Status messages: clear text for sending, thinking, the architect failing to answer, connection lost, and session ended (which also stops the refreshing). If the server rejects a message, for example "Wait for the previous answer.", the real reason is shown and the user's text is put back.
- Security: the regular refresh still uses the logged-in session (same-origin, no-store), the security token (CSRF) is still sent with every message, and refreshing pauses while the browser tab is hidden.
console/index.php (markup and styling only, no server logic changed):
- Messages are now shown as plain escaped text (with line breaks kept by CSS), so the page and the script show exactly the same text.
- Keyboard-friendly settings on the text box and the page, including a 16px font so iPhones don't zoom in when you tap it.
- Space for the iPhone home bar, a minimum 44px tap size for Send, and distinct colours for the different status messages.
Tests added:
tests/architect-chat-client.test.mjs runs the real chat.js and checks 8 scenarios, including sending, no duplicates, genuine repeats, rejected messages, failures, session end, scroll position and Enter-key handling.tests/architect-chat-mobile-regression.php (replaces the earlier draft test) starts the real app with a temporary database. It checks:- a sent message redirects, so reloading the page can't send it again;
- a second message while the first is still waiting is rejected;
- a reloaded page shows the message exactly once;
- forms without a valid token, or with a token from another session, are refused;
- chat updates are refused without login.
It then runs the Node test.
Checks:
php -l passes on every file in console/, app/ and `te
[truncated]
Материалы