fix: don't consider an activity finished if no assigned roles are finished (#3728)

This commit is contained in:
ggurdin 2025-08-13 14:34:54 -04:00 committed by GitHub
parent 34e1229835
commit 45052a6b01
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 4 deletions

View file

@ -252,12 +252,25 @@ extension ActivityRoomExtension on Room {
}
}
Map<String, ActivityRoleModel>? get assignedRoles {
final roles = activityRoles?.roles;
if (roles == null) return null;
final participants = getParticipants();
return Map.fromEntries(
roles.entries.where(
(r) => participants.any(
(p) => p.id == r.value.userId && p.membership == Membership.join,
),
),
);
}
ActivityRoleModel? get ownRole => activityRoles?.role(client.userID!);
int get remainingRoles {
final availableRoles = activityPlan!.roles;
final assignedRoles = activityRoles?.roles ?? {};
return max(0, availableRoles.length - assignedRoles.length);
return max(0, availableRoles.length - (assignedRoles?.length ?? 0));
}
bool get showActivityChatUI {
@ -286,6 +299,8 @@ extension ActivityRoomExtension on Room {
);
if (roles == null || roles.isEmpty) return false;
if (!roles.any((r) => r.isFinished)) return false;
return roles.every((r) {
if (r.isFinished) return true;

View file

@ -23,7 +23,7 @@ class ActivityStateEvent extends StatelessWidget {
try {
final activity = ActivityPlanModel.fromJson(event.content);
final availableRoles = event.room.activityPlan!.roles;
final assignedRoles = event.room.activityRoles?.roles ?? {};
final assignedRoles = event.room.assignedRoles ?? {};
final remainingMembers = event.room.getParticipants().where(
(p) => !assignedRoles.values.any((r) => r.userId == p.id),

View file

@ -36,7 +36,7 @@ class ActivityUnfinishedStatusMessageState
final completed = widget.room.hasCompletedActivity;
final availableRoles = widget.room.activityPlan!.roles;
final assignedRoles = widget.room.activityRoles?.roles ?? {};
final assignedRoles = widget.room.assignedRoles ?? {};
final remainingRoles = availableRoles.length - assignedRoles.length;
final unassignedIds = availableRoles.keys