// // // import 'package:guru_app/account/account_data_store.dart'; // import 'package:guru_app/account/model/account_profile.dart'; // import 'package:guru_app/account/model/user.dart'; // import 'package:guru_utils/controller/controller.dart'; // // /// Created by Haoyi on 2022/5/23 // // mixin AccountAware on LifecycleController { // AccountDataStore get accountDataStore => AccountDataStore.instance; // // Stream get observableAccountProfile => accountDataStore.observableAccountProfile; // // String? get saasToken => accountDataStore.saasToken; // // String? get uid => accountDataStore.uid; // // AccountProfile? get accountProfile => accountDataStore.accountProfile; // // String? get nickname => accountDataStore.nickname; // // String? get countryCode => accountDataStore.countryCode; // // SaasUser? get user => accountDataStore.user; // // DeviceInfo? get currentDevice => accountDataStore.currentDevice; // // String? get userAvatar => accountProfile?.avatar; // // CumulativeInt? get bestScore => accountProfile?.bestScore; // // bool get accountInitialized => accountDataStore.initialized; // // Stream get observableNickname => // observableAccountProfile.map((accountProfile) => accountProfile?.nickname); // // Stream get observableAccountInitialized => accountDataStore.observableInitialized; // // void initAccount() { // Injector.provide().init(); // } // // Future updateAccountProfile( // {String? nickname, String? avatar, CumulativeInt? bestScore, String? countryCode}) async { // final accountService = Injector.provide(); // // final rankService = Injector.provide(); // return await accountService.modifyProfile( // nickname: nickname, avatar: avatar, bestScore: bestScore, countryCode: countryCode); // // if (result) { // // await rankService.refreshAccountProfile(); // // } // return true; // } // // // Future uploadBestScore() async { // // final accountService = Injector.provide(); // // final rankService = Injector.provide(); // // final latestBestScore = StatisticManager.instance.peekBestScore(); // // final accountBestScore = bestScore ?? CumulativeInt.zero; // // // // Log.w("uploadBestScore latestBestScore! $latestBestScore $accountBestScore", // // syncFirebase: true); // // if (latestBestScore > accountBestScore) { // // String? changedCountryCode = DeviceUtils.buildLocaleInfo().countryCode.toUpperCase(); // // if (DartExt.isBlank(changedCountryCode) || countryCode == changedCountryCode) { // // changedCountryCode = null; // // } // // try { // // await accountService.modifyProfile( // // bestScore: latestBestScore, countryCode: changedCountryCode); // // } catch (error, stacktrace) { // // Log.w("modifyProfile error!", error: error, stackTrace: stacktrace, syncFirebase: true); // // } // // } // // await rankService.uploadBestScore(latestBestScore); // // return true; // // } // // // // RankData buildEmptyRankData(String boardId, {CumulativeInt? bestScore}) { // // return RankData( // // boardId, // // uid ?? "", // // -1, // // bestScore ?? this.bestScore, // // LbUserInfo( // // nickname: nickname ?? "", // // countryCode: DeviceUtils.buildLocaleInfo().countryCode.toUpperCase(), // // avatar: "avatar_1", // // attr: UserAttr.real)); // // } // }