93 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Dart
		
	
	
			
		
		
	
	
			93 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Dart
		
	
	
| //
 | |
| //
 | |
| // 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<AccountProfile?> 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<String?> get observableNickname =>
 | |
| //       observableAccountProfile.map<String?>((accountProfile) => accountProfile?.nickname);
 | |
| //
 | |
| //   Stream<bool> get observableAccountInitialized => accountDataStore.observableInitialized;
 | |
| //
 | |
| //   void initAccount() {
 | |
| //     Injector.provide<AccountService>().init();
 | |
| //   }
 | |
| //
 | |
| //   Future<bool> updateAccountProfile(
 | |
| //       {String? nickname, String? avatar, CumulativeInt? bestScore, String? countryCode}) async {
 | |
| //     final accountService = Injector.provide<AccountService>();
 | |
| //     // final rankService = Injector.provide<RankService>();
 | |
| //     return await accountService.modifyProfile(
 | |
| //         nickname: nickname, avatar: avatar, bestScore: bestScore, countryCode: countryCode);
 | |
| //     // if (result) {
 | |
| //     //   await rankService.refreshAccountProfile();
 | |
| //     // }
 | |
| //     return true;
 | |
| //   }
 | |
| //
 | |
| //   // Future<bool> uploadBestScore() async {
 | |
| //   //   final accountService = Injector.provide<AccountService>();
 | |
| //   //   final rankService = Injector.provide<RankService>();
 | |
| //   //   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));
 | |
| //   // }
 | |
| // }
 |