Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
e124fa0
Add Meet-style home with explicit room actions
https-shini Nov 9, 2026
b7903c2
Separate identity login from entering a room
https-shini Nov 9, 2026
0224ce9
Navigate to home after session acceptance
https-shini Nov 9, 2026
9c61e22
Wire explicit home and room selection into frontend
https-shini Nov 9, 2026
d8f1ce7
Keep identity active on room errors and distinguish create from join
https-shini Nov 9, 2026
ce5be2f
Style responsive home actions
https-shini Nov 9, 2026
43fc205
Load home stylesheet
https-shini Nov 9, 2026
0152a77
Preserve room on reconnect and allow returning home
https-shini Nov 9, 2026
d398a9c
Return to home after leaving room and validate invite codes
https-shini Nov 9, 2026
4cf601d
Reuse canonical invite parser in home
https-shini Nov 9, 2026
28e2c57
Destroy empty rooms immediately by default
https-shini Nov 9, 2026
b02f591
Add separate home navigation and explicit leave-room action
https-shini Nov 9, 2026
aa7411c
Expose home and leave-room controls in chat interface
https-shini Nov 9, 2026
8ef7fee
Style distinct room navigation and leave controls
https-shini Nov 9, 2026
b810ff5
feat(state): track room conversations independently with unread count…
https-shini Nov 9, 2026
510878a
feat(events): route room-specific traffic to conversation store and r…
https-shini Nov 9, 2026
8ea1dd1
feat(home): list active rooms and unread previews with room actions
https-shini Nov 9, 2026
13b060c
feat(main): use conversation registry for explicit selection, reconne…
https-shini Nov 9, 2026
8e3c750
style(home): responsive active conversation cards
https-shini Nov 9, 2026
ffa514a
style(home): format CSS according to project conventions
https-shini Nov 9, 2026
4ccc2fd
feat(session): restore temporary identity on same-tab refresh
https-shini Nov 9, 2026
825c8c3
style(events): format conversation routing and people mapping
https-shini Nov 9, 2026
7ea88e4
style(home): align JavaScript with Prettier formatting
https-shini Nov 9, 2026
442344a
fix(events): ignore departures from unrelated conversations
https-shini Nov 9, 2026
ae1b8c7
test(rooms): explicitly select room after login in event fixture
https-shini Nov 9, 2026
742b748
test(conversations): cover isolation, switching, unread counts and re…
https-shini Nov 9, 2026
414044d
ci: diagnose PR6 type, lint, build and test failures independently of…
https-shini Nov 9, 2026
958a5b5
fix(frontend): annotate recovery state and guarded room actions
https-shini Nov 9, 2026
9401159
fix(store): address strict nullability and const typing
https-shini Nov 9, 2026
73d561a
fix(events): type room routing, members and room listing
https-shini Nov 9, 2026
65031ca
test(history): explicitly activate a room before asserting its transc…
https-shini Nov 9, 2026
71e94f6
test(entry): assert Home-first flow and explicit conversation selection
https-shini Nov 9, 2026
4e57371
refactor(home): construct safe DOM without innerHTML and type compone…
https-shini Nov 9, 2026
08ed21f
security(frontend): replace unsafe room navigation innerHTML with DOM…
https-shini Nov 9, 2026
24e916f
style(css): use lowercase color keyword to pass Stylelint
https-shini Nov 9, 2026
eeadf3e
ci(diag): emit canonical Prettier results to resolve blocked PR forma…
https-shini Nov 9, 2026
8080b5e
fix(home): complete JS type annotations for DOM factory
https-shini Nov 9, 2026
70de22d
style(prettier): apply canonical formatting to frontend/src/main.js
https-shini Nov 9, 2026
b9ff339
style(prettier): apply canonical formatting to frontend/src/state/eve…
https-shini Nov 9, 2026
1f05006
style(prettier): apply canonical formatting to frontend/src/state/sto…
https-shini Nov 9, 2026
83de09b
style(prettier): apply canonical formatting to frontend/test/conversa…
https-shini Nov 9, 2026
0445f0a
style(prettier): format accessible Home component
https-shini Nov 9, 2026
80c9b0a
feat(protocol): add rate-limited user search request and result events
https-shini Nov 9, 2026
8d1a19e
feat(protocol): add rate-limited user search request and result events
https-shini Nov 9, 2026
d7c0ba4
feat(identity): bounded online username search with private session i…
https-shini Nov 9, 2026
eb8dbb6
feat(hub): authorize and rate-limit partial username search
https-shini Nov 9, 2026
b40db5d
feat(protocol): serialize username search results
https-shini Nov 9, 2026
2a7c607
feat(transport): expose authorized username lookup through WebSocket
https-shini Nov 9, 2026
ff7ff30
feat(ui): accessible debounced username search with results and loadi…
https-shini Nov 9, 2026
7f0e0a1
feat(home): integrate username lookup panel and search results
https-shini Nov 9, 2026
60db546
feat(events): validate and deliver username search results to UI
https-shini Nov 9, 2026
d12d33c
feat(main): wire debounced user search into real-time backend
https-shini Nov 9, 2026
7a75594
style(search): responsive username search list and feedback
https-shini Nov 9, 2026
0af3b3d
test(search): verify privacy, partial lookup and per-user rate limiting
https-shini Nov 9, 2026
d8a23b6
ci: include username search in canonical formatting diagnostics
https-shini Nov 9, 2026
94f58ba
feat(room): share room engine with DMs and explicitly close private h…
https-shini Nov 9, 2026
0d81afe
feat(directory): unique temporary DMs with shared history engine and …
https-shini Nov 9, 2026
a9d0237
feat(server): instantiate direct chats with existing scoped room engine
https-shini Nov 9, 2026
bd01869
feat(protocol): add authenticated direct conversation open operation
https-shini Nov 9, 2026
f4f05b7
feat(protocol): add authenticated direct conversation open operation
https-shini Nov 9, 2026
3a5c1d8
feat(hub): initiate authorized DM with online username and rate limiting
https-shini Nov 9, 2026
5edc3db
feat(errors): explicit user-unavailable response for DM requests
https-shini Nov 9, 2026
e7a6687
feat(errors): explicit user-unavailable response for DM requests
https-shini Nov 9, 2026
09976fd
feat(ws): route DM creation to authenticated conversation hub
https-shini Nov 9, 2026
6af765f
fix(dm): avoid double-destroy after closing private conversation
https-shini Nov 9, 2026
86fd162
feat(events): identify direct messages in conversation list
https-shini Nov 9, 2026
8fe6876
feat(ui): render private conversation header without invitation code
https-shini Nov 9, 2026
48b2aec
feat(frontend): start direct chats, open DM without invite URLs and c…
https-shini Nov 9, 2026
b9225fb
test(entry): expect conversation kind metadata in room selection
https-shini Nov 9, 2026
8ce1523
test(dm): real WebSocket private messaging, deduplication, authorizat…
https-shini Nov 9, 2026
2fcc196
ci: capture Prettier formatting for all DM files
https-shini Nov 9, 2026
55d8486
style(prettier): normalize frontend/src/main.js
https-shini Nov 9, 2026
dc8a34d
style(prettier): normalize frontend/src/state/events.js
https-shini Nov 9, 2026
d12293a
style(prettier): normalize frontend/src/ui/home.js
https-shini Nov 9, 2026
ff9fbf2
style(prettier): format backend/test/integration/direct.test.js
https-shini Nov 9, 2026
1425889
style(prettier): format frontend/src/ui/roomHeader.js
https-shini Nov 9, 2026
c326aae
feat(ui): add Discord-like room navigation without leaving conversations
https-shini Nov 9, 2026
7493cc3
feat(navigation): switch live rooms and DMs directly in chat interface
https-shini Nov 9, 2026
c185755
style(navigation): responsive horizontal conversation switching
https-shini Nov 9, 2026
7a370f3
feat(errors): route unavailable-user DM errors to Home feedback
https-shini Nov 9, 2026
c810139
security(retention): purge deduplication message content when a room …
https-shini Nov 9, 2026
6507197
ci: include conversation navigation in formatting verification
https-shini Nov 9, 2026
e4cc26b
fix(types): annotate conversation navigation callback
https-shini Nov 9, 2026
15062df
docs: record PR6 architecture, privacy, local validation and remainin…
https-shini Nov 9, 2026
7b766dd
ci: include PR6 technical documentation in formatter output
https-shini Nov 9, 2026
8b14db8
feat(home): add explicit logout and DM/room labels for temporary chats
https-shini Nov 9, 2026
080b010
feat(session): provide Home logout and contextual DM termination button
https-shini Nov 9, 2026
70b70e8
style(docs): apply canonical Markdown formatting to PR6 handoff
https-shini Nov 9, 2026
b8cadfd
style(prettier): normalize Home logout and DM action markup
https-shini Nov 9, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/pr6-diagnostics.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: PR6 diagnostics

