2006 target language information needs to be updated when users change (#2069)

* chore: use short lang code in public profile

* chore: update public profile each time analytics are updated to account for case of missed target language update
This commit is contained in:
ggurdin 2025-03-07 10:30:39 -05:00 committed by GitHub
parent 6914d9d0d7
commit ab3e1266e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 11 additions and 11 deletions

View file

@ -144,6 +144,13 @@ class GetAnalyticsController extends BaseController {
if (oldLevel < constructListModel.level) _onLevelUp();
if (oldLevel > constructListModel.level) await _onLevelDown(oldLevel);
_updateAnalyticsStream(origin: analyticsUpdate.origin);
// Update public profile each time that new analytics are added.
// If the level hasn't changed, this will not send an update to the server.
// Do this on all updates (not just on level updates) to account for cases
// of target language updates being missed (https://github.com/pangeachat/client/issues/2006)
_pangeaController.userController.updatePublicProfile(
level: constructListModel.level,
);
}
void _updateAnalyticsStream({
@ -152,10 +159,6 @@ class GetAnalyticsController extends BaseController {
analyticsStream.add(AnalyticsStreamUpdate(origin: origin));
void _onLevelUp() {
_pangeaController.userController.updatePublicProfile(
level: constructListModel.level,
);
setState({'level_up': constructListModel.level});
}

View file

@ -60,7 +60,7 @@ class LevelDisplayNameState extends State<LevelDisplayName> {
children: [
if (_profile?.targetLanguage != null)
Text(
_profile!.targetLanguage!.langCode.toUpperCase(),
_profile!.targetLanguage!.langCodeShort.toUpperCase(),
style: TextStyle(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.primary,

View file

@ -178,8 +178,8 @@ class UserController extends BaseController {
}
Future<void> updatePublicProfile({
required int level,
LanguageModel? targetLanguage,
int? level,
}) async {
targetLanguage ??= _pangeaController.languageController.userL2;
if (targetLanguage == null || publicProfile == null) return;
@ -190,10 +190,7 @@ class UserController extends BaseController {
}
publicProfile!.targetLanguage = targetLanguage;
if (level != null) {
publicProfile!.setLevel(targetLanguage, level);
}
publicProfile!.setLevel(targetLanguage, level);
await _savePublicProfile();
}

View file

@ -43,7 +43,7 @@ class PublicProfileModel {
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
if (targetLanguage != null) {
json[ModelKey.userTargetLanguage] = targetLanguage!.langCode;
json[ModelKey.userTargetLanguage] = targetLanguage!.langCodeShort;
}
final analytics = {};