fix: fix calculation of completed activities (#3986)

pull/2245/head
ggurdin 1 month ago committed by GitHub
parent 29315990e3
commit 7ab96467b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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;
}
CourseTopicModel? currentTopic(
String userID,
CoursePlanModel course,
) {
if (coursePlan == null) return null;
if (course.loadedTopics.isEmpty) return null;
final completedTopicActivities =
state.completedActivities.intersection(topicActivityIds);
final index = course.loadedTopics.indexWhere(
(t) => !_hasCompletedTopic(userID, t, course),
);
return index == -1 ? null : course.loadedTopics[index];
return completedTopicActivities.length >= numTwoPersonActivities;
}
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) =>

Loading…
Cancel
Save