v1.4.2: 녹음 중에 들어온 사람이 사이트에서 "알 수 없음"으로 뜨던 문제

- 앱: 녹음 중 새로 들어온 사람을 저장한 뒤 users.updated 를 보낸다
- 사이트: 실시간 발화 · 녹음 상태에 모르는 유저 아이디가 오면 유저 목록을 한 번 다시 받는다 (예전 앱 대비)
- 목 서버: /mock/latejoin 로 재현

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-16 22:41:48 +09:00
parent c6a8721fce
commit 79d6bb2aad
8 changed files with 74 additions and 12 deletions

View File

@@ -139,21 +139,36 @@ export function DataProvider({ children }: { children: ReactNode }) {
alive = false;
};
}, [epoch, locked]);
const reloadUsers = useCallback(() => {
api
.users()
.then((users) => setOverview((o) => (o ? { ...o, users } : o)))
.catch(() => {});
}, []);
const users = overview?.users ?? [];
const map = useMemo(() => new Map(users.map((u) => [u.id, u])), [users]);
// 처음 보는 사람 아이디는 한 번만 유저 목록을 다시 받아 온다 (v1.4.1 이하 앱은 녹음 중에 들어온 사람을 알려 주지 않아 "알 수 없음"으로 뜸)
const asked = useRef(new Set<string>());
const checkUnknown = (ids: string[]) => {
if (!overview) return;
const fresh = ids.filter((id) => id && !map.has(id) && !asked.current.has(id));
if (!fresh.length) return;
fresh.forEach((id) => asked.current.add(id));
reloadUsers();
};
useLive((e) => {
if (e.type === 'users.updated') {
// v1.3.5 이하 앱은 빈 목록을 보낸다: 그대로 쓰면 모든 발화가 "알 수 없음"이 되니 다시 받아 온다
if (e.data.length) setOverview((o) => (o ? { ...o, users: e.data } : o));
else
api
.users()
.then((users) => setOverview((o) => (o ? { ...o, users } : o)))
.catch(() => {});
else reloadUsers();
}
if (e.type === 'recording.state') setOverview((o) => (o ? { ...o, recording: e.data } : o));
if (e.type === 'recording.state') {
setOverview((o) => (o ? { ...o, recording: e.data } : o));
checkUnknown(e.data.participants);
}
if (e.type === 'utterance.created' || e.type === 'utterance.updated') checkUnknown([e.data.userId]);
if (e.type === 'games.state') setOverview((o) => (o ? { ...o, live: e.data } : o));
});
const users = overview?.users ?? [];
const map = useMemo(() => new Map(users.map((u) => [u.id, u])), [users]);
const userById = useCallback((id: string | undefined | null) => (id ? map.get(id) : undefined), [map]);
return <DataCtx.Provider value={{ overview, users, userById }}>{children}</DataCtx.Provider>;
}