chore: react to new token selection when token is initally selected (#3358)

pull/2245/head
ggurdin 4 months ago committed by GitHub
parent 8dc1df1fef
commit 41830f2f2d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -121,13 +121,6 @@ class MessageOverlayController extends State<MessageSelectionOverlay>
WidgetsBinding.instance.addPostFrameCallback( WidgetsBinding.instance.addPostFrameCallback(
(_) => widget.chatController.setSelectedEvent(event), (_) => widget.chatController.setSelectedEvent(event),
); );
newTokens = pangeaMessageEvent?.messageDisplayRepresentation?.tokens
?.where((token) {
return token.lemma.saveVocab == true &&
token.vocabConstruct.uses.isEmpty &&
messageInUserL2;
}).toList() ??
[];
} }
@override @override
@ -173,6 +166,14 @@ class MessageOverlayController extends State<MessageSelectionOverlay>
.map((token) => token.getLemmaInfo()) .map((token) => token.getLemmaInfo())
.toList(); .toList();
newTokens = pangeaMessageEvent?.messageDisplayRepresentation?.tokens
?.where((token) {
return token.lemma.saveVocab == true &&
token.vocabConstruct.uses.isEmpty &&
messageInUserL2;
}).toList() ??
[];
Future.wait(lemmaInfoFutures).then((resp) { Future.wait(lemmaInfoFutures).then((resp) {
if (mounted) { if (mounted) {
setState( setState(
@ -309,9 +310,9 @@ class MessageOverlayController extends State<MessageSelectionOverlay>
} }
if (mounted) setState(() {}); if (mounted) setState(() {});
// Future.delayed(const Duration(milliseconds: 10), () { if (selectedToken != null && isNewToken(selectedToken!)) {
// _showReadingAssistanceContent(); _onSelectNewToken(selectedToken!);
// }); }
} }
void _showReadingAssistanceContent() { void _showReadingAssistanceContent() {
@ -570,44 +571,45 @@ class MessageOverlayController extends State<MessageSelectionOverlay>
} }
updateSelectedSpan(token.text); updateSelectedSpan(token.text);
}
if (isNewToken(token)) { void _onSelectNewToken(PangeaToken token) {
Future.delayed(const Duration(milliseconds: 1700), () { if (!isNewToken(token)) return;
MatrixState.pangeaController.putAnalytics.setState( Future.delayed(const Duration(milliseconds: 1700), () {
AnalyticsStream( MatrixState.pangeaController.putAnalytics.setState(
eventId: event.eventId, AnalyticsStream(
roomId: event.room.id, eventId: event.eventId,
constructs: [ roomId: event.room.id,
OneConstructUse( constructs: [
useType: ConstructUseTypeEnum.click, OneConstructUse(
lemma: token.lemma.text, useType: ConstructUseTypeEnum.click,
constructType: ConstructTypeEnum.vocab, lemma: token.lemma.text,
metadata: ConstructUseMetaData( constructType: ConstructTypeEnum.vocab,
roomId: event.room.id, metadata: ConstructUseMetaData(
timeStamp: DateTime.now(), roomId: event.room.id,
eventId: event.eventId, timeStamp: DateTime.now(),
), eventId: event.eventId,
category: token.pos,
form: token.text.content,
xp: ConstructUseTypeEnum.click.pointValue,
), ),
], category: token.pos,
targetID: token.text.uniqueKey, form: token.text.content,
), xp: ConstructUseTypeEnum.click.pointValue,
); ),
],
targetID: token.text.uniqueKey,
),
);
if (mounted) { if (mounted) {
setState(() { setState(() {
newTokens.removeWhere( newTokens.removeWhere(
(t) => (t) =>
t.text.offset == token.text.offset && t.text.offset == token.text.offset &&
t.text.length == token.text.length && t.text.length == token.text.length &&
t.lemma.text.equals(token.lemma.text), t.lemma.text.equals(token.lemma.text),
); );
}); });
} }
}); });
}
} }
PracticeTarget? practiceTargetForToken(PangeaToken token) { PracticeTarget? practiceTargetForToken(PangeaToken token) {

Loading…
Cancel
Save