commit
3a39a1aa85
6 changed files with 26 additions and 30 deletions
|
|
@ -17,7 +17,6 @@ import 'package:fluffychat/pangea/models/tokens_event_content_model.dart';
|
|||
import 'package:fluffychat/pangea/repo/full_text_translation_repo.dart';
|
||||
import 'package:fluffychat/pangea/widgets/chat/message_audio_card.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
|
|
@ -83,7 +82,6 @@ class PangeaMessageEvent {
|
|||
|
||||
Future<PangeaAudioFile?> getMatrixAudioFile(
|
||||
String langCode,
|
||||
BuildContext context,
|
||||
) async {
|
||||
final RepresentationEvent? rep = representationByLanguage(langCode);
|
||||
|
||||
|
|
@ -91,7 +89,12 @@ class PangeaMessageEvent {
|
|||
|
||||
final TextToSpeechRequest params = TextToSpeechRequest(
|
||||
text: rep.content.text,
|
||||
tokens: (await rep.tokensGlobal(context)).map((t) => t.text).toList(),
|
||||
tokens: (await rep.tokensGlobal(
|
||||
senderId,
|
||||
originServerTs,
|
||||
))
|
||||
.map((t) => t.text)
|
||||
.toList(),
|
||||
langCode: langCode,
|
||||
userL1: l1Code ?? LanguageKeys.unknownLanguage,
|
||||
userL2: l2Code ?? LanguageKeys.unknownLanguage,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import 'package:fluffychat/pangea/models/pangea_token_model.dart';
|
|||
import 'package:fluffychat/pangea/models/token_api_models.dart';
|
||||
import 'package:fluffychat/pangea/models/tokens_event_content_model.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:matrix/src/utils/markdown.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
|
@ -118,16 +117,21 @@ class RepresentationEvent {
|
|||
return _tokens?.tokens;
|
||||
}
|
||||
|
||||
Future<List<PangeaToken>> tokensGlobal(BuildContext context) async {
|
||||
Future<List<PangeaToken>> tokensGlobal(
|
||||
String senderID,
|
||||
DateTime timestamp,
|
||||
) async {
|
||||
if (tokens != null) return tokens!;
|
||||
|
||||
if (_event == null) {
|
||||
if (_event == null && timestamp.isAfter(DateTime(2024, 9, 25))) {
|
||||
ErrorHandler.logError(
|
||||
m: 'representation with no _event and no tokens got tokens directly. This means an original_sent with no tokens. This should not happen in messages sent after September 25',
|
||||
s: StackTrace.current,
|
||||
data: {
|
||||
'content': content.toJson(),
|
||||
'event': _event?.toJson(),
|
||||
'timestamp': timestamp,
|
||||
'senderID': senderID,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,7 +158,6 @@ class MessageAudioCardState extends State<MessageAudioCard> {
|
|||
} else {
|
||||
audioFile = await widget.messageEvent.getMatrixAudioFile(
|
||||
langCode,
|
||||
context,
|
||||
);
|
||||
}
|
||||
debugPrint("audio file is now: $audioFile. setting starts and ends...");
|
||||
|
|
|
|||
|
|
@ -32,7 +32,10 @@ class OverlayMessageTextState extends State<OverlayMessageText> {
|
|||
tokens = widget.pangeaMessageEvent.originalSent?.tokens;
|
||||
if (widget.pangeaMessageEvent.originalSent != null && tokens == null) {
|
||||
widget.pangeaMessageEvent.originalSent!
|
||||
.tokensGlobal(context)
|
||||
.tokensGlobal(
|
||||
widget.pangeaMessageEvent.senderId,
|
||||
widget.pangeaMessageEvent.originServerTs,
|
||||
)
|
||||
.then((tokens) {
|
||||
// this isn't currently working because originalSent's _event is null
|
||||
setState(() => this.tokens = tokens);
|
||||
|
|
|
|||
|
|
@ -141,7 +141,6 @@ class PracticeActivityCardState extends State<PracticeActivityCard> {
|
|||
userL2: pangeaController.languageController.userL2!.langCode,
|
||||
messageText: widget.pangeaMessageEvent.originalSent!.text,
|
||||
tokensWithXP: await targetTokensController.targetTokens(
|
||||
context,
|
||||
widget.pangeaMessageEvent,
|
||||
),
|
||||
messageId: widget.pangeaMessageEvent.eventId,
|
||||
|
|
@ -218,7 +217,6 @@ class PracticeActivityCardState extends State<PracticeActivityCard> {
|
|||
currentActivity!,
|
||||
metadata,
|
||||
),
|
||||
context,
|
||||
widget.pangeaMessageEvent,
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,8 @@ import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_message_event.dar
|
|||
import 'package:fluffychat/pangea/models/analytics/construct_list_model.dart';
|
||||
import 'package:fluffychat/pangea/models/analytics/constructs_model.dart';
|
||||
import 'package:fluffychat/pangea/models/practice_activities.dart/message_activity_request.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Seperated out the target tokens from the practice activity card
|
||||
/// in order to control the state of the target tokens
|
||||
|
|
@ -19,20 +17,18 @@ class TargetTokensController {
|
|||
/// From the tokens in the message, do a preliminary filtering of which to target
|
||||
/// Then get the construct uses for those tokens
|
||||
Future<List<TokenWithXP>> targetTokens(
|
||||
BuildContext context,
|
||||
PangeaMessageEvent pangeaMessageEvent,
|
||||
) async {
|
||||
if (_targetTokens != null) {
|
||||
return _targetTokens!;
|
||||
}
|
||||
|
||||
_targetTokens = await _initialize(context, pangeaMessageEvent);
|
||||
_targetTokens = await _initialize(pangeaMessageEvent);
|
||||
|
||||
final allConstructs = MatrixState
|
||||
.pangeaController.analytics.analyticsStream.value?.constructs;
|
||||
await updateTokensWithConstructs(
|
||||
MatrixState
|
||||
.pangeaController.analytics.analyticsStream.value?.constructs ??
|
||||
[],
|
||||
context,
|
||||
allConstructs ?? [],
|
||||
pangeaMessageEvent,
|
||||
);
|
||||
|
||||
|
|
@ -40,20 +36,14 @@ class TargetTokensController {
|
|||
}
|
||||
|
||||
Future<List<TokenWithXP>> _initialize(
|
||||
BuildContext context,
|
||||
PangeaMessageEvent pangeaMessageEvent,
|
||||
) async {
|
||||
if (!context.mounted) {
|
||||
ErrorHandler.logError(
|
||||
m: 'getTargetTokens called when not mounted',
|
||||
s: StackTrace.current,
|
||||
);
|
||||
return _targetTokens = [];
|
||||
}
|
||||
|
||||
final tokens = await pangeaMessageEvent
|
||||
.representationByLanguage(pangeaMessageEvent.messageDisplayLangCode)
|
||||
?.tokensGlobal(context);
|
||||
?.tokensGlobal(
|
||||
pangeaMessageEvent.senderId,
|
||||
pangeaMessageEvent.originServerTs,
|
||||
);
|
||||
|
||||
if (tokens == null || tokens.isEmpty) {
|
||||
debugger(when: kDebugMode);
|
||||
|
|
@ -66,7 +56,6 @@ class TargetTokensController {
|
|||
|
||||
Future<void> updateTokensWithConstructs(
|
||||
List<OneConstructUse> constructUses,
|
||||
context,
|
||||
pangeaMessageEvent,
|
||||
) async {
|
||||
final ConstructListModel constructList = ConstructListModel(
|
||||
|
|
@ -74,7 +63,7 @@ class TargetTokensController {
|
|||
type: null,
|
||||
);
|
||||
|
||||
_targetTokens ??= await _initialize(context, pangeaMessageEvent);
|
||||
_targetTokens ??= await _initialize(pangeaMessageEvent);
|
||||
|
||||
for (final token in _targetTokens!) {
|
||||
// we don't need to do this for tokens that don't have saveVocab set to true
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue