clean up models
This commit is contained in:
parent
0db2c70ef4
commit
749517fafb
17 changed files with 44 additions and 135 deletions
|
|
@ -40,10 +40,10 @@ import 'package:fluffychat/pangea/bot/utils/bot_name.dart';
|
|||
import 'package:fluffychat/pangea/chat/utils/unlocked_morphs_snackbar.dart';
|
||||
import 'package:fluffychat/pangea/chat/widgets/event_too_large_dialog.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/controllers/choreographer.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/controllers/pangea_text_controller.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/enums/edit_type.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/models/choreo_record.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/repo/language_mismatch_repo.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/utils/pangea_text_controller.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/widgets/igc/language_mismatch_popup.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/widgets/igc/message_analytics_feedback.dart';
|
||||
import 'package:fluffychat/pangea/common/constants/model_keys.dart';
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import 'package:matrix/matrix.dart';
|
|||
import 'package:slugify/slugify.dart';
|
||||
|
||||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/utils/pangea_text_controller.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/controllers/pangea_text_controller.dart';
|
||||
import 'package:fluffychat/pangea/toolbar/utils/shrinkable_text.dart';
|
||||
import 'package:fluffychat/utils/markdown_context_builder.dart';
|
||||
import 'package:fluffychat/widgets/mxc_image.dart';
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import 'package:sentry_flutter/sentry_flutter.dart';
|
|||
|
||||
import 'package:fluffychat/pages/chat/chat.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/controllers/igc_controller.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/controllers/pangea_text_controller.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/enums/assistance_state_enum.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/enums/edit_type.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/enums/pangea_match_status.dart';
|
||||
|
|
@ -15,7 +16,6 @@ import 'package:fluffychat/pangea/choreographer/models/choreo_record.dart';
|
|||
import 'package:fluffychat/pangea/choreographer/models/it_step.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/models/pangea_match_state.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/utils/input_paste_listener.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/utils/pangea_text_controller.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/widgets/igc/paywall_card.dart';
|
||||
import 'package:fluffychat/pangea/common/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/common/utils/any_state_holder.dart';
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ import 'package:fluffychat/pangea/choreographer/widgets/igc/span_card.dart';
|
|||
import 'package:fluffychat/pangea/subscription/controllers/subscription_controller.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import '../../common/utils/overlay.dart';
|
||||
import '../controllers/choreographer.dart';
|
||||
import '../enums/edit_type.dart';
|
||||
import 'choreographer.dart';
|
||||
|
||||
class PangeaTextController extends TextEditingController {
|
||||
Choreographer choreographer;
|
||||
|
|
@ -139,7 +139,6 @@ class ChoreoRecord {
|
|||
static const _stepsKey = "stps";
|
||||
static const _openMatchesKey = "mtchs";
|
||||
static const _originalTextKey = "ogtxt_v2";
|
||||
// static const _currentKey = "crnt";
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
|
|
@ -147,27 +146,23 @@ class ChoreoRecord {
|
|||
data[_openMatchesKey] =
|
||||
jsonEncode(openMatches.map((e) => e.toJson()).toList());
|
||||
data[_originalTextKey] = originalText;
|
||||
// data[_currentKey] = current;
|
||||
return data;
|
||||
}
|
||||
|
||||
void addRecord(String text, {PangeaMatch? match, ITStep? step}) {
|
||||
if (match != null && step != null) {
|
||||
throw Exception("match and step should not both be defined");
|
||||
}
|
||||
bool get includedIT => choreoSteps.any((step) {
|
||||
return step.acceptedOrIgnoredMatch?.status ==
|
||||
PangeaMatchStatus.accepted &&
|
||||
(step.acceptedOrIgnoredMatch?.isOutOfTargetMatch ?? false);
|
||||
});
|
||||
|
||||
final edit = ChoreoEdit.fromText(
|
||||
originalText: stepText(),
|
||||
editedText: text,
|
||||
);
|
||||
bool get includedIGC => choreoSteps.any((step) {
|
||||
return step.acceptedOrIgnoredMatch?.status ==
|
||||
PangeaMatchStatus.accepted &&
|
||||
(step.acceptedOrIgnoredMatch?.isGrammarMatch ?? false);
|
||||
});
|
||||
|
||||
choreoSteps.add(
|
||||
ChoreoRecordStep(
|
||||
edits: edit,
|
||||
acceptedOrIgnoredMatch: match,
|
||||
itStep: step,
|
||||
),
|
||||
);
|
||||
bool endedWithIT(String sent) {
|
||||
return includedIT && stepText() == sent;
|
||||
}
|
||||
|
||||
/// Get the text at [stepIndex]
|
||||
|
|
@ -195,40 +190,23 @@ class ChoreoRecord {
|
|||
return text;
|
||||
}
|
||||
|
||||
bool get hasAcceptedMatches => choreoSteps.any(
|
||||
(element) =>
|
||||
element.acceptedOrIgnoredMatch?.status ==
|
||||
PangeaMatchStatus.accepted,
|
||||
);
|
||||
void addRecord(String text, {PangeaMatch? match, ITStep? step}) {
|
||||
if (match != null && step != null) {
|
||||
throw Exception("match and step should not both be defined");
|
||||
}
|
||||
|
||||
bool get hasIgnoredMatches => choreoSteps.any(
|
||||
(element) =>
|
||||
element.acceptedOrIgnoredMatch?.status == PangeaMatchStatus.ignored,
|
||||
);
|
||||
final edit = ChoreoEdit.fromText(
|
||||
originalText: stepText(),
|
||||
editedText: text,
|
||||
);
|
||||
|
||||
// bool get includedIT => choreoSteps.any((step) {
|
||||
// return step.acceptedOrIgnoredMatch?.status ==
|
||||
// PangeaMatchStatus.accepted &&
|
||||
// (step.acceptedOrIgnoredMatch?.isITStart ?? false);
|
||||
// });
|
||||
|
||||
bool get includedIT => choreoSteps.any((step) {
|
||||
return step.acceptedOrIgnoredMatch?.status ==
|
||||
PangeaMatchStatus.accepted &&
|
||||
(step.acceptedOrIgnoredMatch?.isOutOfTargetMatch ?? false);
|
||||
});
|
||||
|
||||
bool get includedIGC => choreoSteps.any((step) {
|
||||
return step.acceptedOrIgnoredMatch?.status ==
|
||||
PangeaMatchStatus.accepted &&
|
||||
(step.acceptedOrIgnoredMatch?.isGrammarMatch ?? false);
|
||||
});
|
||||
|
||||
List<ITStep> get itSteps =>
|
||||
choreoSteps.where((e) => e.itStep != null).map((e) => e.itStep!).toList();
|
||||
|
||||
bool endedWithIT(String sent) {
|
||||
return includedIT && stepText() == sent;
|
||||
choreoSteps.add(
|
||||
ChoreoRecordStep(
|
||||
edits: edit,
|
||||
acceptedOrIgnoredMatch: match,
|
||||
itStep: step,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,32 +22,6 @@ class ITStep {
|
|||
}
|
||||
}
|
||||
|
||||
Continuance? get chosenContinuance {
|
||||
if (chosen == null) return null;
|
||||
return continuances[chosen!];
|
||||
}
|
||||
|
||||
String choiceFeedback(BuildContext context) {
|
||||
if (continuances.length == 1) return '';
|
||||
return chosenContinuance?.feedbackText(context) ?? "";
|
||||
}
|
||||
|
||||
bool get isCorrect =>
|
||||
chosenContinuance != null &&
|
||||
(chosenContinuance!.level == ChoreoConstants.levelThresholdForGreen ||
|
||||
chosenContinuance!.gold);
|
||||
|
||||
bool get isYellow =>
|
||||
chosenContinuance != null &&
|
||||
chosenContinuance!.level == ChoreoConstants.levelThresholdForYellow;
|
||||
|
||||
bool get isWrong {
|
||||
return chosenContinuance != null &&
|
||||
chosenContinuance!.level == ChoreoConstants.levelThresholdForRed;
|
||||
}
|
||||
|
||||
bool get isCustom => chosenContinuance == null;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
data['continuances'] = continuances.map((e) => e.toJson(true)).toList();
|
||||
|
|
@ -67,6 +41,11 @@ class ITStep {
|
|||
customInput: json['custom_input'],
|
||||
);
|
||||
}
|
||||
|
||||
Continuance? get chosenContinuance {
|
||||
if (chosen == null) return null;
|
||||
return continuances[chosen!];
|
||||
}
|
||||
}
|
||||
|
||||
class Continuance {
|
||||
|
|
@ -113,7 +92,6 @@ class Continuance {
|
|||
data['level'] = level;
|
||||
data['text'] = text;
|
||||
data['clkd'] = wasClicked;
|
||||
// data[ModelKey.tokens] = tokens.map((e) => e.toJson()).toList();
|
||||
|
||||
if (!condensed) {
|
||||
data['description'] = description;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'package:fluffychat/pangea/choreographer/enums/pangea_match_status.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/enums/span_data_type.dart';
|
||||
import 'package:fluffychat/pangea/common/utils/error_handler.dart';
|
||||
import '../constants/match_rule_ids.dart';
|
||||
import 'span_data.dart';
|
||||
|
||||
|
|
@ -39,40 +34,17 @@ class PangeaMatch {
|
|||
[SpanDataTypeEnum.itStart, SpanDataTypeEnum.itStart.name]
|
||||
.contains(match.type.typeName);
|
||||
|
||||
bool get needsTranslation => match.rule?.id != null
|
||||
bool get _needsTranslation => match.rule?.id != null
|
||||
? [
|
||||
MatchRuleIds.tokenNeedsTranslation,
|
||||
MatchRuleIds.tokenSpanNeedsTranslation,
|
||||
].contains(match.rule!.id)
|
||||
: false;
|
||||
|
||||
bool get isOutOfTargetMatch => isITStart || needsTranslation;
|
||||
bool get isOutOfTargetMatch => isITStart || _needsTranslation;
|
||||
|
||||
bool get isGrammarMatch => !isOutOfTargetMatch;
|
||||
|
||||
String get matchContent {
|
||||
late int beginning;
|
||||
late int end;
|
||||
if (match.offset < 0) {
|
||||
beginning = 0;
|
||||
debugger(when: kDebugMode);
|
||||
ErrorHandler.logError(m: "match.offset < 0", data: match.toJson());
|
||||
} else {
|
||||
beginning = match.offset;
|
||||
}
|
||||
if (match.offset + match.length > match.fullText.length) {
|
||||
end = match.fullText.length;
|
||||
debugger(when: kDebugMode);
|
||||
ErrorHandler.logError(
|
||||
m: "match.offset + match.length > match.fullText.length",
|
||||
data: match.toJson(),
|
||||
);
|
||||
} else {
|
||||
end = match.offset + match.length;
|
||||
}
|
||||
return match.fullText.substring(beginning, end);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,3 @@
|
|||
//Possible actions/effects from cards
|
||||
// Nothing
|
||||
// useType of viewed definitions
|
||||
// SpanChoice of text in message from options
|
||||
// Call to server for additional/followup info
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
|
|
@ -246,8 +240,6 @@ class SpanChoice {
|
|||
return feedback!;
|
||||
}
|
||||
|
||||
bool get isDistractor => type == SpanChoiceType.distractor;
|
||||
|
||||
bool get isBestCorrection => type == SpanChoiceType.bestCorrection;
|
||||
|
||||
Color get color => type.color;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:fluffychat/pangea/choreographer/controllers/pangea_text_controller.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/enums/edit_type.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/utils/pangea_text_controller.dart';
|
||||
|
||||
class InputPasteListener {
|
||||
final PangeaTextController controller;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ class ChoicesArray extends StatefulWidget {
|
|||
final ChoiceCallback onPressed;
|
||||
final ChoiceCallback? onLongPress;
|
||||
final int? selectedChoiceIndex;
|
||||
final String originalSpan;
|
||||
|
||||
final bool enableAudio;
|
||||
|
||||
|
|
@ -56,7 +55,6 @@ class ChoicesArray extends StatefulWidget {
|
|||
required this.isLoading,
|
||||
required this.choices,
|
||||
required this.onPressed,
|
||||
required this.originalSpan,
|
||||
required this.selectedChoiceIndex,
|
||||
this.enableAudio = true,
|
||||
this.langCode,
|
||||
|
|
@ -132,7 +130,6 @@ class ChoicesArrayState extends State<ChoicesArray> {
|
|||
return widget.isLoading &&
|
||||
(widget.choices == null || widget.choices!.length <= 1)
|
||||
? ItShimmer(
|
||||
originalSpan: widget.originalSpan,
|
||||
fontSize: widget.fontSize ??
|
||||
Theme.of(context).textTheme.bodyMedium?.fontSize ??
|
||||
16,
|
||||
|
|
|
|||
|
|
@ -150,8 +150,6 @@ class WordMatchContent extends StatelessWidget {
|
|||
children: [
|
||||
const SizedBox(height: 8),
|
||||
ChoicesArray(
|
||||
originalSpan:
|
||||
controller.widget.match.updatedMatch.matchContent,
|
||||
isLoading: controller.fetchingData,
|
||||
choices:
|
||||
controller.widget.match.updatedMatch.match.choices
|
||||
|
|
|
|||
|
|
@ -368,8 +368,6 @@ class ITChoices extends StatelessWidget {
|
|||
isLoading: controller.isLoading ||
|
||||
controller.choreographer.isFetching ||
|
||||
controller.currentITStep == null,
|
||||
//TODO - pass current span being translated
|
||||
originalSpan: "dummy",
|
||||
choices: controller.currentITStep!.continuances.map((e) {
|
||||
try {
|
||||
return Choice(
|
||||
|
|
|
|||
|
|
@ -5,11 +5,9 @@ import 'package:flutter/material.dart';
|
|||
class ItShimmer extends StatelessWidget {
|
||||
const ItShimmer({
|
||||
super.key,
|
||||
required this.originalSpan,
|
||||
required this.fontSize,
|
||||
});
|
||||
|
||||
final String originalSpan;
|
||||
final double fontSize;
|
||||
|
||||
Iterable<Widget> renderShimmerIfListEmpty(
|
||||
|
|
@ -18,7 +16,7 @@ class ItShimmer extends StatelessWidget {
|
|||
}) {
|
||||
final List<String> dummyStrings = [];
|
||||
for (int i = 0; i < noOfBars; i++) {
|
||||
dummyStrings.add(originalSpan);
|
||||
dummyStrings.add(" " * 10);
|
||||
}
|
||||
return dummyStrings.map(
|
||||
(e) => ITShimmerElement(
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import 'package:matrix/matrix.dart';
|
|||
|
||||
import 'package:fluffychat/pangea/common/utils/error_handler.dart';
|
||||
import 'package:fluffychat/pangea/events/extensions/pangea_event_extension.dart';
|
||||
import '../../events/constants/pangea_event_types.dart';
|
||||
import '../models/choreo_record.dart';
|
||||
import '../../choreographer/models/choreo_record.dart';
|
||||
import '../constants/pangea_event_types.dart';
|
||||
|
||||
class ChoreoEvent {
|
||||
Event event;
|
||||
|
|
@ -10,12 +10,12 @@ import 'package:matrix/src/utils/markdown.dart';
|
|||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
import 'package:fluffychat/pangea/analytics_misc/constructs_model.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/event_wrappers/pangea_choreo_event.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/models/choreo_record.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/models/language_detection_model.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/repo/full_text_translation_request_model.dart';
|
||||
import 'package:fluffychat/pangea/common/utils/error_handler.dart';
|
||||
import 'package:fluffychat/pangea/events/constants/pangea_event_types.dart';
|
||||
import 'package:fluffychat/pangea/events/event_wrappers/pangea_choreo_event.dart';
|
||||
import 'package:fluffychat/pangea/events/extensions/pangea_event_extension.dart';
|
||||
import 'package:fluffychat/pangea/events/models/pangea_token_model.dart';
|
||||
import 'package:fluffychat/pangea/events/models/representation_content_model.dart';
|
||||
|
|
|
|||
|
|
@ -132,8 +132,7 @@ class PangeaRepresentation {
|
|||
.toList();
|
||||
}
|
||||
|
||||
if (choreo == null ||
|
||||
(choreo.choreoSteps.isEmpty && choreo.itSteps.isEmpty)) {
|
||||
if (choreo == null || choreo.choreoSteps.isEmpty) {
|
||||
for (final token in tokensToSave) {
|
||||
uses.addAll(
|
||||
token.allUses(
|
||||
|
|
|
|||
|
|
@ -234,7 +234,6 @@ class MultipleChoiceActivityState extends State<MultipleChoiceActivity> {
|
|||
),
|
||||
ChoicesArray(
|
||||
isLoading: false,
|
||||
originalSpan: "placeholder",
|
||||
onPressed: updateChoice,
|
||||
selectedChoiceIndex: selectedChoiceIndex,
|
||||
choices: choices(context),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue