사이트: 모르는 유저 다시 받기가 한 번 실패하면 영영 안 받던 문제
받는 중 중복만 막고, 실패하면 다음 이벤트에서 다시 받는다 (성공한 아이디만 기억). lib/unknown-users.ts 로 빼고 테스트 추가, 목 서버에 /mock/users-fail · latejoin?again=1 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
24
site/web/src/lib/unknown-users.ts
Normal file
24
site/web/src/lib/unknown-users.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* 처음 보는 유저 아이디가 오면 유저 목록을 다시 받아 온다 (v1.4.1 이하 앱은 녹음 중에 들어온 사람을 알려 주지 않아 "알 수 없음"으로 뜸).
|
||||
* - 받는 중에는 또 부르지 않는다
|
||||
* - 받기에 성공한 아이디는 다시 묻지 않는다 (목록에 없어도 매 발화마다 부르지 않게)
|
||||
* - 실패하면 기억하지 않아 다음 이벤트에서 다시 받는다
|
||||
*/
|
||||
export function makeUnknownUserCheck(load: () => Promise<unknown>) {
|
||||
const done = new Set<string>();
|
||||
let busy = false;
|
||||
return (ids: string[], known: (id: string) => boolean): void => {
|
||||
if (busy) return;
|
||||
const fresh = ids.filter((id) => id && !known(id) && !done.has(id));
|
||||
if (!fresh.length) return;
|
||||
busy = true;
|
||||
load()
|
||||
.then(
|
||||
() => fresh.forEach((id) => done.add(id)),
|
||||
() => {},
|
||||
)
|
||||
.finally(() => {
|
||||
busy = false;
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, use
|
||||
import type { DeviceStatus, LiveEvent, Overview, User } from '@gvr/shared';
|
||||
import { api, onApiSignal, type Me } from '../lib/api';
|
||||
import { live, type LiveConn } from '../lib/live';
|
||||
import { makeUnknownUserCheck } from '../lib/unknown-users';
|
||||
|
||||
// ── 로그인 ───────────────────────────────────────────
|
||||
type AuthState = { status: 'loading' } | { status: 'anon' } | { status: 'not_member' } | { status: 'ok'; me: Me };
|
||||
@@ -139,22 +140,14 @@ 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 fetchUsers = useCallback(() => api.users().then((users) => setOverview((o) => (o ? { ...o, users } : o))), []);
|
||||
const reloadUsers = useCallback(() => void fetchUsers().catch(() => {}), [fetchUsers]);
|
||||
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 unknownCheck = useRef(makeUnknownUserCheck(fetchUsers));
|
||||
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();
|
||||
if (overview) unknownCheck.current(ids, (id) => map.has(id));
|
||||
};
|
||||
useLive((e) => {
|
||||
if (e.type === 'users.updated') {
|
||||
|
||||
Reference in New Issue
Block a user