fix: In lemma definition request, use lemma.form if no lemma.text and log error to sentry (#1376)
This commit is contained in:
parent
350c9e6840
commit
7b1cccf78b
5 changed files with 22 additions and 13 deletions
|
|
@ -524,7 +524,7 @@ class PangeaToken {
|
|||
|
||||
Future<List<String>> getEmojiChoices() => LemmaDictionaryRepo.get(
|
||||
LemmaDefinitionRequest(
|
||||
lemma: lemma.text,
|
||||
lemma: lemma,
|
||||
partOfSpeech: pos,
|
||||
lemmaLang: MatrixState
|
||||
.pangeaController.languageController.userL2?.langCode ??
|
||||
|
|
|
|||
|
|
@ -2,31 +2,40 @@ import 'dart:convert';
|
|||
|
||||
import 'package:http/http.dart';
|
||||
|
||||
import 'package:fluffychat/pangea/models/lemma.dart';
|
||||
import 'package:fluffychat/pangea/network/urls.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import '../config/environment.dart';
|
||||
import '../network/requests.dart';
|
||||
|
||||
class LemmaDefinitionRequest {
|
||||
final String lemma;
|
||||
final Lemma _lemma;
|
||||
final String partOfSpeech;
|
||||
final String lemmaLang;
|
||||
final String userL1;
|
||||
|
||||
LemmaDefinitionRequest({
|
||||
required this.lemma,
|
||||
required this.partOfSpeech,
|
||||
required this.lemmaLang,
|
||||
required this.userL1,
|
||||
});
|
||||
required Lemma lemma,
|
||||
}) : _lemma = lemma;
|
||||
|
||||
factory LemmaDefinitionRequest.fromJson(Map<String, dynamic> json) {
|
||||
return LemmaDefinitionRequest(
|
||||
lemma: json['lemma'] as String,
|
||||
partOfSpeech: json['part_of_speech'] as String,
|
||||
lemmaLang: json['lemma_lang'] as String,
|
||||
userL1: json['user_l1'] as String,
|
||||
String get lemma {
|
||||
if (_lemma.text.isNotEmpty) {
|
||||
return _lemma.text;
|
||||
}
|
||||
ErrorHandler.logError(
|
||||
e: "Found lemma with empty text",
|
||||
data: {
|
||||
'lemma': _lemma,
|
||||
'part_of_speech': partOfSpeech,
|
||||
'lemma_lang': lemmaLang,
|
||||
'user_l1': userL1,
|
||||
},
|
||||
);
|
||||
return _lemma.form;
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class WordMeaningActivityGenerator {
|
|||
);
|
||||
|
||||
final LemmaDefinitionRequest lemmaDefReq = LemmaDefinitionRequest(
|
||||
lemma: lemmaId.lemma,
|
||||
lemma: req.targetTokens[0].lemma,
|
||||
partOfSpeech: lemmaId.category,
|
||||
|
||||
/// This assumes that the user's L2 is the language of the lemma
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class ContextualTranslationWidget extends StatelessWidget {
|
|||
|
||||
Future<String> _fetchDefinition() async {
|
||||
final LemmaDefinitionRequest lemmaDefReq = LemmaDefinitionRequest(
|
||||
lemma: token.lemma.text,
|
||||
lemma: token.lemma,
|
||||
partOfSpeech: token.pos,
|
||||
|
||||
/// This assumes that the user's L2 is the language of the lemma
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class LemmaDefinitionWidgetState extends State<LemmaDefinitionWidget> {
|
|||
} else {
|
||||
final res = await LemmaDictionaryRepo.get(
|
||||
LemmaDefinitionRequest(
|
||||
lemma: widget.token.lemma.text,
|
||||
lemma: widget.token.lemma,
|
||||
partOfSpeech: widget.token.pos,
|
||||
lemmaLang: widget.tokenLang,
|
||||
userL1: MatrixState
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue