Merge branch 'main' into toolbar-min-dimensions

pull/1428/head
ggurdin 1 year ago committed by GitHub
commit 5ba7e938bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,18 +1,18 @@
import 'dart:async'; import 'dart:async';
class BaseController<T> { class BaseController<T> {
final StreamController<T> stateListener = StreamController<T>(); final StreamController<T> _stateListener = StreamController<T>();
late Stream<T> stateStream; late Stream<T> stateStream;
BaseController() { BaseController() {
stateStream = stateListener.stream.asBroadcastStream(); stateStream = _stateListener.stream.asBroadcastStream();
} }
dispose() { dispose() {
stateListener.close(); _stateListener.close();
} }
setState(T data) { setState(T data) {
stateListener.add(data); _stateListener.add(data);
} }
} }

@ -121,19 +121,26 @@ class UserController extends BaseController {
/// Initializes the user's profile by waiting for account data to load, reading in account /// Initializes the user's profile by waiting for account data to load, reading in account
/// data to profile, and migrating from the pangea profile if the account data is not present. /// data to profile, and migrating from the pangea profile if the account data is not present.
Future<void> _initialize() async { Future<void> _initialize() async {
// wait for account data to load
// as long as it's not null, then this we've already migrated the profile
await _pangeaController.matrixState.client.waitForAccountData(); await _pangeaController.matrixState.client.waitForAccountData();
if (profile.userSettings.dateOfBirth != null) { if (profile.userSettings.dateOfBirth != null) {
return; return;
} }
// we used to store the user's profile in the pangea server
// we now store it in the matrix account data
final PangeaProfileResponse? resp = await PUserRepo.fetchPangeaUserInfo( final PangeaProfileResponse? resp = await PUserRepo.fetchPangeaUserInfo(
userID: userId!, userID: userId!,
matrixAccessToken: _matrixAccessToken!, matrixAccessToken: _matrixAccessToken!,
); );
// if it's null, we don't have a profile in the pangea server
if (resp?.profile == null) { if (resp?.profile == null) {
return; return;
} }
// if we have a profile in the pangea server, we need to migrate it to the matrix account data
final userSetting = UserSettings.fromJson(resp!.profile.toJson()); final userSetting = UserSettings.fromJson(resp!.profile.toJson());
final newProfile = Profile(userSettings: userSetting); final newProfile = Profile(userSettings: userSetting);
await newProfile.saveProfileData(waitForDataInSync: true); await newProfile.saveProfileData(waitForDataInSync: true);

@ -125,3 +125,12 @@ extension ConstructUseTypeExtension on ConstructUseTypeEnum {
} }
} }
} }
class ConstructUseTypeUtil {
static ConstructUseTypeEnum fromString(String value) {
return ConstructUseTypeEnum.values.firstWhere(
(e) => e.string == value,
orElse: () => ConstructUseTypeEnum.nan,
);
}
}

@ -1,6 +1,5 @@
import 'dart:developer'; import 'dart:developer';
import 'package:collection/collection.dart';
import 'package:fluffychat/pangea/enum/construct_use_type_enum.dart'; import 'package:fluffychat/pangea/enum/construct_use_type_enum.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
@ -106,9 +105,7 @@ class OneConstructUse {
debugger(when: kDebugMode && constructType == null); debugger(when: kDebugMode && constructType == null);
return OneConstructUse( return OneConstructUse(
useType: ConstructUseTypeEnum.values useType: ConstructUseTypeUtil.fromString(json['useType']),
.firstWhereOrNull((e) => e.string == json['useType']) ??
ConstructUseTypeEnum.unk,
lemma: json['lemma'], lemma: json['lemma'],
form: json['form'], form: json['form'],
categories: json['categories'] != null categories: json['categories'] != null

@ -27,12 +27,7 @@ class ConstructWithXP {
? DateTime.parse(json['last_used'] as String) ? DateTime.parse(json['last_used'] as String)
: null, : null,
condensedConstructUses: (json['uses'] as List<String>).map((e) { condensedConstructUses: (json['uses'] as List<String>).map((e) {
return ConstructUseTypeEnum.values.firstWhereOrNull( return ConstructUseTypeUtil.fromString(e);
(element) =>
element.string == e ||
element.toString().split('.').last == e,
) ??
ConstructUseTypeEnum.nan;
}).toList(), }).toList(),
); );
} }

Loading…
Cancel
Save