move logic for showing the first available match into chat controller
This commit is contained in:
parent
26c8728114
commit
08f393199b
6 changed files with 40 additions and 96 deletions
|
|
@ -46,6 +46,7 @@ import 'package:fluffychat/pangea/choreographer/controllers/extensions/choreogra
|
|||
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/models/pangea_match_state.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/repo/language_mismatch_repo.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/widgets/igc/language_mismatch_popup.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/widgets/igc/message_analytics_feedback.dart';
|
||||
|
|
@ -2207,6 +2208,22 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
l1 != activityLang;
|
||||
}
|
||||
|
||||
void onSelectMatch(PangeaMatchState? match) {
|
||||
if (match != null) {
|
||||
if (match.updatedMatch.isITStart) {
|
||||
choreographer.openIT(match);
|
||||
} else {
|
||||
OverlayUtil.showIGCMatch(
|
||||
match,
|
||||
choreographer,
|
||||
context,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
inputFocus.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> showLanguageMismatchPopup() async {
|
||||
if (!shouldShowLanguageMismatchPopup) {
|
||||
return;
|
||||
|
|
@ -2226,19 +2243,10 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
waitForDataInSync: true,
|
||||
);
|
||||
|
||||
await choreographer.requestLanguageAssistance();
|
||||
final openMatch = choreographer.firstOpenMatch;
|
||||
if (openMatch != null) {
|
||||
if (openMatch.updatedMatch.isITStart) {
|
||||
choreographer.openIT(openMatch);
|
||||
} else {
|
||||
OverlayUtil.showIGCMatch(
|
||||
openMatch,
|
||||
choreographer,
|
||||
context,
|
||||
);
|
||||
}
|
||||
}
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
await choreographer.requestLanguageAssistance();
|
||||
onSelectMatch(choreographer.firstOpenMatch);
|
||||
});
|
||||
},
|
||||
),
|
||||
maxHeight: 325,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import 'package:fluffychat/pangea/choreographer/controllers/extensions/choreogra
|
|||
import 'package:fluffychat/pangea/choreographer/controllers/extensions/choreographer_ui_extension.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/controllers/pangea_text_controller.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/widgets/igc/paywall_card.dart';
|
||||
import 'package:fluffychat/pangea/common/utils/overlay.dart';
|
||||
import 'package:fluffychat/pangea/subscription/controllers/subscription_controller.dart';
|
||||
import 'package:fluffychat/pangea/toolbar/utils/shrinkable_text.dart';
|
||||
import 'package:fluffychat/utils/markdown_context_builder.dart';
|
||||
|
|
@ -449,13 +448,7 @@ class InputBar extends StatelessWidget {
|
|||
final match = choreographer.igcController.getMatchByOffset(
|
||||
selection.baseOffset,
|
||||
);
|
||||
if (match == null) return;
|
||||
|
||||
// if autoplay on and it start then just start it
|
||||
if (match.updatedMatch.isITStart) {
|
||||
return choreographer.openIT(match);
|
||||
}
|
||||
OverlayUtil.showIGCMatch(match, choreographer, context);
|
||||
choreographer.chatController.onSelectMatch(match);
|
||||
}
|
||||
// Pangea#
|
||||
|
||||
|
|
|
|||
|
|
@ -432,6 +432,7 @@ class Choreographer extends ChangeNotifier {
|
|||
);
|
||||
}
|
||||
MatrixState.pAnyState.closeOverlay();
|
||||
chatController.inputFocus.requestFocus();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
|
@ -446,10 +447,11 @@ class Choreographer extends ChangeNotifier {
|
|||
EditType.igc,
|
||||
);
|
||||
MatrixState.pAnyState.closeOverlay();
|
||||
chatController.inputFocus.requestFocus();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void onIgnoreMatch({required PangeaMatchState match}) {
|
||||
void onIgnoreReplacement({required PangeaMatchState match}) {
|
||||
final updatedMatch = igcController.ignoreReplacement(match);
|
||||
if (!updatedMatch.match.isNormalizationError()) {
|
||||
_initChoreoRecord();
|
||||
|
|
@ -459,6 +461,7 @@ class Choreographer extends ChangeNotifier {
|
|||
);
|
||||
}
|
||||
MatrixState.pAnyState.closeOverlay();
|
||||
chatController.inputFocus.requestFocus();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,8 +79,10 @@ class MessageAnalyticsFeedbackState extends State<MessageAnalyticsFeedback>
|
|||
_numbersController.forward,
|
||||
);
|
||||
Future.delayed(const Duration(milliseconds: 4000), () async {
|
||||
await _bubbleController.reverse();
|
||||
if (mounted) widget.close();
|
||||
if (mounted) {
|
||||
await _bubbleController.reverse();
|
||||
widget.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,14 +6,12 @@ import 'package:sentry_flutter/sentry_flutter.dart';
|
|||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/pangea/bot/utils/bot_style.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/controllers/choreographer.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/controllers/extensions/choreographer_state_extension.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/enums/span_choice_type.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/enums/span_data_type.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/models/pangea_match_state.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/models/span_data.dart';
|
||||
import 'package:fluffychat/pangea/common/utils/error_handler.dart';
|
||||
import 'package:fluffychat/pangea/common/utils/feedback_model.dart';
|
||||
import 'package:fluffychat/pangea/common/utils/overlay.dart';
|
||||
import 'package:fluffychat/pangea/common/widgets/error_indicator.dart';
|
||||
import '../../../../widgets/matrix.dart';
|
||||
import '../choice_array.dart';
|
||||
|
|
@ -153,19 +151,12 @@ class SpanCardState extends State<SpanCard> {
|
|||
});
|
||||
|
||||
void _onIgnoreMatch() => _onMatchUpdate(() {
|
||||
widget.choreographer.onIgnoreMatch(match: widget.match);
|
||||
widget.choreographer.onIgnoreReplacement(match: widget.match);
|
||||
});
|
||||
|
||||
void _showFirstMatch() {
|
||||
if (widget.choreographer.canShowFirstIGCMatch) {
|
||||
OverlayUtil.showIGCMatch(
|
||||
widget.choreographer.igcController.firstOpenMatch!,
|
||||
widget.choreographer,
|
||||
context,
|
||||
);
|
||||
} else {
|
||||
MatrixState.pAnyState.closeOverlay();
|
||||
}
|
||||
final match = widget.choreographer.igcController.firstOpenMatch;
|
||||
widget.choreographer.chatController.onSelectMatch(match);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
|||
|
|
@ -6,10 +6,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:fluffychat/config/themes.dart';
|
||||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/controllers/extensions/choreographer_state_extension.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/controllers/extensions/choreographer_ui_extension.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/enums/assistance_state_enum.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/widgets/igc/paywall_card.dart';
|
||||
import 'package:fluffychat/pangea/common/utils/overlay.dart';
|
||||
import 'package:fluffychat/pangea/learning_settings/pages/settings_learning.dart';
|
||||
import '../../../pages/chat/chat.dart';
|
||||
|
||||
|
|
@ -61,23 +58,6 @@ class StartIGCButtonState extends State<StartIGCButton>
|
|||
}
|
||||
}
|
||||
|
||||
void _showFirstMatch() {
|
||||
if (widget.controller.choreographer.canShowFirstIGCMatch) {
|
||||
final match =
|
||||
widget.controller.choreographer.igcController.firstOpenMatch;
|
||||
if (match == null) return;
|
||||
if (match.updatedMatch.isITStart) {
|
||||
widget.controller.choreographer.openIT(match);
|
||||
} else {
|
||||
OverlayUtil.showIGCMatch(
|
||||
match,
|
||||
widget.controller.choreographer,
|
||||
context,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool get _enableFeedback {
|
||||
return ![
|
||||
AssistanceState.fetching,
|
||||
|
|
@ -90,46 +70,13 @@ class StartIGCButtonState extends State<StartIGCButton>
|
|||
}
|
||||
|
||||
Future<void> _onTap() async {
|
||||
switch (assistanceState) {
|
||||
case AssistanceState.noSub:
|
||||
await PaywallCard.show(
|
||||
context,
|
||||
widget.controller.choreographer.inputTransformTargetKey,
|
||||
);
|
||||
return;
|
||||
case AssistanceState.noMessage:
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (c) => const SettingsLearning(),
|
||||
barrierDismissible: false,
|
||||
);
|
||||
return;
|
||||
case AssistanceState.notFetched:
|
||||
if (widget.controller.shouldShowLanguageMismatchPopup) {
|
||||
widget.controller.showLanguageMismatchPopup();
|
||||
} else {
|
||||
await widget.controller.choreographer.requestLanguageAssistance();
|
||||
final openMatch = widget.controller.choreographer.firstOpenMatch;
|
||||
if (openMatch != null) {
|
||||
if (openMatch.updatedMatch.isITStart) {
|
||||
widget.controller.choreographer.openIT(openMatch);
|
||||
} else {
|
||||
OverlayUtil.showIGCMatch(
|
||||
openMatch,
|
||||
widget.controller.choreographer,
|
||||
context,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
case AssistanceState.fetched:
|
||||
_showFirstMatch();
|
||||
return;
|
||||
case AssistanceState.complete:
|
||||
case AssistanceState.fetching:
|
||||
case AssistanceState.error:
|
||||
return;
|
||||
if (!_enableFeedback) return;
|
||||
if (widget.controller.shouldShowLanguageMismatchPopup) {
|
||||
widget.controller.showLanguageMismatchPopup();
|
||||
} else {
|
||||
await widget.controller.choreographer.requestLanguageAssistance();
|
||||
final openMatch = widget.controller.choreographer.firstOpenMatch;
|
||||
widget.controller.onSelectMatch(openMatch);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue