Merge pull request #173 from pangeachat/matrix-profile

added remaining pangea profile info to matrix profile
pull/1116/head
ggurdin 2 years ago committed by GitHub
commit 8bf5cabe5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -68,13 +68,60 @@ class UserController extends BaseController {
}
Future<void> migrateMatrixProfile() async {
final String? pangeaDob = userModel?.profile?.dateOfBirth;
final Profile? pangeaProfile = userModel?.profile;
final String? pangeaDob = pangeaProfile?.dateOfBirth;
final String? matrixDob = _pangeaController.pStoreService.read(
ModelKey.userDateOfBirth,
);
final String? dob =
pangeaDob != null && matrixDob != pangeaDob ? pangeaDob : null;
final pangeaCreatedAt = pangeaProfile?.createdAt;
final matrixCreatedAt = _pangeaController.pStoreService.read(
MatrixProfile.createdAt.title,
);
final String? createdAt =
pangeaCreatedAt != null && matrixCreatedAt != pangeaCreatedAt
? pangeaCreatedAt
: null;
final String? pangeaTargetLanguage = pangeaProfile?.targetLanguage;
final String? matrixTargetLanguage = _pangeaController.pStoreService.read(
MatrixProfile.targetLanguage.title,
);
final String? targetLanguage = pangeaTargetLanguage != null &&
matrixTargetLanguage != pangeaTargetLanguage
? pangeaTargetLanguage
: null;
final String? pangeaSourceLanguage = pangeaProfile?.sourceLanguage;
final String? matrixSourceLanguage = _pangeaController.pStoreService.read(
MatrixProfile.sourceLanguage.title,
);
final String? sourceLanguage = pangeaSourceLanguage != null &&
matrixSourceLanguage != pangeaSourceLanguage
? pangeaSourceLanguage
: null;
final String? pangeaCountry = pangeaProfile?.country;
final String? matrixCountry = _pangeaController.pStoreService.read(
MatrixProfile.country.title,
);
final String? country =
pangeaCountry != null && matrixCountry != pangeaCountry
? pangeaCountry
: null;
final bool? pangeaPublicProfile = pangeaProfile?.publicProfile;
final bool? matrixPublicProfile = _pangeaController.pStoreService.read(
MatrixProfile.publicProfile.title,
);
final bool? publicProfile = pangeaPublicProfile != null &&
matrixPublicProfile != pangeaPublicProfile
? pangeaPublicProfile
: null;
final bool? autoPlay = migratedProfileInfo(MatrixProfile.autoPlayMessages);
final bool? trial = migratedProfileInfo(MatrixProfile.activatedFreeTrial);
final bool? interactiveTranslator =
@ -104,6 +151,11 @@ class UserController extends BaseController {
showedItInstructions: showItInstructions,
showedClickMessage: showClickMessage,
showedBlurMeansTranslate: showBlurMeansTranslate,
createdAt: createdAt,
targetLanguage: targetLanguage,
sourceLanguage: sourceLanguage,
country: country,
publicProfile: publicProfile,
);
}
@ -150,9 +202,14 @@ class UserController extends BaseController {
refresh: userModel!.refresh,
profile: updatedUserProfile,
).save(_pangeaController);
if (dateOfBirth != null) {
await updateMatrixProfile(dateOfBirth: dateOfBirth);
}
await updateMatrixProfile(
dateOfBirth: dateOfBirth,
targetLanguage: targetLanguage,
sourceLanguage: sourceLanguage,
country: country,
publicProfile: publicProfile,
);
}
PUserModel? get userModel {
@ -175,6 +232,11 @@ class UserController extends BaseController {
bool? showedItInstructions,
bool? showedClickMessage,
bool? showedBlurMeansTranslate,
String? createdAt,
String? targetLanguage,
String? sourceLanguage,
String? country,
bool? publicProfile,
}) async {
if (dateOfBirth != null) {
await _pangeaController.pStoreService.save(
@ -242,6 +304,36 @@ class UserController extends BaseController {
showedBlurMeansTranslate,
);
}
if (createdAt != null) {
await _pangeaController.pStoreService.save(
MatrixProfile.createdAt.title,
createdAt,
);
}
if (targetLanguage != null) {
await _pangeaController.pStoreService.save(
MatrixProfile.targetLanguage.title,
targetLanguage,
);
}
if (sourceLanguage != null) {
await _pangeaController.pStoreService.save(
MatrixProfile.sourceLanguage.title,
sourceLanguage,
);
}
if (country != null) {
await _pangeaController.pStoreService.save(
MatrixProfile.country.title,
country,
);
}
if (publicProfile != null) {
await _pangeaController.pStoreService.save(
MatrixProfile.publicProfile.title,
publicProfile,
);
}
}
void _completeCompleter() {

@ -63,6 +63,11 @@ enum MatrixProfile {
showedItInstructions,
showedClickMessage,
showedBlurMeansTranslate,
createdAt,
targetLanguage,
sourceLanguage,
country,
publicProfile,
}
extension MatrixProfileExtension on MatrixProfile {
@ -90,6 +95,16 @@ extension MatrixProfileExtension on MatrixProfile {
return InstructionsEnum.clickMessage.toString();
case MatrixProfile.showedBlurMeansTranslate:
return InstructionsEnum.blurMeansTranslate.toString();
case MatrixProfile.createdAt:
return ModelKey.userCreatedAt;
case MatrixProfile.targetLanguage:
return ModelKey.l2LanguageKey;
case MatrixProfile.sourceLanguage:
return ModelKey.l1LanguageKey;
case MatrixProfile.country:
return ModelKey.userCountry;
case MatrixProfile.publicProfile:
return ModelKey.publicProfile;
}
}
}

Loading…
Cancel
Save