merge main branch into combined selection view branch
This commit is contained in:
commit
9f641633e4
20 changed files with 372 additions and 391 deletions
|
|
@ -4127,5 +4127,6 @@
|
|||
"createSpace": "Create space",
|
||||
"createChat": "Create chat",
|
||||
"error520Title": "Please try again.",
|
||||
"error520Desc": "Sorry, we could not understand your message..."
|
||||
"error520Desc": "Sorry, we could not understand your message...",
|
||||
"translationChoicesBody": "Click and hold an option for a hint."
|
||||
}
|
||||
|
|
@ -63,13 +63,11 @@ abstract class AppConfig {
|
|||
path: '/krille-chan/fluffychat/issues/new',
|
||||
);
|
||||
// #Pangea
|
||||
// static bool renderHtml = true;
|
||||
static const bool enableSentry = true;
|
||||
static const String sentryDns =
|
||||
'https://8591d0d863b646feb4f3dda7e5dcab38@o256755.ingest.sentry.io/5243143';
|
||||
static bool renderHtml = false;
|
||||
// static bool renderHtml = true;
|
||||
// Pangea#
|
||||
static bool renderHtml = true;
|
||||
static bool hideRedactedEvents = false;
|
||||
static bool hideUnknownEvents = true;
|
||||
static bool hideUnimportantStateEvents = true;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
import 'package:animations/animations.dart';
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/controllers/choreographer.dart';
|
||||
import 'package:fluffychat/pages/chat/input_bar.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/widgets/send_button.dart';
|
||||
import 'package:fluffychat/pangea/constants/language_constants.dart';
|
||||
import 'package:fluffychat/pangea/widgets/chat/input_bar_wrapper.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/widgets/avatar.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
|
@ -34,7 +33,7 @@ class ChatInputRow extends StatelessWidget {
|
|||
controller.pangeaController.languageController.activeL2Model();
|
||||
|
||||
String hintText() {
|
||||
if (controller.choreographer.choreoMode == ChoreoMode.it) {
|
||||
if (controller.choreographer.itController.willOpen) {
|
||||
return L10n.of(context)!.buildTranslation;
|
||||
}
|
||||
return activel1 != null &&
|
||||
|
|
@ -322,10 +321,7 @@ class ChatInputRow extends StatelessWidget {
|
|||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 0.0),
|
||||
// #Pangea
|
||||
// child: InputBar(
|
||||
child: InputBarWrapper(
|
||||
// Pangea#
|
||||
child: InputBar(
|
||||
room: controller.room,
|
||||
minLines: 1,
|
||||
maxLines: 8,
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ import 'package:fluffychat/pages/chat/chat_app_bar_list_tile.dart';
|
|||
import 'package:fluffychat/pages/chat/chat_app_bar_title.dart';
|
||||
import 'package:fluffychat/pages/chat/chat_emoji_picker.dart';
|
||||
import 'package:fluffychat/pages/chat/chat_event_list.dart';
|
||||
import 'package:fluffychat/pages/chat/chat_input_row.dart';
|
||||
import 'package:fluffychat/pages/chat/pinned_events.dart';
|
||||
import 'package:fluffychat/pages/chat/reply_display.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/widgets/it_bar.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/widgets/start_igc_button.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/widgets/chat/chat_floating_action_button.dart';
|
||||
import 'package:fluffychat/pangea/widgets/chat/input_bar_wrapper.dart';
|
||||
import 'package:fluffychat/utils/account_config.dart';
|
||||
import 'package:fluffychat/widgets/chat_settings_popup_menu.dart';
|
||||
import 'package:fluffychat/widgets/connection_status_header.dart';
|
||||
|
|
@ -496,7 +496,9 @@ class ChatView extends StatelessWidget {
|
|||
choreographer: controller.choreographer,
|
||||
),
|
||||
ReplyDisplay(controller),
|
||||
ChatInputRow(controller),
|
||||
ChatInputRowWrapper(
|
||||
controller: controller,
|
||||
),
|
||||
ChatEmojiPicker(controller),
|
||||
],
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
import 'package:emojis/emoji.dart';
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pages/chat/command_hints.dart';
|
||||
import 'package:fluffychat/pangea/widgets/igc/pangea_text_controller.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/widgets/avatar.dart';
|
||||
import 'package:fluffychat/widgets/mxc_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:flutter_typeahead/flutter_typeahead.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:pasteboard/pasteboard.dart';
|
||||
|
|
@ -225,106 +229,117 @@ class InputBar extends StatelessWidget {
|
|||
Map<String, String?> suggestion,
|
||||
Client? client,
|
||||
) {
|
||||
const size = 30.0;
|
||||
// #Pangea
|
||||
// const size = 30.0;
|
||||
// const padding = EdgeInsets.all(4.0);
|
||||
// if (suggestion['type'] == 'command') {
|
||||
// final command = suggestion['name']!;
|
||||
// final hint = commandHint(L10n.of(context)!, command);
|
||||
// return Tooltip(
|
||||
// message: hint,
|
||||
// waitDuration: const Duration(days: 1), // don't show on hover
|
||||
// child: Container(
|
||||
// padding: padding,
|
||||
// child: Column(
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// children: [
|
||||
// Text(
|
||||
// commandExample(command),
|
||||
// style: const TextStyle(fontFamily: 'monospace'),
|
||||
// ),
|
||||
// Text(
|
||||
// hint,
|
||||
// maxLines: 1,
|
||||
// overflow: TextOverflow.ellipsis,
|
||||
// style: Theme.of(context).textTheme.bodySmall,
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// if (suggestion['type'] == 'emoji') {
|
||||
// final label = suggestion['label']!;
|
||||
// return Tooltip(
|
||||
// message: label,
|
||||
// waitDuration: const Duration(days: 1), // don't show on hover
|
||||
// child: Container(
|
||||
// padding: padding,
|
||||
// child: Text(label, style: const TextStyle(fontFamily: 'monospace')),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// if (suggestion['type'] == 'emote') {
|
||||
// return Container(
|
||||
// padding: padding,
|
||||
// child: Row(
|
||||
// crossAxisAlignment: CrossAxisAlignment.center,
|
||||
// children: <Widget>[
|
||||
// MxcImage(
|
||||
// // ensure proper ordering ...
|
||||
// key: ValueKey(suggestion['name']),
|
||||
// uri: suggestion['mxc'] is String
|
||||
// ? Uri.parse(suggestion['mxc'] ?? '')
|
||||
// : null,
|
||||
// width: size,
|
||||
// height: size,
|
||||
// ),
|
||||
// const SizedBox(width: 6),
|
||||
// Text(suggestion['name']!),
|
||||
// Expanded(
|
||||
// child: Align(
|
||||
// alignment: Alignment.centerRight,
|
||||
// child: Opacity(
|
||||
// opacity: suggestion['pack_avatar_url'] != null ? 0.8 : 0.5,
|
||||
// child: suggestion['pack_avatar_url'] != null
|
||||
// ? Avatar(
|
||||
// mxContent: Uri.tryParse(
|
||||
// suggestion.tryGet<String>('pack_avatar_url') ?? '',
|
||||
// ),
|
||||
// name: suggestion.tryGet<String>('pack_display_name'),
|
||||
// size: size * 0.9,
|
||||
// client: client,
|
||||
// )
|
||||
// : Text(suggestion['pack_display_name']!),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// if (suggestion['type'] == 'user' || suggestion['type'] == 'room') {
|
||||
// final url = Uri.parse(suggestion['avatar_url'] ?? '');
|
||||
// return Container(
|
||||
// padding: padding,
|
||||
// child: Row(
|
||||
// crossAxisAlignment: CrossAxisAlignment.center,
|
||||
// children: <Widget>[
|
||||
// Avatar(
|
||||
// mxContent: url,
|
||||
// name: suggestion.tryGet<String>('displayname') ??
|
||||
// suggestion.tryGet<String>('mxid'),
|
||||
// size: size,
|
||||
// client: client,
|
||||
// ),
|
||||
// const SizedBox(width: 6),
|
||||
// Text(suggestion['displayname'] ?? suggestion['mxid']!),
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
const padding = EdgeInsets.all(8.0);
|
||||
// Pangea#
|
||||
if (suggestion['type'] == 'command') {
|
||||
final command = suggestion['name']!;
|
||||
final hint = commandHint(L10n.of(context)!, command);
|
||||
return Tooltip(
|
||||
message: hint,
|
||||
waitDuration: const Duration(days: 1), // don't show on hover
|
||||
child: Container(
|
||||
padding: padding,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
commandExample(command),
|
||||
style: const TextStyle(fontFamily: 'monospace'),
|
||||
),
|
||||
Text(
|
||||
hint,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (suggestion['type'] == 'emoji') {
|
||||
final label = suggestion['label']!;
|
||||
return Tooltip(
|
||||
message: label,
|
||||
waitDuration: const Duration(days: 1), // don't show on hover
|
||||
child: Container(
|
||||
padding: padding,
|
||||
child: Text(label, style: const TextStyle(fontFamily: 'monospace')),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (suggestion['type'] == 'emote') {
|
||||
return Container(
|
||||
padding: padding,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
MxcImage(
|
||||
// ensure proper ordering ...
|
||||
key: ValueKey(suggestion['name']),
|
||||
uri: suggestion['mxc'] is String
|
||||
? Uri.parse(suggestion['mxc'] ?? '')
|
||||
: null,
|
||||
width: size,
|
||||
height: size,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(suggestion['name']!),
|
||||
Expanded(
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Opacity(
|
||||
opacity: suggestion['pack_avatar_url'] != null ? 0.8 : 0.5,
|
||||
child: suggestion['pack_avatar_url'] != null
|
||||
? Avatar(
|
||||
mxContent: Uri.tryParse(
|
||||
suggestion.tryGet<String>('pack_avatar_url') ?? '',
|
||||
),
|
||||
name: suggestion.tryGet<String>('pack_display_name'),
|
||||
size: size * 0.9,
|
||||
client: client,
|
||||
)
|
||||
: Text(suggestion['pack_display_name']!),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
if (suggestion['type'] == 'user' || suggestion['type'] == 'room') {
|
||||
final url = Uri.parse(suggestion['avatar_url'] ?? '');
|
||||
return Container(
|
||||
padding: padding,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Avatar(
|
||||
mxContent: url,
|
||||
name: suggestion.tryGet<String>('displayname') ??
|
||||
suggestion.tryGet<String>('mxid'),
|
||||
size: size,
|
||||
client: client,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
// #Pangea
|
||||
Flexible(
|
||||
child:
|
||||
// Pangea#
|
||||
Text(
|
||||
suggestion['displayname'] ?? suggestion['mxid']!,
|
||||
// #Pangea
|
||||
overflow: TextOverflow.ellipsis,
|
||||
// Pangea#
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
|
|
@ -533,6 +548,15 @@ class InputBar extends StatelessWidget {
|
|||
// fix loading briefly flickering a dark box
|
||||
emptyBuilder: (BuildContext context) => const SizedBox
|
||||
.shrink(), // fix loading briefly showing no suggestions
|
||||
// #Pangea
|
||||
// If we ever want to change the suggestion background color
|
||||
// here is the code for it
|
||||
// decorationBuilder: (context, child) => Material(
|
||||
// borderRadius: BorderRadius.circular(AppConfig.borderRadius),
|
||||
// color: Theme.of(context).colorScheme.surfaceContainerHigh,
|
||||
// child: child,
|
||||
// ),
|
||||
// Pangea#
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -4,12 +4,14 @@ import 'dart:developer';
|
|||
import 'package:fluffychat/pangea/choreographer/controllers/choreographer.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/controllers/error_service.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/controllers/span_data_controller.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_message_event.dart';
|
||||
import 'package:fluffychat/pangea/models/igc_text_data_model.dart';
|
||||
import 'package:fluffychat/pangea/models/pangea_match_model.dart';
|
||||
import 'package:fluffychat/pangea/repo/igc_repo.dart';
|
||||
import 'package:fluffychat/pangea/widgets/igc/span_card.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import '../../models/span_card_model.dart';
|
||||
import '../../utils/error_handler.dart';
|
||||
|
|
@ -39,10 +41,12 @@ class IgcController {
|
|||
|
||||
final IGCRequestBody reqBody = IGCRequestBody(
|
||||
fullText: choreographer.currentText,
|
||||
userId: choreographer.pangeaController.userController.userId!,
|
||||
userL1: choreographer.l1LangCode!,
|
||||
userL2: choreographer.l2LangCode!,
|
||||
enableIGC: choreographer.igcEnabled && !onlyTokensAndLanguageDetection,
|
||||
enableIT: choreographer.itEnabled && !onlyTokensAndLanguageDetection,
|
||||
prevMessages: prevMessages(),
|
||||
);
|
||||
|
||||
final IGCTextData igcTextDataResponse = await IgcRepo.getIGC(
|
||||
|
|
@ -125,6 +129,49 @@ class IgcController {
|
|||
);
|
||||
}
|
||||
|
||||
/// Get the content of previous text and audio messages in chat.
|
||||
/// Passed to IGC request to add context.
|
||||
List<PreviousMessage> prevMessages({int numMessages = 5}) {
|
||||
final List<Event> events = choreographer.chatController.visibleEvents
|
||||
.where(
|
||||
(e) =>
|
||||
e.type == EventTypes.Message &&
|
||||
(e.messageType == MessageTypes.Text ||
|
||||
e.messageType == MessageTypes.Audio),
|
||||
)
|
||||
.toList();
|
||||
|
||||
final List<PreviousMessage> messages = [];
|
||||
for (final Event event in events) {
|
||||
final String? content = event.messageType == MessageTypes.Text
|
||||
? event.content.toString()
|
||||
: PangeaMessageEvent(
|
||||
event: event,
|
||||
timeline: choreographer.chatController.timeline!,
|
||||
ownMessage: event.senderId ==
|
||||
choreographer.pangeaController.matrixState.client.userID,
|
||||
)
|
||||
.getSpeechToTextLocal(
|
||||
choreographer.l1LangCode,
|
||||
choreographer.l2LangCode,
|
||||
)
|
||||
?.transcript
|
||||
.text;
|
||||
if (content == null) continue;
|
||||
messages.add(
|
||||
PreviousMessage(
|
||||
content: content,
|
||||
sender: event.senderId,
|
||||
timestamp: event.originServerTs,
|
||||
),
|
||||
);
|
||||
if (messages.length >= numMessages) {
|
||||
return messages;
|
||||
}
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
|
||||
bool get hasRelevantIGCTextData {
|
||||
if (igcTextData == null) return false;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import 'dart:developer';
|
|||
|
||||
import 'package:fluffychat/pangea/choreographer/controllers/error_service.dart';
|
||||
import 'package:fluffychat/pangea/constants/choreo_constants.dart';
|
||||
import 'package:fluffychat/pangea/enum/instructions_enum.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
|
@ -54,6 +55,23 @@ class ITController {
|
|||
choreographer.setState();
|
||||
}
|
||||
|
||||
bool _closingHint = false;
|
||||
Duration get animationSpeed => (_closingHint || !_willOpen)
|
||||
? const Duration(milliseconds: 500)
|
||||
: const Duration(milliseconds: 2000);
|
||||
|
||||
void closeHint() {
|
||||
_closingHint = true;
|
||||
final String hintKey = InlineInstructions.translationChoices.toString();
|
||||
final instructionsController = choreographer.pangeaController.instructions;
|
||||
instructionsController.turnOffInstruction(hintKey);
|
||||
instructionsController.updateEnableInstructions(hintKey, true);
|
||||
choreographer.setState();
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
_closingHint = false;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> initializeIT(ITStartData itStartData) async {
|
||||
_willOpen = true;
|
||||
Future.delayed(const Duration(microseconds: 100), () {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ import 'package:fluffychat/pangea/choreographer/widgets/it_bar_buttons.dart';
|
|||
import 'package:fluffychat/pangea/choreographer/widgets/it_feedback_card.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/widgets/translation_finished_flow.dart';
|
||||
import 'package:fluffychat/pangea/constants/choreo_constants.dart';
|
||||
import 'package:fluffychat/pangea/enum/instructions_enum.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
import 'package:fluffychat/pangea/utils/inline_tooltip.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
|
|
@ -45,12 +47,16 @@ class ITBarState extends State<ITBar> {
|
|||
super.dispose();
|
||||
}
|
||||
|
||||
bool get instructionsTurnedOff =>
|
||||
widget.choreographer.pangeaController.instructions
|
||||
.wereInstructionsTurnedOff(
|
||||
InlineInstructions.translationChoices.toString(),
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedSize(
|
||||
duration: itController.willOpen
|
||||
? const Duration(milliseconds: 2000)
|
||||
: const Duration(milliseconds: 500),
|
||||
duration: itController.animationSpeed,
|
||||
curve: Curves.fastOutSlowIn,
|
||||
clipBehavior: Clip.none,
|
||||
child: !itController.willOpen
|
||||
|
|
@ -58,9 +64,7 @@ class ITBarState extends State<ITBar> {
|
|||
: CompositedTransformTarget(
|
||||
link: widget.choreographer.itBarLinkAndKey.link,
|
||||
child: AnimatedOpacity(
|
||||
duration: itController.willOpen
|
||||
? const Duration(milliseconds: 2000)
|
||||
: const Duration(milliseconds: 500),
|
||||
duration: itController.animationSpeed,
|
||||
opacity: itController.willOpen ? 1.0 : 0.0,
|
||||
child: Container(
|
||||
key: widget.choreographer.itBarLinkAndKey.key,
|
||||
|
|
@ -109,6 +113,12 @@ class ITBarState extends State<ITBar> {
|
|||
// const SizedBox(height: 40.0),
|
||||
OriginalText(controller: itController),
|
||||
const SizedBox(height: 7.0),
|
||||
if (!instructionsTurnedOff)
|
||||
InlineTooltip(
|
||||
body: InlineInstructions.translationChoices
|
||||
.body(context),
|
||||
onClose: itController.closeHint,
|
||||
),
|
||||
IntrinsicHeight(
|
||||
child: Container(
|
||||
constraints:
|
||||
|
|
@ -151,6 +161,7 @@ class ITBarState extends State<ITBar> {
|
|||
),
|
||||
),
|
||||
),
|
||||
// ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
@ -305,7 +316,11 @@ class ITChoices extends StatelessWidget {
|
|||
chosenContinuance:
|
||||
controller.currentITStep!.continuances[index].text,
|
||||
bestContinuance: controller.currentITStep!.best.text,
|
||||
feedbackLang: controller.targetLangCode,
|
||||
// TODO: we want this to eventually switch between target and source lang,
|
||||
// based on the learner's proficiency - maybe with the words involved in the translation
|
||||
// maybe overall. For now, we'll just use the source lang.
|
||||
feedbackLang: controller.choreographer.l1Lang?.langCode ??
|
||||
controller.sourceLangCode,
|
||||
sourceTextLang: controller.sourceLangCode,
|
||||
targetLang: controller.targetLangCode,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -146,8 +146,11 @@ class ITFeedbackCardView extends StatelessWidget {
|
|||
controller.res!.text,
|
||||
style: BotStyle.text(context),
|
||||
),
|
||||
// if res is not null, show a button to translate the text
|
||||
if (controller.res != null && controller.translatedFeedback == null)
|
||||
// if res is not null and feedback not in the userL1, show a button to translate the text
|
||||
if (controller.res != null &&
|
||||
controller.translatedFeedback == null &&
|
||||
controller.widget.req.feedbackLang !=
|
||||
controller.controller.languageController.userL1?.langCode)
|
||||
Column(
|
||||
children: [
|
||||
const SizedBox(height: 10),
|
||||
|
|
|
|||
|
|
@ -50,7 +50,10 @@ class StartIGCButtonState extends State<StartIGCButton>
|
|||
_controller?.stop();
|
||||
_controller?.reverse();
|
||||
}
|
||||
setState(() => prevState = assistanceState);
|
||||
|
||||
if (mounted) {
|
||||
setState(() => prevState = assistanceState);
|
||||
}
|
||||
}
|
||||
|
||||
bool get itEnabled => widget.controller.choreographer.itEnabled;
|
||||
|
|
|
|||
|
|
@ -69,6 +69,10 @@ class ModelKey {
|
|||
static const String permissions = "permissions";
|
||||
static const String enableIGC = "enable_igc";
|
||||
static const String enableIT = "enable_it";
|
||||
static const String prevMessages = "prev_messages";
|
||||
static const String prevContent = "prev_content";
|
||||
static const String prevSender = "prev_sender";
|
||||
static const String prevTimestamp = "prev_timestamp";
|
||||
|
||||
static const String originalSent = "original_sent";
|
||||
static const String originalWritten = "original_written";
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ extension InstructionsEnumExtension on InstructionsEnum {
|
|||
enum InlineInstructions {
|
||||
speechToText,
|
||||
l1Translation,
|
||||
translationChoices,
|
||||
}
|
||||
|
||||
extension InlineInstructionsExtension on InlineInstructions {
|
||||
|
|
@ -67,6 +68,21 @@ extension InlineInstructionsExtension on InlineInstructions {
|
|||
return L10n.of(context)!.speechToTextBody;
|
||||
case InlineInstructions.l1Translation:
|
||||
return L10n.of(context)!.l1TranslationBody;
|
||||
case InlineInstructions.translationChoices:
|
||||
return L10n.of(context)!.translationChoicesBody;
|
||||
}
|
||||
}
|
||||
|
||||
bool get toggledOff {
|
||||
final instructionSettings =
|
||||
MatrixState.pangeaController.userController.profile.instructionSettings;
|
||||
switch (this) {
|
||||
case InlineInstructions.speechToText:
|
||||
return instructionSettings.showedSpeechToTextTooltip;
|
||||
case InlineInstructions.l1Translation:
|
||||
return instructionSettings.showedL1TranslationTooltip;
|
||||
case InlineInstructions.translationChoices:
|
||||
return instructionSettings.showedTranslationChoicesTooltip;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -269,6 +269,21 @@ class PangeaMessageEvent {
|
|||
null;
|
||||
}).toSet();
|
||||
|
||||
SpeechToTextModel? getSpeechToTextLocal(
|
||||
String? l1Code,
|
||||
String? l2Code,
|
||||
) {
|
||||
if (l1Code == null || l2Code == null) {
|
||||
return null;
|
||||
}
|
||||
return representations
|
||||
.firstWhereOrNull(
|
||||
(element) => element.content.speechToText != null,
|
||||
)
|
||||
?.content
|
||||
.speechToText;
|
||||
}
|
||||
|
||||
Future<SpeechToTextModel?> getSpeechToText(
|
||||
String l1Code,
|
||||
String l2Code,
|
||||
|
|
|
|||
|
|
@ -186,11 +186,18 @@ class UserInstructions {
|
|||
bool showedBlurMeansTranslate;
|
||||
bool showedTooltipInstructions;
|
||||
|
||||
bool showedSpeechToTextTooltip;
|
||||
bool showedL1TranslationTooltip;
|
||||
bool showedTranslationChoicesTooltip;
|
||||
|
||||
UserInstructions({
|
||||
this.showedItInstructions = false,
|
||||
this.showedClickMessage = false,
|
||||
this.showedBlurMeansTranslate = false,
|
||||
this.showedTooltipInstructions = false,
|
||||
this.showedSpeechToTextTooltip = false,
|
||||
this.showedL1TranslationTooltip = false,
|
||||
this.showedTranslationChoicesTooltip = false,
|
||||
});
|
||||
|
||||
factory UserInstructions.fromJson(Map<String, dynamic> json) =>
|
||||
|
|
@ -203,6 +210,12 @@ class UserInstructions {
|
|||
json[InstructionsEnum.blurMeansTranslate.toString()] ?? false,
|
||||
showedTooltipInstructions:
|
||||
json[InstructionsEnum.tooltipInstructions.toString()] ?? false,
|
||||
showedL1TranslationTooltip:
|
||||
json[InlineInstructions.l1Translation.toString()] ?? false,
|
||||
showedTranslationChoicesTooltip:
|
||||
json[InlineInstructions.translationChoices.toString()] ?? false,
|
||||
showedSpeechToTextTooltip:
|
||||
json[InlineInstructions.speechToText.toString()] ?? false,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
|
|
@ -213,6 +226,12 @@ class UserInstructions {
|
|||
showedBlurMeansTranslate;
|
||||
data[InstructionsEnum.tooltipInstructions.toString()] =
|
||||
showedTooltipInstructions;
|
||||
data[InlineInstructions.l1Translation.toString()] =
|
||||
showedL1TranslationTooltip;
|
||||
data[InlineInstructions.translationChoices.toString()] =
|
||||
showedTranslationChoicesTooltip;
|
||||
data[InlineInstructions.speechToText.toString()] =
|
||||
showedSpeechToTextTooltip;
|
||||
return data;
|
||||
}
|
||||
|
||||
|
|
@ -238,6 +257,21 @@ class UserInstructions {
|
|||
?.content[InstructionsEnum.tooltipInstructions.toString()]
|
||||
as bool?) ??
|
||||
false,
|
||||
showedL1TranslationTooltip:
|
||||
(accountData[InlineInstructions.l1Translation.toString()]
|
||||
?.content[InlineInstructions.l1Translation.toString()]
|
||||
as bool?) ??
|
||||
false,
|
||||
showedTranslationChoicesTooltip: (accountData[
|
||||
InlineInstructions.translationChoices.toString()]
|
||||
?.content[InlineInstructions.translationChoices.toString()]
|
||||
as bool?) ??
|
||||
false,
|
||||
showedSpeechToTextTooltip:
|
||||
(accountData[InlineInstructions.speechToText.toString()]
|
||||
?.content[InlineInstructions.speechToText.toString()]
|
||||
as bool?) ??
|
||||
false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,12 +94,43 @@ class IgcRepo {
|
|||
}
|
||||
}
|
||||
|
||||
/// Previous text/audio message sent in chat
|
||||
/// Contain message content, sender, and timestamp
|
||||
class PreviousMessage {
|
||||
String content;
|
||||
String sender;
|
||||
DateTime timestamp;
|
||||
|
||||
PreviousMessage({
|
||||
required this.content,
|
||||
required this.sender,
|
||||
required this.timestamp,
|
||||
});
|
||||
|
||||
factory PreviousMessage.fromJson(Map<String, dynamic> json) =>
|
||||
PreviousMessage(
|
||||
content: json[ModelKey.prevContent] ?? "",
|
||||
sender: json[ModelKey.prevSender] ?? "",
|
||||
timestamp: json[ModelKey.prevTimestamp] == null
|
||||
? DateTime.now()
|
||||
: DateTime.parse(json[ModelKey.prevTimestamp]),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
ModelKey.prevContent: content,
|
||||
ModelKey.prevSender: sender,
|
||||
ModelKey.prevTimestamp: timestamp.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
class IGCRequestBody {
|
||||
String fullText;
|
||||
String userL1;
|
||||
String userL2;
|
||||
bool enableIT;
|
||||
bool enableIGC;
|
||||
String userId;
|
||||
List<PreviousMessage> prevMessages;
|
||||
|
||||
IGCRequestBody({
|
||||
required this.fullText,
|
||||
|
|
@ -107,6 +138,8 @@ class IGCRequestBody {
|
|||
required this.userL2,
|
||||
required this.enableIGC,
|
||||
required this.enableIT,
|
||||
required this.userId,
|
||||
required this.prevMessages,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
|
|
@ -115,5 +148,8 @@ class IGCRequestBody {
|
|||
ModelKey.userL2: userL2,
|
||||
"enable_it": enableIT,
|
||||
"enable_igc": enableIGC,
|
||||
ModelKey.userId: userId,
|
||||
ModelKey.prevMessages:
|
||||
jsonEncode(prevMessages.map((x) => x.toJson()).toList()),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class InlineTooltip extends StatelessWidget {
|
|||
onPressed: onClose,
|
||||
),
|
||||
),
|
||||
child: Container(
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: Theme.of(context).colorScheme.primary.withAlpha(20),
|
||||
|
|
|
|||
|
|
@ -25,9 +25,15 @@ class InstructionsController {
|
|||
final Map<String, bool> _instructionsShown = {};
|
||||
|
||||
/// Returns true if the user requested this popup not be shown again
|
||||
bool? toggledOff(String key) => InstructionsEnum.values
|
||||
.firstWhereOrNull((value) => value.toString() == key)
|
||||
?.toggledOff;
|
||||
bool? toggledOff(String key) {
|
||||
final bool? instruction = InstructionsEnum.values
|
||||
.firstWhereOrNull((value) => value.toString() == key)
|
||||
?.toggledOff;
|
||||
final bool? tooltip = InlineInstructions.values
|
||||
.firstWhereOrNull((value) => value.toString() == key)
|
||||
?.toggledOff;
|
||||
return instruction ?? tooltip;
|
||||
}
|
||||
|
||||
InstructionsController(PangeaController pangeaController) {
|
||||
_pangeaController = pangeaController;
|
||||
|
|
@ -58,6 +64,15 @@ class InstructionsController {
|
|||
if (key == InstructionsEnum.tooltipInstructions.toString()) {
|
||||
profile.instructionSettings.showedTooltipInstructions = value;
|
||||
}
|
||||
if (key == InlineInstructions.speechToText.toString()) {
|
||||
profile.instructionSettings.showedSpeechToTextTooltip = value;
|
||||
}
|
||||
if (key == InlineInstructions.l1Translation.toString()) {
|
||||
profile.instructionSettings.showedL1TranslationTooltip = value;
|
||||
}
|
||||
if (key == InlineInstructions.translationChoices.toString()) {
|
||||
profile.instructionSettings.showedTranslationChoicesTooltip = value;
|
||||
}
|
||||
return profile;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,48 +1,23 @@
|
|||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:fluffychat/pages/chat/input_bar.dart';
|
||||
import 'package:fluffychat/pages/chat/chat.dart';
|
||||
import 'package:fluffychat/pages/chat/chat_input_row.dart';
|
||||
import 'package:fluffychat/pangea/widgets/igc/pangea_text_controller.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
class InputBarWrapper extends StatefulWidget {
|
||||
final Room room;
|
||||
final int? minLines;
|
||||
final int? maxLines;
|
||||
final TextInputType? keyboardType;
|
||||
final TextInputAction? textInputAction;
|
||||
final ValueChanged<String>? onSubmitted;
|
||||
final ValueChanged<Uint8List?>? onSubmitImage;
|
||||
final FocusNode? focusNode;
|
||||
final PangeaTextController? controller;
|
||||
final InputDecoration? decoration;
|
||||
final ValueChanged<String>? onChanged;
|
||||
final bool? autofocus;
|
||||
final bool readOnly;
|
||||
class ChatInputRowWrapper extends StatefulWidget {
|
||||
final ChatController controller;
|
||||
|
||||
const InputBarWrapper({
|
||||
required this.room,
|
||||
this.minLines,
|
||||
this.maxLines,
|
||||
this.keyboardType,
|
||||
this.onSubmitted,
|
||||
this.onSubmitImage,
|
||||
this.focusNode,
|
||||
this.controller,
|
||||
this.decoration,
|
||||
this.onChanged,
|
||||
this.autofocus,
|
||||
this.textInputAction,
|
||||
this.readOnly = false,
|
||||
const ChatInputRowWrapper({
|
||||
required this.controller,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
State<InputBarWrapper> createState() => InputBarWrapperState();
|
||||
State<ChatInputRowWrapper> createState() => ChatInputRowWrapperState();
|
||||
}
|
||||
|
||||
class InputBarWrapperState extends State<InputBarWrapper> {
|
||||
class ChatInputRowWrapperState extends State<ChatInputRowWrapper> {
|
||||
StreamSubscription? _choreoSub;
|
||||
String _currentText = '';
|
||||
|
||||
|
|
@ -50,7 +25,7 @@ class InputBarWrapperState extends State<InputBarWrapper> {
|
|||
void initState() {
|
||||
// Rebuild the widget each time there's an update from choreo
|
||||
_choreoSub =
|
||||
widget.controller?.choreographer.stateListener.stream.listen((_) {
|
||||
widget.controller.choreographer.stateListener.stream.listen((_) {
|
||||
setState(() {});
|
||||
});
|
||||
super.initState();
|
||||
|
|
@ -63,10 +38,6 @@ class InputBarWrapperState extends State<InputBarWrapper> {
|
|||
}
|
||||
|
||||
void refreshOnChange(String text) {
|
||||
if (widget.onChanged != null) {
|
||||
widget.onChanged!(text);
|
||||
}
|
||||
|
||||
final bool decreasedFromMaxLength =
|
||||
_currentText.length >= PangeaTextController.maxLength &&
|
||||
text.length < PangeaTextController.maxLength;
|
||||
|
|
@ -81,21 +52,5 @@ class InputBarWrapperState extends State<InputBarWrapper> {
|
|||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InputBar(
|
||||
room: widget.room,
|
||||
minLines: widget.minLines,
|
||||
maxLines: widget.maxLines,
|
||||
keyboardType: widget.keyboardType,
|
||||
onSubmitted: widget.onSubmitted,
|
||||
onSubmitImage: widget.onSubmitImage,
|
||||
focusNode: widget.focusNode,
|
||||
controller: widget.controller,
|
||||
decoration: widget.decoration,
|
||||
onChanged: refreshOnChange,
|
||||
autofocus: widget.autofocus,
|
||||
textInputAction: widget.textInputAction,
|
||||
readOnly: widget.readOnly,
|
||||
);
|
||||
}
|
||||
Widget build(BuildContext context) => ChatInputRow(widget.controller);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,206 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
Future<T?> showAlignedDialog<T>({
|
||||
required BuildContext context,
|
||||
required WidgetBuilder builder,
|
||||
bool barrierDismissible = true,
|
||||
Color? barrierColor = Colors.black54,
|
||||
String? barrierLabel,
|
||||
bool useRootNavigator = true,
|
||||
RouteSettings? routeSettings,
|
||||
Alignment followerAnchor = Alignment.center,
|
||||
Alignment targetAnchor = Alignment.center,
|
||||
Size? refChildSize,
|
||||
Offset offset = Offset.zero,
|
||||
bool avoidOverflow = false,
|
||||
bool isGlobal = false,
|
||||
RouteTransitionsBuilder? transitionsBuilder,
|
||||
Duration? duration,
|
||||
}) {
|
||||
assert(debugCheckHasMaterialLocalizations(context));
|
||||
|
||||
final CapturedThemes themes = InheritedTheme.capture(
|
||||
from: context,
|
||||
to: Navigator.of(
|
||||
context,
|
||||
rootNavigator: useRootNavigator,
|
||||
).context,
|
||||
);
|
||||
|
||||
final RenderBox targetBox = context.findRenderObject()! as RenderBox;
|
||||
final RenderBox overlay =
|
||||
Navigator.of(context).overlay!.context.findRenderObject()! as RenderBox;
|
||||
Offset position = targetBox
|
||||
.localToGlobal(targetAnchor.alongSize(targetBox.size), ancestor: overlay);
|
||||
|
||||
if (isGlobal) {
|
||||
position = overlay.localToGlobal(followerAnchor.alongSize(overlay.size));
|
||||
}
|
||||
|
||||
return Navigator.of(context, rootNavigator: useRootNavigator).push<T>(
|
||||
AlignedDialogRoute<T>(
|
||||
followerAlignment: followerAnchor,
|
||||
position: position,
|
||||
context: context,
|
||||
builder: builder,
|
||||
barrierColor: barrierColor,
|
||||
barrierDismissible: barrierDismissible,
|
||||
barrierLabel: barrierLabel,
|
||||
useSafeArea: isGlobal == true,
|
||||
settings: routeSettings,
|
||||
themes: themes,
|
||||
transitionsBuilder: transitionsBuilder,
|
||||
duration: duration,
|
||||
avoidOverflow: avoidOverflow,
|
||||
offset: offset,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class AlignedDialogRoute<T> extends RawDialogRoute<T> {
|
||||
/// A dialog route with Material entrance and exit animations,
|
||||
/// modal barrier color, and modal barrier behavior (dialog is dismissible
|
||||
/// with a tap on the barrier).
|
||||
AlignedDialogRoute({
|
||||
required BuildContext context,
|
||||
required WidgetBuilder builder,
|
||||
required Alignment followerAlignment,
|
||||
required Offset position,
|
||||
CapturedThemes? themes,
|
||||
super.barrierColor = Colors.transparent,
|
||||
super.barrierDismissible,
|
||||
String? barrierLabel,
|
||||
bool useSafeArea = false,
|
||||
super.settings,
|
||||
RouteTransitionsBuilder? transitionsBuilder,
|
||||
Duration? duration,
|
||||
bool avoidOverflow = false,
|
||||
Offset offset = Offset.zero,
|
||||
}) : super(
|
||||
pageBuilder: (
|
||||
BuildContext buildContext,
|
||||
Animation<double> animation,
|
||||
Animation<double> secondaryAnimation,
|
||||
) {
|
||||
final Widget pageChild = Builder(builder: builder);
|
||||
Widget dialog = Builder(
|
||||
builder: (BuildContext context) {
|
||||
final MediaQueryData mediaQuery = MediaQuery.of(context);
|
||||
return CustomSingleChildLayout(
|
||||
delegate: _FollowerDialogRouteLayout(
|
||||
followerAlignment,
|
||||
position,
|
||||
Directionality.of(context),
|
||||
mediaQuery.padding.top,
|
||||
mediaQuery.padding.bottom,
|
||||
offset,
|
||||
avoidOverflow,
|
||||
),
|
||||
child: pageChild,
|
||||
);
|
||||
},
|
||||
);
|
||||
dialog = themes?.wrap(dialog) ?? dialog;
|
||||
if (useSafeArea) {
|
||||
dialog = SafeArea(child: dialog);
|
||||
}
|
||||
return dialog;
|
||||
},
|
||||
barrierLabel: barrierLabel ??
|
||||
MaterialLocalizations.of(context).modalBarrierDismissLabel,
|
||||
transitionDuration: duration ?? const Duration(milliseconds: 200),
|
||||
transitionBuilder:
|
||||
transitionsBuilder ?? _buildMaterialDialogTransitions,
|
||||
);
|
||||
}
|
||||
|
||||
// Positioning of the menu on the screen.
|
||||
class _FollowerDialogRouteLayout extends SingleChildLayoutDelegate {
|
||||
_FollowerDialogRouteLayout(
|
||||
this.followerAnchor,
|
||||
this.position,
|
||||
this.textDirection,
|
||||
this.topPadding,
|
||||
this.bottomPadding,
|
||||
this.offset,
|
||||
this.avoidOverflow,
|
||||
);
|
||||
|
||||
final Alignment followerAnchor;
|
||||
|
||||
final Offset position;
|
||||
|
||||
final TextDirection textDirection;
|
||||
|
||||
final double topPadding;
|
||||
|
||||
final double bottomPadding;
|
||||
|
||||
final Offset offset;
|
||||
final bool avoidOverflow;
|
||||
|
||||
@override
|
||||
BoxConstraints getConstraintsForChild(BoxConstraints constraints) {
|
||||
// The menu can be at most the size of the overlay minus 8.0 pixels in each
|
||||
// direction.
|
||||
return BoxConstraints.loose(constraints.biggest)
|
||||
.deflate(EdgeInsets.only(top: topPadding, bottom: bottomPadding));
|
||||
}
|
||||
|
||||
@override
|
||||
Offset getPositionForChild(Size size, Size childSize) {
|
||||
Offset rst = followerAnchor.alongSize(childSize);
|
||||
rst = position - rst;
|
||||
rst += offset;
|
||||
if (avoidOverflow) {
|
||||
if (rst.dx < 0) rst = Offset(0, rst.dy);
|
||||
if (rst.dy < 0) rst = Offset(rst.dx, 0);
|
||||
if (rst.dx + childSize.width > size.width) {
|
||||
rst = Offset(size.width - childSize.width, rst.dy);
|
||||
}
|
||||
if (rst.dy + childSize.height > size.height) {
|
||||
rst = Offset(rst.dx, size.height - childSize.height);
|
||||
}
|
||||
}
|
||||
return rst;
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRelayout(_FollowerDialogRouteLayout oldDelegate) {
|
||||
return followerAnchor != oldDelegate.followerAnchor ||
|
||||
position != oldDelegate.position ||
|
||||
offset != oldDelegate.offset ||
|
||||
avoidOverflow != oldDelegate.avoidOverflow ||
|
||||
textDirection != oldDelegate.textDirection ||
|
||||
topPadding != oldDelegate.topPadding ||
|
||||
bottomPadding != oldDelegate.bottomPadding;
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildMaterialDialogTransitions(
|
||||
BuildContext context,
|
||||
Animation<double> animation,
|
||||
Animation<double> secondaryAnimation,
|
||||
Widget child,
|
||||
) {
|
||||
return FadeTransition(
|
||||
opacity: CurvedAnimation(
|
||||
parent: animation,
|
||||
curve: Curves.easeOut,
|
||||
),
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
Offset _buildOffSet(
|
||||
BuildContext context, {
|
||||
required Size refChildSize,
|
||||
required Offset offset,
|
||||
}) {
|
||||
final Size screenSize = MediaQuery.of(context).size;
|
||||
final Size maxAvilableArea = Size(
|
||||
screenSize.width - refChildSize.width,
|
||||
screenSize.height - refChildSize.height,
|
||||
);
|
||||
return const Offset(0, 0);
|
||||
}
|
||||
|
|
@ -21,13 +21,18 @@ class ErrorReporter {
|
|||
// Exits early to prevent further execution
|
||||
return;
|
||||
}
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
l10n.oopsSomethingWentWrong, // Use the non-null L10n instance to get the error message
|
||||
|
||||
try {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
l10n.oopsSomethingWentWrong, // Use the non-null L10n instance to get the error message
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
} catch (err) {
|
||||
debugPrint("Failed to show error snackbar.");
|
||||
}
|
||||
}
|
||||
// final text = '$error\n${stackTrace ?? ''}';
|
||||
// await showAdaptiveDialog(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue