Skip to content

Commit

Permalink
Merge pull request #1017 from pangeachat/xp-fix
Browse files Browse the repository at this point in the history
manage getting construct uses with category 'other'
  • Loading branch information
ggurdin authored Nov 15, 2024
2 parents 50906f9 + 62bdde9 commit 653ee5f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void main() async {

// #Pangea
try {
await dotenv.load(fileName: ".env.local_choreo");
await dotenv.load(fileName: ".env");
} catch (e) {
Logs().e('Failed to load .env file', e);
}
Expand Down
24 changes: 23 additions & 1 deletion lib/pangea/models/analytics/construct_list_model.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:math';

import 'package:collection/collection.dart';
import 'package:fluffychat/pangea/enum/construct_type_enum.dart';
import 'package:fluffychat/pangea/models/analytics/construct_use_model.dart';
import 'package:fluffychat/pangea/models/analytics/constructs_model.dart';
Expand Down Expand Up @@ -127,7 +128,28 @@ class ConstructListModel {
}

ConstructUses? getConstructUses(ConstructIdentifier identifier) {
return _constructMap[identifier.string];
final partialKey = "${identifier.lemma}-${identifier.type.string}";

if (_constructMap.containsKey(identifier.string)) {
// try to get construct use entry with full ID key
return _constructMap[identifier.string];
} else if (identifier.category.toLowerCase() == "other") {
// if the category passed to this function is "other", return the first
// construct use entry that starts with the partial key
return _constructMap.entries
.firstWhereOrNull((entry) => entry.key.startsWith(partialKey))
?.value;
} else {
// if the category passed to this function is not "other", return the first
// construct use entry that starts with the partial key and ends with "other"
return _constructMap.entries
.firstWhereOrNull(
(entry) =>
entry.key.startsWith(partialKey) &&
entry.key.toLowerCase().endsWith("other"),
)
?.value;
}
}

List<ConstructUses> constructList({ConstructTypeEnum? type}) => _constructList
Expand Down
4 changes: 1 addition & 3 deletions lib/pangea/models/analytics/constructs_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ class OneConstructUse {
useType: ConstructUseTypeUtil.fromString(json['useType']),
lemma: json['lemma'],
form: json['form'],
category: constructType == ConstructTypeEnum.morph
? getCategory(json)
: "Other",
category: getCategory(json),
constructType: constructType,
id: json['id'],
metadata: ConstructUseMetaData(
Expand Down
13 changes: 4 additions & 9 deletions lib/pangea/models/pangea_token_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,11 @@ class PangeaToken {

List<ConstructUses> get constructs => _constructIDs
.map(
(id) =>
MatrixState.pangeaController.getAnalytics.constructListModel
.getConstructUses(id) ??
ConstructUses(
lemma: id.lemma,
constructType: id.type,
category: id.category,
uses: [],
),
(id) => MatrixState.pangeaController.getAnalytics.constructListModel
.getConstructUses(id),
)
.where((construct) => construct != null)
.cast<ConstructUses>()
.toList();

Map<String, dynamic> toServerChoiceTokenWithXP() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ class ConstructIdentifier {

return other is ConstructIdentifier &&
other.lemma == lemma &&
other.type == type;
other.type == type &&
(category == other.category ||
category.toLowerCase() == "other" ||
other.category.toLowerCase() == "other");
}

@override
Expand Down
30 changes: 18 additions & 12 deletions lib/pangea/widgets/chat/message_selection_overlay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MessageSelectionOverlay extends StatefulWidget {
final Event? _nextEvent;
final Event? _prevEvent;
final PangeaMessageEvent _pangeaMessageEvent;
final PangeaToken? _selectedTokenOnInitialization;
final PangeaToken? _initialSelectedToken;

const MessageSelectionOverlay({
required this.chatController,
Expand All @@ -43,7 +43,7 @@ class MessageSelectionOverlay extends StatefulWidget {
required Event? nextEvent,
required Event? prevEvent,
super.key,
}) : _selectedTokenOnInitialization = selectedTokenOnInitialization,
}) : _initialSelectedToken = selectedTokenOnInitialization,
_pangeaMessageEvent = pangeaMessageEvent,
_nextEvent = nextEvent,
_prevEvent = prevEvent,
Expand Down Expand Up @@ -78,16 +78,22 @@ class MessageOverlayController extends State<MessageSelectionOverlay>

bool get showToolbarButtons => !widget._pangeaMessageEvent.isAudioMessage;

PangeaToken? get selectedTargetTokenForWordMeaning =>
widget._selectedTokenOnInitialization != null &&
!(messageAnalyticsEntry?.isTokenInHiddenWordActivity(
widget._selectedTokenOnInitialization!,
) ??
false) &&
widget._selectedTokenOnInitialization!
.shouldDoActivity(ActivityTypeEnum.wordMeaning)
? widget._selectedTokenOnInitialization
: null;
PangeaToken? get selectedTargetTokenForWordMeaning {
if (widget._initialSelectedToken == null || messageAnalyticsEntry == null) {
return null;
}

final isInActivity = messageAnalyticsEntry!.isTokenInHiddenWordActivity(
widget._initialSelectedToken!,
);

final shouldDoActivity = widget._initialSelectedToken!
.shouldDoActivity(ActivityTypeEnum.wordMeaning);

return isInActivity && shouldDoActivity
? widget._initialSelectedToken
: null;
}

List<PangeaToken>? tokens;

Expand Down

0 comments on commit 653ee5f

Please sign in to comment.