Merge pull request #5091 from pangeachat/5082-can-collect-words-in-other-l2s-via-activity-lemmas

fix: disable new token collection for token not in L2
This commit is contained in:
ggurdin 2026-01-06 15:10:18 -05:00 committed by GitHub
commit 4c23bbaf92
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 40 additions and 13 deletions

View file

@ -154,6 +154,8 @@ class ActivityStatsMenu extends StatelessWidget {
langCode: controller.room.activityPlan!.req.targetLanguage,
targetId: "activity-vocab",
usedVocab: controller.activityController.usedVocab,
activityLangCode:
controller.room.activityPlan!.req.targetLanguage,
),
),
],

View file

@ -17,6 +17,7 @@ class ActivityVocabWidget extends StatelessWidget {
final List<Vocab> vocab;
final String langCode;
final String targetId;
final String activityLangCode;
final ValueNotifier<Set<String>>? usedVocab;
const ActivityVocabWidget({
@ -24,6 +25,7 @@ class ActivityVocabWidget extends StatelessWidget {
required this.vocab,
required this.langCode,
required this.targetId,
required this.activityLangCode,
this.usedVocab,
});
@ -35,6 +37,7 @@ class ActivityVocabWidget extends StatelessWidget {
targetId: targetId,
langCode: langCode,
usedVocab: const {},
activityLangCode: activityLangCode,
);
}
@ -45,6 +48,7 @@ class ActivityVocabWidget extends StatelessWidget {
targetId: targetId,
langCode: langCode,
usedVocab: used,
activityLangCode: activityLangCode,
),
);
}
@ -54,12 +58,14 @@ class _VocabChips extends StatefulWidget {
final List<Vocab> vocab;
final String targetId;
final String langCode;
final String activityLangCode;
final Set<String> usedVocab;
const _VocabChips({
required this.vocab,
required this.targetId,
required this.langCode,
required this.activityLangCode,
required this.usedVocab,
});
@ -132,7 +138,11 @@ class _VocabChipsState extends State<_VocabChips> with TokenRenderingMixin {
@override
Widget build(BuildContext context) {
final tokens = widget.vocab.map((v) => v.asToken()).toList();
final newTokens = TokensUtil.getNewTokens("activity_tokens", tokens);
final newTokens = TokensUtil.getNewTokens(
"activity_tokens",
tokens,
widget.activityLangCode,
);
final renderer = TokenRenderingUtil(
existingStyle: TextStyle(
color: Theme.of(context).colorScheme.onSurface,

View file

@ -190,6 +190,7 @@ class ActivitySummary extends StatelessWidget {
langCode: activity.req.targetLanguage,
targetId: "activity-summary-vocab",
usedVocab: usedVocab,
activityLangCode: activity.req.targetLanguage,
),
),
],

View file

@ -42,7 +42,12 @@ class SttTranscriptTokens extends StatelessWidget {
existingStyle: (style ?? DefaultTextStyle.of(context).style),
);
final newTokens = TokensUtil.getNewTokens(eventId, tokens);
final newTokens = TokensUtil.getNewTokens(
eventId,
tokens,
model.langCode,
);
return RichText(
textScaler: TextScaler.noScaling,
text: TextSpan(

View file

@ -74,7 +74,8 @@ class TokensUtil {
static List<PangeaTokenText> getNewTokens(
String cacheKey,
List<PangeaToken> tokens, {
List<PangeaToken> tokens,
String tokensLangCode, {
int? maxTokens,
}) {
if (MatrixState
@ -82,8 +83,19 @@ class TokensUtil {
return [];
}
final messageInUserL2 = tokensLangCode.split('-').first ==
MatrixState.pangeaController.userController.userL2?.langCodeShort;
final cached = _getCachedNewTokens(cacheKey);
if (cached != null) return cached;
if (cached != null) {
if (!messageInUserL2) {
_newTokenCache.remove(cacheKey);
return [];
}
return cached;
}
if (!messageInUserL2) return [];
final List<PangeaTokenText> newTokens = [];
final analyticsService =
@ -136,15 +148,12 @@ class TokensUtil {
return [];
}
return getNewTokens(event.eventId, tokens, maxTokens: 3);
}
static bool isNewToken(
String cacheKey,
PangeaToken token,
) {
final newTokens = getNewTokens(cacheKey, [token]);
return newTokens.any((t) => t == token.text);
return getNewTokens(
event.eventId,
tokens,
event.messageDisplayLangCode,
maxTokens: 3,
);
}
static bool isNewTokenByEvent(PangeaToken token, PangeaMessageEvent event) {