on:
push:
branches: ["feat/home-meet-discord-flow"]

permissions:
contents: read

jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "22"
cache: npm
- run: npm ci
- run: npm --prefix backend ci
- name: Emit canonical Prettier output for reviewable corrections
shell: bash
run: |
node --input-type=module <<'NODE'
import fs from "node:fs";
import prettier from "prettier";
for (const path of [
"frontend/src/main.js",
"frontend/src/state/events.js",
"frontend/src/state/store.js",
"frontend/src/ui/home.js",
"frontend/test/conversations.test.js",
"backend/src/protocol.js",
"backend/src/room/sessions.js",
"backend/src/room/hub.js",
"backend/src/transport/connection.js",
"backend/test/integration/userSearch.test.js",
"frontend/src/protocol.js",
"frontend/src/ui/userSearch.js",
"frontend/src/css/home.css",
"backend/src/room/room.js",
"backend/src/room/directory.js",
"backend/src/transport/chatServer.js",
"backend/src/errors.js",
"backend/test/integration/direct.test.js",
"frontend/src/ui/roomHeader.js",
"frontend/test/entry.test.js",
"frontend/src/ui/conversationTabs.js",
"docs/PR6-STATUS.md",
]) {
const original = fs.readFileSync(path, "utf8");
const config = await prettier.resolveConfig(path);
const formatted = await prettier.format(original, { ...config, filepath: path });
console.log("PR6_FORMAT:" + JSON.stringify({ path, content: formatted }));
}
NODE
- name: Run all independent quality checks without skipping failures
shell: bash
run: |
rc=0
npm run check:types || rc=1
npm run lint:js || rc=1
npm run lint:css || rc=1
npm run build || rc=1
npm test || rc=1
exit "$rc"
5 changes: 5 additions & 0 deletions backend/src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const ERROR_CODES = Object.freeze({
INVALID_NAME: "invalid_name",
INVALID_USERNAME: "invalid_username",
USERNAME_TAKEN: "username_taken",
USER_NOT_FOUND: "user_not_found",
EMPTY_MESSAGE: "empty_message",
ALREADY_LOGGED_IN: "already_logged_in",
NOT_LOGGED_IN: "not_logged_in",
Expand Down Expand Up @@ -63,6 +64,10 @@ const CATALOG = Object.freeze({
message:
"Username inválido ou reservado. Use de 3 a 20 caracteres: letras minúsculas sem acento, números, ponto ou _.",
},
[ERROR_CODES.USER_NOT_FOUND]: {
category: VALIDATION,
message: "Usuário indisponível para conversar no momento.",
},
[ERROR_CODES.USERNAME_TAKEN]: {
category: VALIDATION,
message: "Este username já está em uso. Escolha outro.",
Expand Down
14 changes: 14 additions & 0 deletions backend/src/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export const CLIENT_EVENTS = Object.freeze({
ROOM_LEAVE: "room_leave",
/** Pedir a lista das salas de que a identidade participa. */
ROOM_LIST: "room_list",
USER_SEARCH: "user_search",
DM_OPEN: "dm_open",
});

/** Eventos que o servidor envia. */
Expand All @@ -86,6 +88,7 @@ export const SERVER_EVENTS = Object.freeze({
ROOM_LIST: "room_list",
/** O resumo de uma sala mudou (ex.: anfitrião novo). */
ROOM_UPDATED: "room_updated",
USER_SEARCH_RESULTS: "user_search_results",
});

/**
Expand Down Expand Up @@ -262,6 +265,17 @@ export const serverMessage = Object.freeze({
payload: { rooms, ...(requestId ? { requestId } : {}) },
}),

/**
* Resultado de pesquisa de perfis públicos de identidades conectadas.
* @param {string} query
* @param {{id: string, name: string, username: string}[]} users
* @param {string | null} [requestId]
*/
userSearchResults: (query, users, requestId = null) => ({
type: SERVER_EVENTS.USER_SEARCH_RESULTS,
payload: { query, users, ...(requestId ? { requestId } : {}) },
}),

/** @param {unknown[]} entries mensagens de chat já no formato de envio */
history: (entries) => ({ type: SERVER_EVENTS.MESSAGE_HISTORY, payload: entries }),

Expand Down
72 changes: 63 additions & 9 deletions backend/src/room/directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Guarda as salas ativas por `conversationId` e por código de convite, gera
* códigos únicos e aplica os limites de criação e participação. É também
* quem decide quando uma sala acaba: sem nenhuma participação (nem de quem
* está na janela de retomada), ela espera `emptyTtlMs` e é destruída junto
* está na janela de retomada), ela espera `emptyTtlMs` (zero por padrão) e é destruída junto
* com o histórico. Entrar de novo durante a espera a mantém viva.
*
* Nada aqui sobrevive ao processo: reiniciar o servidor apaga todas as
Expand All @@ -27,7 +27,7 @@ export const ROOM_DEFAULTS = Object.freeze({
/** Salas ativas criadas por uma mesma identidade. */
maxCreatedPerIdentity: 5,
/** Tolerância de uma sala vazia antes de ser destruída. */
emptyTtlMs: 60_000,
emptyTtlMs: 0,
});

/** Código novo `abc-defg-hij`, com sorteio criptograficamente seguro. */
Expand All @@ -53,7 +53,7 @@ const CODE_ATTEMPTS = 20;

/**
* @param {{
* makeRoom: (identity: {id: string, code: string, name: string}) => Room,
* makeRoom: (identity: {id: string, code: string, name: string, kind?: "room" | "dm"}) => Room,
* log: (level: "info" | "warn" | "error", event: string, fields?: Record<string, unknown>) => void,
* limits?: Partial<typeof ROOM_DEFAULTS>,
* destroyScheduler?: Scheduler | null,
Expand All @@ -74,10 +74,12 @@ export const createRoomDirectory = ({
...limits,
};

/** @type {Map<string, {room: Room, createdBy: string, destroyTimer: unknown}>} */
/** @type {Map<string, {room: Room, createdBy: string | null, destroyTimer: unknown}>} */
const rooms = new Map();
/** código → conversationId @type {Map<string, string>} */
const byCode = new Map();
/** Pair of IDs to direct conversation ID. @type {Map<string, string>} */
const directPairs = new Map();
/** Salas ativas criadas por cada identidade (id → quantidade). @type {Map<string, number>} */
const created = new Map();

Expand All @@ -88,10 +90,19 @@ export const createRoomDirectory = ({
destroyScheduler.cancel(entry.destroyTimer);
}
rooms.delete(conversationId);
byCode.delete(entry.room.code);
const count = (created.get(entry.createdBy) ?? 1) - 1;
if (count > 0) created.set(entry.createdBy, count);
else created.delete(entry.createdBy);
if (entry.room.kind === "dm") {
for (const [key, value] of directPairs) {
if (value === conversationId) directPairs.delete(key);
}
} else {
byCode.delete(entry.room.code);
const owner = entry.createdBy;
if (owner !== null) {
const count = (created.get(owner) ?? 1) - 1;
if (count > 0) created.set(owner, count);
else created.delete(owner);
}
}
entry.room.destroy();
};

Expand Down Expand Up @@ -161,6 +172,42 @@ export const createRoomDirectory = ({
return { ok: true, room };
},

/**
* Cria DM única entre duas identidades, com a mesma infraestrutura
* de histórico e autorização das salas, mas sem código público.
* @param {Identity} source
* @param {Identity} target
*/
openDirect(source, target) {
if (source.id === target.id) {
return { ok: false, code: ERROR_CODES.INVALID_USERNAME };
}
const key = [source.id, target.id].sort().join(":");
const oldId = directPairs.get(key);
const existing = oldId ? rooms.get(oldId)?.room : null;
if (existing) {
existing.add(source);
return { ok: true, room: existing, already: true };
}
if (
source.rooms.size >= maxRoomsPerIdentity ||
target.rooms.size >= maxRoomsPerIdentity
) {
return { ok: false, code: ERROR_CODES.ROOM_JOIN_LIMIT };
}
if (rooms.size >= maxRooms) return { ok: false, code: ERROR_CODES.ROOMS_FULL };
const id = freshConversationId();
if (!id) return { ok: false, code: ERROR_CODES.ROOMS_FULL };
const name = "@" + source.username + " · @" + target.username;
const room = makeRoom({ id, code: "", name, kind: "dm" });
rooms.set(id, { room, createdBy: null, destroyTimer: null });
directPairs.set(key, id);
room.add(source);
room.add(target);
log("info", "direct_created", { conversation: id });
return { ok: true, room, already: false };
},

/**
* Entra numa sala pelo código (já no formato canônico).
* @param {Identity} identity
Expand Down Expand Up @@ -193,7 +240,14 @@ export const createRoomDirectory = ({
*/
leave(identity, conversationId, reason = REMOVAL_REASONS.LEFT) {
const entry = rooms.get(conversationId);
if (!entry || !entry.room.remove(identity, reason)) return false;
if (!entry) return false;
if (entry.room.kind === "dm") {
if (!entry.room.has(identity)) return false;
entry.room.closeDirect();
destroy(conversationId);
return true;
}
if (!entry.room.remove(identity, reason)) return false;
scheduleIfEmpty(conversationId);
return true;
},
Expand Down
67 changes: 67 additions & 0 deletions backend/src/room/hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

import { ERROR_CODES } from "../errors.js";
import { createRateLimiter } from "../rateLimiter.js";
import { LIMITS, ROLES, serverMessage } from "../protocol.js";
import {
normalizeText,
Expand Down Expand Up @@ -66,6 +67,26 @@ export const createHub = ({
/** Conexões com sessão. @type {Map<unknown, {identity: Identity, label: string}>} */
const connections = new Map();

// Consultas parciais não podem se transformar em enumeração ilimitada.
// Balde global impede que trocar repetidamente de identidade reinicie
// a cota do servidor; o balde individual limita o abuso por conta.
const globalSearchLimit = createRateLimiter({
capacity: 100,
refillPerSecond: 20,
now,
});
/** @type {WeakMap<Identity, () => boolean>} */
const searchLimiters = new WeakMap();
/** @param {Identity} identity */
const searchAllowed = (identity) => {
let allowed = searchLimiters.get(identity);
if (!allowed) {
allowed = createRateLimiter({ capacity: 5, refillPerSecond: 2, now });
searchLimiters.set(identity, allowed);
}
return allowed() && globalSearchLimit();
};

/** @param {unknown} member @param {Record<string, unknown>} message */
const sendTo = (member, message) => deliver(member, JSON.stringify(message));

Expand Down Expand Up @@ -270,6 +291,52 @@ export const createHub = ({

resolve,

/**
* Pesquisa limitada por identificador público @username.
* Só retorna pessoas online; dados da sessão nunca são enviados.
* @param {unknown} member
* @param {Record<string, unknown>} payload
* @returns {{ok: true, users: {id: string, name: string, username: string}[], query: string} | Refusal}
*/
openDirect(member, payload) {
const entry = connections.get(member);
if (!entry) return { ok: false, code: ERROR_CODES.NOT_LOGGED_IN };
if (!searchAllowed(entry.identity)) {
return { ok: false, code: ERROR_CODES.RATE_LIMITED };
}
const read = readUsername(payload.username);
if (!read.ok || !read.username) {
return { ok: false, code: ERROR_CODES.INVALID_USERNAME };
}
const target = identities.findOnline(read.username);
if (!target) return { ok: false, code: ERROR_CODES.USER_NOT_FOUND };
return directory.openDirect(entry.identity, target);
},

searchUsers(member, payload) {
const entry = connections.get(member);
if (!entry) return { ok: false, code: ERROR_CODES.NOT_LOGGED_IN };
if (!searchAllowed(entry.identity)) {
return { ok: false, code: ERROR_CODES.RATE_LIMITED };
}
if (typeof payload.query !== "string" || payload.query.length > 40) {
return { ok: false, code: ERROR_CODES.INVALID_USERNAME };
}
const query = payload.query.trim().replace(/^@/, "").toLowerCase();
if (
query.length < LIMITS.usernameMinLength ||
query.length > LIMITS.usernameMaxLength ||
!/^[a-z0-9_.]+$/.test(query)
) {
return { ok: false, code: ERROR_CODES.INVALID_USERNAME };
}
return {
ok: true,
query,
users: identities.searchOnline(query, entry.identity.id, 10),
};
},

/**
* @param {unknown} member
* @param {Record<string, unknown>} payload `{ conversationId, content, clientMsgId? }`
Expand Down
24 changes: 22 additions & 2 deletions backend/src/room/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const REMOVAL_REASONS = Object.freeze({
* id: string,
* code: string,
* name: string,
* kind?: "room" | "dm",
* deliver: (holder: unknown, data: string) => void,
* log: (level: "info" | "warn" | "error", event: string, fields?: Record<string, unknown>) => void,
* historySize: number,
Expand All @@ -92,6 +93,7 @@ export const createRoom = ({
id,
code,
name,
kind = "room",
deliver,
log,
historySize,
Expand Down Expand Up @@ -200,7 +202,7 @@ export const createRoom = ({
*/
const summaryFor = (identity) => ({
conversationId: id,
kind: "room",
kind,
code,
name,
role: members.get(identity)?.role ?? ROLES.MEMBER,
Expand Down Expand Up @@ -352,6 +354,7 @@ export const createRoom = ({
id,
code,
name,
kind,

/**
* Entrada na sala. Quem já participa recebe o estado de novo, sem
Expand Down Expand Up @@ -426,6 +429,16 @@ export const createRoom = ({

remove,

/** Encerramento definitivo de DM: informa os dois participantes e
* descarta o histórico, independentemente da conexão atual. */
closeDirect() {
if (kind !== "dm") return false;
for (const identity of members.keys()) {
sendTo(identity, serverMessage.roomLeft(id, ROOM_LEFT_REASONS.CLOSED));
}
return true;
},

/**
* Mensagem digitada. O autor é a identidade; `kind` e `format` do
* payload são ignorados (só comandos os produzem).
Expand Down Expand Up @@ -632,7 +645,14 @@ export const createRoom = ({
*/
destroy() {
this.silence();
for (const identity of members.keys()) identity.rooms.delete(id);
for (const identity of members.keys()) {
identity.rooms.delete(id);
// DMs apagadas não podem continuar retidas nos registros
// de deduplicação, que também carregam o texto da mensagem.
for (const key of identity.recent.keys()) {
if (key.startsWith(id + ":")) identity.recent.delete(key);
}
}
members.clear();
history.length = 0;
banned.clear();
Expand Down
Loading
Loading