앱 공통 계층 — 데이터 저장소 · 서버 시계 · 푸시 · 결제·광고 · 다국어 5종 · 행성 표현 · 공통 UI · 화면 자산
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import 'backend.dart';
|
||||
|
||||
/// 내 초대 코드 — 공유 링크 `?ref=` 에 붙는다(원장 B-69 추천).
|
||||
///
|
||||
/// 세션당 한 번 `fnInviteCodeGet` 을 부른다(없으면 서버가 만든다). 공유는 이 값을 기다리지
|
||||
/// 않는다 — 아직 없거나 실패했으면 `?ref=` 없이 나간다. 계정이 바뀌면 다시 받는다.
|
||||
class InviteCode {
|
||||
InviteCode._();
|
||||
|
||||
/// 받아 둔 코드. 없으면 null.
|
||||
static String? current;
|
||||
|
||||
static String? _uid;
|
||||
static Future<void>? _fetch;
|
||||
|
||||
static Future<void> ensure(Backend backend) {
|
||||
final uid = backend.uid;
|
||||
if (uid == null) return Future.value();
|
||||
if (uid != _uid) {
|
||||
_uid = uid;
|
||||
current = null;
|
||||
_fetch = null;
|
||||
}
|
||||
return _fetch ??= _load(backend, uid);
|
||||
}
|
||||
|
||||
static Future<void> _load(Backend backend, String uid) async {
|
||||
try {
|
||||
final code = (await backend.call('fnInviteCodeGet'))['code'];
|
||||
if (_uid == uid && code is String && code.isNotEmpty) current = code;
|
||||
} catch (_) {
|
||||
if (_uid == uid) _fetch = null; // 다음 기회에 다시 받는다.
|
||||
}
|
||||
}
|
||||
|
||||
/// 테스트가 회차마다 처음 상태로 돌린다.
|
||||
static void reset() {
|
||||
current = null;
|
||||
_uid = null;
|
||||
_fetch = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user