diff --git a/lib/pangea/matrix_event_wrappers/pangea_message_event.dart b/lib/pangea/matrix_event_wrappers/pangea_message_event.dart index 32b8c1a29..c9c05aca1 100644 --- a/lib/pangea/matrix_event_wrappers/pangea_message_event.dart +++ b/lib/pangea/matrix_event_wrappers/pangea_message_event.dart @@ -577,18 +577,18 @@ class PangeaMessageEvent { // this is just showActivityIcon now but will include // logic for showing - bool get showMessageButtons => showActivityIcon; + bool get showMessageButtons => hasUncompletedActivity; /// Returns a boolean value indicating whether to show an activity icon for this message event. /// - /// The [showActivityIcon] getter checks if the [l2Code] is null, and if so, returns false. + /// The [hasUncompletedActivity] getter checks if the [l2Code] is null, and if so, returns false. /// Otherwise, it retrieves a list of [PracticeActivityEvent] objects using the [practiceActivities] function /// with the [l2Code] as an argument. /// If the list is empty, it returns false. /// Otherwise, it checks if every activity in the list is complete using the [isComplete] property. /// If any activity is not complete, it returns true, indicating that the activity icon should be shown. /// Otherwise, it returns false. - bool get showActivityIcon { + bool get hasUncompletedActivity { if (l2Code == null) return false; final List activities = practiceActivities(l2Code!); diff --git a/lib/pangea/models/practice_activities.dart/practice_activity_record_model.dart b/lib/pangea/models/practice_activities.dart/practice_activity_record_model.dart index 7aa7f6b88..93ec8e478 100644 --- a/lib/pangea/models/practice_activities.dart/practice_activity_record_model.dart +++ b/lib/pangea/models/practice_activities.dart/practice_activity_record_model.dart @@ -38,6 +38,16 @@ class PracticeActivityRecordModel { }; } + /// get the latest response index according to the response timeStamp + /// sort the responses by timestamp and get the index of the last response + int? get latestResponseIndex { + if (responses.isEmpty) { + return null; + } + responses.sort((a, b) => a.timestamp.compareTo(b.timestamp)); + return responses.length - 1; + } + void addResponse({ String? text, Uint8List? audioBytes, diff --git a/lib/pangea/widgets/chat/message_toolbar.dart b/lib/pangea/widgets/chat/message_toolbar.dart index ff7b73b72..9bb5aacbe 100644 --- a/lib/pangea/widgets/chat/message_toolbar.dart +++ b/lib/pangea/widgets/chat/message_toolbar.dart @@ -189,6 +189,12 @@ class MessageToolbarState extends State { return; } + // if there is an uncompleted activity, then show that + // we don't want the user to user the tools to get the answer :P + if (widget.pangeaMessageEvent.hasUncompletedActivity) { + newMode = MessageMode.practiceActivity; + } + if (mounted) { setState(() { currentMode = newMode; diff --git a/lib/pangea/widgets/practice_activity_card/generate_practice_activity.dart b/lib/pangea/widgets/practice_activity_card/generate_practice_activity.dart index 02d7e90cd..7d01d8b4c 100644 --- a/lib/pangea/widgets/practice_activity_card/generate_practice_activity.dart +++ b/lib/pangea/widgets/practice_activity_card/generate_practice_activity.dart @@ -15,6 +15,7 @@ class GeneratePracticeActivityButton extends StatelessWidget { required this.onActivityGenerated, }); + //TODO - probably disable the generation of activities for specific messages @override Widget build(BuildContext context) { return ElevatedButton( diff --git a/lib/pangea/widgets/practice_activity_card/message_practice_activity_content.dart b/lib/pangea/widgets/practice_activity_card/message_practice_activity_content.dart index 8f234bc8d..6b7ebf7d9 100644 --- a/lib/pangea/widgets/practice_activity_card/message_practice_activity_content.dart +++ b/lib/pangea/widgets/practice_activity_card/message_practice_activity_content.dart @@ -47,6 +47,7 @@ class MessagePracticeActivityContentState ); } else { recordModel = recordEvent!.record; + selectedChoiceIndex = recordModel!.latestResponseIndex; recordSubmittedPreviousSession = true; recordSubmittedThisSession = true; }