From 7ab96467b390e952d2f78ef9563b311b7365bf56 Mon Sep 17 00:00:00 2001 From: ggurdin <46800240+ggurdin@users.noreply.github.com> Date: Mon, 15 Sep 2025 12:07:54 -0400 Subject: [PATCH] fix: fix calculation of completed activities (#3986) --- .../course_plan_room_extension.dart | 40 +++++++------------ 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/lib/pangea/course_plans/course_plan_room_extension.dart b/lib/pangea/course_plans/course_plan_room_extension.dart index b5f5016fb..c11f7fc75 100644 --- a/lib/pangea/course_plans/course_plan_room_extension.dart +++ b/lib/pangea/course_plans/course_plan_room_extension.dart @@ -104,31 +104,17 @@ extension CoursePlanRoomExtension on Room { throw Exception('Topic not found'); } - final numTwoPersonActivities = course - .loadedTopics[topicIndex].loadedActivities - .where((a) => a.req.numberOfParticipants <= 2) - .length; + final topicActivities = course.loadedTopics[topicIndex].loadedActivities; + final topicActivityIds = topicActivities.map((a) => a.activityId).toSet(); + final numTwoPersonActivities = + topicActivities.where((a) => a.req.numberOfParticipants <= 2).length; - return state.completedActivities.length >= numTwoPersonActivities; + final completedTopicActivities = + state.completedActivities.intersection(topicActivityIds); + + return completedTopicActivities.length >= numTwoPersonActivities; } - CourseTopicModel? currentTopic( - String userID, - CoursePlanModel course, - ) { - if (coursePlan == null) return null; - if (course.loadedTopics.isEmpty) return null; - - final index = course.loadedTopics.indexWhere( - (t) => !_hasCompletedTopic(userID, t, course), - ); - - return index == -1 ? null : course.loadedTopics[index]; - } - - CourseTopicModel? ownCurrentTopic(CoursePlanModel course) => - currentTopic(client.userID!, course); - int currentTopicIndex( String userID, CoursePlanModel course, @@ -136,11 +122,13 @@ extension CoursePlanRoomExtension on Room { if (coursePlan == null) return -1; if (course.loadedTopics.isEmpty) return -1; - final index = course.loadedTopics.indexWhere( - (t) => !_hasCompletedTopic(userID, t, course), - ); + for (int i = 0; i < course.loadedTopics.length; i++) { + if (!_hasCompletedTopic(userID, course.loadedTopics[i], course)) { + return i; + } + } - return index == -1 ? 0 : index; + return 0; } int ownCurrentTopicIndex(CoursePlanModel course) =>