From 0aaf2d6bcad05aa1b7b330c08bd42f06e37ac7fd Mon Sep 17 00:00:00 2001 From: ggurdin <46800240+ggurdin@users.noreply.github.com> Date: Mon, 13 Jan 2025 11:57:00 -0500 Subject: [PATCH] fix: prevent proportion from being negative. If negative, return 0 (#1418) --- .../pangea_message_event.dart | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/pangea/matrix_event_wrappers/pangea_message_event.dart b/lib/pangea/matrix_event_wrappers/pangea_message_event.dart index 1f4c04f36..1e8315ddb 100644 --- a/lib/pangea/matrix_event_wrappers/pangea_message_event.dart +++ b/lib/pangea/matrix_event_wrappers/pangea_message_event.dart @@ -567,22 +567,22 @@ class PangeaMessageEvent { messageDisplayRepresentation?.tokens == null) { return 1; } - final int total = messageDisplayRepresentation!.tokens! - .where( - (token) => - token.isActivityBasicallyEligible(ActivityTypeEnum.wordMeaning), - ) - .length; - final int toDo = messageDisplayRepresentation!.tokens! + final eligibleTokens = messageDisplayRepresentation!.tokens!.where( + (token) => + token.isActivityBasicallyEligible(ActivityTypeEnum.wordMeaning), + ); + + final int total = eligibleTokens.length; + + final int toDo = eligibleTokens .where( (token) => token.didActivitySuccessfully(ActivityTypeEnum.wordMeaning), ) .length; - final double proportion = - (total - toDo) / messageDisplayRepresentation!.tokens!.length; + final double proportion = (total - toDo) / total; if (proportion < 0) { debugger(when: kDebugMode); @@ -595,6 +595,7 @@ class PangeaMessageEvent { "tokens": messageDisplayRepresentation!.tokens, }, ); + return 0; } return proportion;