some code cleanup and comments

pull/1428/head
William Jordan-Cooley 1 year ago
parent 17261600d2
commit 00d6277bc6

@ -1,18 +1,18 @@
import 'dart:async';
class BaseController<T> {
final StreamController<T> stateListener = StreamController<T>();
final StreamController<T> _stateListener = StreamController<T>();
late Stream<T> stateStream;
BaseController() {
stateStream = stateListener.stream.asBroadcastStream();
stateStream = _stateListener.stream.asBroadcastStream();
}
dispose() {
stateListener.close();
_stateListener.close();
}
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
/// data to profile, and migrating from the pangea profile if the account data is not present.
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();
if (profile.userSettings.dateOfBirth != null) {
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(
userID: userId!,
matrixAccessToken: _matrixAccessToken!,
);
// if it's null, we don't have a profile in the pangea server
if (resp?.profile == null) {
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 newProfile = Profile(userSettings: userSetting);
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 'package:collection/collection.dart';
import 'package:fluffychat/pangea/enum/construct_use_type_enum.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:flutter/foundation.dart';
@ -106,9 +105,7 @@ class OneConstructUse {
debugger(when: kDebugMode && constructType == null);
return OneConstructUse(
useType: ConstructUseTypeEnum.values
.firstWhereOrNull((e) => e.string == json['useType']) ??
ConstructUseTypeEnum.unk,
useType: ConstructUseTypeUtil.fromString(json['useType']),
lemma: json['lemma'],
form: json['form'],
categories: json['categories'] != null

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

Loading…
Cancel
Save