From 1bd244011f8b301c2114179e40388a1c5be05b85 Mon Sep 17 00:00:00 2001 From: William Jordan-Cooley Date: Wed, 9 Oct 2024 11:19:07 -0400 Subject: [PATCH 1/3] remove use of record --- .../practice_activity_card.dart | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/pangea/widgets/practice_activity/practice_activity_card.dart b/lib/pangea/widgets/practice_activity/practice_activity_card.dart index 517cbcebe..8e849a6f0 100644 --- a/lib/pangea/widgets/practice_activity/practice_activity_card.dart +++ b/lib/pangea/widgets/practice_activity/practice_activity_card.dart @@ -93,24 +93,24 @@ class MessagePracticeActivityCardState extends State { /// If not, get a new activity from the server. Future initialize() async { _setPracticeActivity( - _fetchExistingIncompleteActivity() ?? await _fetchNewActivity(), + await _fetchNewActivity(), ); } // if the user did the activity before but awhile ago and we don't have any // more target tokens, maybe we should give them the same activity again - PracticeActivityEvent? _fetchExistingIncompleteActivity() { - if (practiceActivities.isEmpty) { - return null; - } + // PracticeActivityEvent? _fetchExistingIncompleteActivity() { + // if (practiceActivities.isEmpty) { + // return null; + // } - final List incompleteActivities = - practiceActivities.where((element) => !element.isComplete).toList(); + // final List incompleteActivities = + // practiceActivities.where((element) => !element.isComplete).toList(); - // TODO - maybe check the user's xp for the tgtConstructs and decide if its relevant for them - // however, maybe we'd like to go ahead and give them the activity to get some data on our xp? - return incompleteActivities.firstOrNull; - } + // // TODO - maybe check the user's xp for the tgtConstructs and decide if its relevant for them + // // however, maybe we'd like to go ahead and give them the activity to get some data on our xp? + // return incompleteActivities.firstOrNull; + // } Future _fetchNewActivity([ ActivityQualityFeedback? activityFeedback, @@ -213,19 +213,19 @@ class MessagePracticeActivityCardState extends State { // save the record without awaiting to avoid blocking the UI // send a copy of the activity record to make sure its not overwritten by // the new activity - MatrixState.pangeaController.activityRecordController - .send(currentCompletionRecord!, currentActivity!) - .catchError( - (e, s) => ErrorHandler.logError( - e: e, - s: s, - m: 'Failed to save record', - data: { - 'record': currentCompletionRecord?.toJson(), - 'activity': currentActivity?.practiceActivity.toJson(), - }, - ), - ); + // MatrixState.pangeaController.activityRecordController + // .send(currentCompletionRecord!, currentActivity!) + // .catchError( + // (e, s) => ErrorHandler.logError( + // e: e, + // s: s, + // m: 'Failed to save record', + // data: { + // 'record': currentCompletionRecord?.toJson(), + // 'activity': currentActivity?.practiceActivity.toJson(), + // }, + // ), + // ); widget.overlayController.onActivityFinish(); From 50c8828dd658ce74110e93089b26f13328e94fdb Mon Sep 17 00:00:00 2001 From: ggurdin Date: Wed, 9 Oct 2024 11:49:48 -0400 Subject: [PATCH 2/3] use activity model instead of activity events --- ...actice_activity_generation_controller.dart | 13 ++++------- .../multiple_choice_activity.dart | 16 +++++-------- .../practice_activity_card.dart | 23 ++++++++++--------- 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/lib/pangea/controllers/practice_activity_generation_controller.dart b/lib/pangea/controllers/practice_activity_generation_controller.dart index bbe961ff8..0e021f205 100644 --- a/lib/pangea/controllers/practice_activity_generation_controller.dart +++ b/lib/pangea/controllers/practice_activity_generation_controller.dart @@ -22,8 +22,7 @@ import 'package:matrix/matrix.dart'; /// Represents an item in the completion cache. class _RequestCacheItem { MessageActivityRequest req; - - Future practiceActivityEvent; + PracticeActivityModel? practiceActivityEvent; _RequestCacheItem({ required this.req, @@ -103,7 +102,7 @@ class PracticeGenerationController { //TODO - allow return of activity content before sending the event // this requires some downstream changes to the way the event is handled - Future getPracticeActivity( + Future getPracticeActivity( MessageActivityRequest req, PangeaMessageEvent event, ) async { @@ -131,7 +130,7 @@ class PracticeGenerationController { return PracticeActivityEvent( event: existingEvent, timeline: event.timeline, - ); + ).practiceActivity; } } @@ -142,11 +141,9 @@ class PracticeGenerationController { debugPrint('Activity generated: ${res.activity!.toJson()}'); - final Future eventFuture = - _sendAndPackageEvent(res.activity!, event); - + _sendAndPackageEvent(res.activity!, event); _cache[cacheKey] = - _RequestCacheItem(req: req, practiceActivityEvent: eventFuture); + _RequestCacheItem(req: req, practiceActivityEvent: res.activity!); return _cache[cacheKey]!.practiceActivityEvent; } diff --git a/lib/pangea/widgets/practice_activity/multiple_choice_activity.dart b/lib/pangea/widgets/practice_activity/multiple_choice_activity.dart index d3b57dc45..7675e39d3 100644 --- a/lib/pangea/widgets/practice_activity/multiple_choice_activity.dart +++ b/lib/pangea/widgets/practice_activity/multiple_choice_activity.dart @@ -3,7 +3,6 @@ import 'dart:developer'; import 'package:collection/collection.dart'; import 'package:fluffychat/pangea/choreographer/widgets/choice_array.dart'; import 'package:fluffychat/pangea/controllers/my_analytics_controller.dart'; -import 'package:fluffychat/pangea/matrix_event_wrappers/practice_activity_event.dart'; import 'package:fluffychat/pangea/models/practice_activities.dart/practice_activity_model.dart'; import 'package:fluffychat/pangea/models/practice_activities.dart/practice_activity_record_model.dart'; import 'package:fluffychat/pangea/widgets/practice_activity/practice_activity_card.dart'; @@ -14,7 +13,7 @@ import 'package:flutter/material.dart'; /// The multiple choice activity view class MultipleChoiceActivity extends StatefulWidget { final MessagePracticeActivityCardState practiceCardController; - final PracticeActivityEvent? currentActivity; + final PracticeActivityModel? currentActivity; const MultipleChoiceActivity({ super.key, @@ -52,9 +51,8 @@ class MultipleChoiceActivityState extends State { return; } - final bool isCorrect = widget - .currentActivity!.practiceActivity.multipleChoice! - .isCorrect(value, index); + final bool isCorrect = + widget.currentActivity!.multipleChoice!.isCorrect(value, index); currentRecordModel?.addResponse( text: value, @@ -74,15 +72,14 @@ class MultipleChoiceActivityState extends State { widget.practiceCardController.widget.pangeaMessageEvent.eventId, roomId: widget.practiceCardController.widget.pangeaMessageEvent.room.id, constructs: currentRecordModel!.latestResponse!.toUses( - widget.practiceCardController.currentActivity!.practiceActivity, + widget.practiceCardController.currentActivity!, widget.practiceCardController.metadata, ), ), ); // If the selected choice is correct, send the record and get the next activity - if (widget.currentActivity!.practiceActivity.multipleChoice! - .isCorrect(value, index)) { + if (widget.currentActivity!.multipleChoice!.isCorrect(value, index)) { widget.practiceCardController.onActivityFinish(); } @@ -93,8 +90,7 @@ class MultipleChoiceActivityState extends State { @override Widget build(BuildContext context) { - final PracticeActivityModel? practiceActivity = - widget.currentActivity?.practiceActivity; + final PracticeActivityModel? practiceActivity = widget.currentActivity; if (practiceActivity == null) { return const SizedBox(); diff --git a/lib/pangea/widgets/practice_activity/practice_activity_card.dart b/lib/pangea/widgets/practice_activity/practice_activity_card.dart index 8e849a6f0..34a077663 100644 --- a/lib/pangea/widgets/practice_activity/practice_activity_card.dart +++ b/lib/pangea/widgets/practice_activity/practice_activity_card.dart @@ -8,6 +8,7 @@ import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_representation_ev import 'package:fluffychat/pangea/matrix_event_wrappers/practice_activity_event.dart'; import 'package:fluffychat/pangea/models/analytics/constructs_model.dart'; import 'package:fluffychat/pangea/models/practice_activities.dart/message_activity_request.dart'; +import 'package:fluffychat/pangea/models/practice_activities.dart/practice_activity_model.dart'; import 'package:fluffychat/pangea/models/practice_activities.dart/practice_activity_record_model.dart'; import 'package:fluffychat/pangea/utils/bot_style.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart'; @@ -42,7 +43,7 @@ class PracticeActivityCard extends StatefulWidget { } class MessagePracticeActivityCardState extends State { - PracticeActivityEvent? currentActivity; + PracticeActivityModel? currentActivity; PracticeActivityRecordModel? currentCompletionRecord; bool fetchingActivity = false; @@ -70,7 +71,7 @@ class MessagePracticeActivityCardState extends State { if (mounted) setState(() => fetchingActivity = value); } - void _setPracticeActivity(PracticeActivityEvent? activity) { + void _setPracticeActivity(PracticeActivityModel? activity) { //set elsewhere but just in case fetchingActivity = false; @@ -83,10 +84,10 @@ class MessagePracticeActivityCardState extends State { //make new completion record currentCompletionRecord = PracticeActivityRecordModel( - question: activity.practiceActivity.question, + question: activity.question, ); - widget.overlayController.setSelectedSpan(activity.practiceActivity); + widget.overlayController.setSelectedSpan(activity); } /// Get an existing activity if there is one. @@ -112,7 +113,7 @@ class MessagePracticeActivityCardState extends State { // return incompleteActivities.firstOrNull; // } - Future _fetchNewActivity([ + Future _fetchNewActivity([ ActivityQualityFeedback? activityFeedback, ]) async { try { @@ -134,7 +135,7 @@ class MessagePracticeActivityCardState extends State { return null; } - final PracticeActivityEvent? ourNewActivity = await pangeaController + final PracticeActivityModel? ourNewActivity = await pangeaController .practiceGenerationController .getPracticeActivity( MessageActivityRequest( @@ -203,7 +204,7 @@ class MessagePracticeActivityCardState extends State { // NOTE - multiple choice activity is handling adding these to analytics await targetTokensController.updateTokensWithConstructs( currentCompletionRecord!.usesForAllResponses( - currentActivity!.practiceActivity, + currentActivity!, metadata, ), context, @@ -235,7 +236,7 @@ class MessagePracticeActivityCardState extends State { _fetchNewActivity(), ]); - _setPracticeActivity(result.last as PracticeActivityEvent?); + _setPracticeActivity(result.last as PracticeActivityModel?); } catch (e, s) { _setPracticeActivity(null); debugger(when: kDebugMode); @@ -262,7 +263,7 @@ class MessagePracticeActivityCardState extends State { _fetchNewActivity( ActivityQualityFeedback( feedbackText: feedback, - badActivity: currentActivity!.practiceActivity, + badActivity: currentActivity!, ), ).then((activity) { _setPracticeActivity(activity); @@ -300,7 +301,7 @@ class MessagePracticeActivityCardState extends State { // return sizedbox with height of 80 return const SizedBox(height: 80); } - switch (currentActivity!.practiceActivity.activityType) { + switch (currentActivity!.activityType) { case ActivityTypeEnum.multipleChoice: return MultipleChoiceActivity( practiceCardController: this, @@ -311,7 +312,7 @@ class MessagePracticeActivityCardState extends State { e: Exception('Unknown activity type'), m: 'Unknown activity type', data: { - 'activityType': currentActivity!.practiceActivity.activityType, + 'activityType': currentActivity!.activityType, }, ); return Text( From 4b2c5bc2134700087f896aa53606059a6126b1ae Mon Sep 17 00:00:00 2001 From: ggurdin Date: Wed, 9 Oct 2024 11:51:51 -0400 Subject: [PATCH 3/3] remove unused commented out code --- .../practice_activity_card.dart | 32 ------------------- 1 file changed, 32 deletions(-) diff --git a/lib/pangea/widgets/practice_activity/practice_activity_card.dart b/lib/pangea/widgets/practice_activity/practice_activity_card.dart index 34a077663..9e0ee3b01 100644 --- a/lib/pangea/widgets/practice_activity/practice_activity_card.dart +++ b/lib/pangea/widgets/practice_activity/practice_activity_card.dart @@ -98,21 +98,6 @@ class MessagePracticeActivityCardState extends State { ); } - // if the user did the activity before but awhile ago and we don't have any - // more target tokens, maybe we should give them the same activity again - // PracticeActivityEvent? _fetchExistingIncompleteActivity() { - // if (practiceActivities.isEmpty) { - // return null; - // } - - // final List incompleteActivities = - // practiceActivities.where((element) => !element.isComplete).toList(); - - // // TODO - maybe check the user's xp for the tgtConstructs and decide if its relevant for them - // // however, maybe we'd like to go ahead and give them the activity to get some data on our xp? - // return incompleteActivities.firstOrNull; - // } - Future _fetchNewActivity([ ActivityQualityFeedback? activityFeedback, ]) async { @@ -211,23 +196,6 @@ class MessagePracticeActivityCardState extends State { widget.pangeaMessageEvent, ); - // save the record without awaiting to avoid blocking the UI - // send a copy of the activity record to make sure its not overwritten by - // the new activity - // MatrixState.pangeaController.activityRecordController - // .send(currentCompletionRecord!, currentActivity!) - // .catchError( - // (e, s) => ErrorHandler.logError( - // e: e, - // s: s, - // m: 'Failed to save record', - // data: { - // 'record': currentCompletionRecord?.toJson(), - // 'activity': currentActivity?.practiceActivity.toJson(), - // }, - // ), - // ); - widget.overlayController.onActivityFinish(); //