feat: expose construct level up stream
This commit is contained in:
parent
f3e57f5f68
commit
16fbc4a52e
4 changed files with 67 additions and 16 deletions
|
|
@ -1,23 +1,9 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:just_audio/just_audio.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:scroll_to_index/scroll_to_index.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:universal_html/html.dart' as html;
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/config/setting_keys.dart';
|
||||
import 'package:fluffychat/config/themes.dart';
|
||||
|
|
@ -88,6 +74,19 @@ import 'package:fluffychat/widgets/adaptive_dialogs/show_text_input_dialog.dart'
|
|||
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:fluffychat/widgets/share_scaffold_dialog.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:just_audio/just_audio.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:scroll_to_index/scroll_to_index.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:universal_html/html.dart' as html;
|
||||
|
||||
import '../../utils/localized_exception_extension.dart';
|
||||
import 'send_file_dialog.dart';
|
||||
import 'send_location_dialog.dart';
|
||||
|
|
@ -192,6 +191,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
StreamSubscription? _levelSubscription;
|
||||
StreamSubscription? _constructsSubscription;
|
||||
StreamSubscription? _tokensSubscription;
|
||||
StreamSubscription? _constructLevelSubscription;
|
||||
|
||||
StreamSubscription? _botAudioSubscription;
|
||||
final timelineUpdateNotifier = _TimelineUpdateNotifier();
|
||||
|
|
@ -529,6 +529,12 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
choreographer.timesDismissedIT.addListener(_onCloseIT);
|
||||
final updater = Matrix.of(context).analyticsDataService.updateDispatcher;
|
||||
|
||||
_constructLevelSubscription =
|
||||
updater.constructLevelUpdateStream.stream.listen((entry) {
|
||||
debugPrint(
|
||||
"Construct level update received: ${entry.key.string} -> ${entry.value}",
|
||||
);
|
||||
});
|
||||
_levelSubscription = updater.levelUpdateStream.stream.listen(_onLevelUp);
|
||||
|
||||
_constructsSubscription =
|
||||
|
|
@ -800,6 +806,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
_levelSubscription?.cancel();
|
||||
_botAudioSubscription?.cancel();
|
||||
_constructsSubscription?.cancel();
|
||||
_constructLevelSubscription?.cancel();
|
||||
_tokensSubscription?.cancel();
|
||||
_router.routeInformationProvider.removeListener(_onRouteChanged);
|
||||
choreographer.timesDismissedIT.removeListener(_onCloseIT);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/pangea/analytics_data/analytics_database.dart';
|
||||
import 'package:fluffychat/pangea/analytics_data/analytics_database_builder.dart';
|
||||
import 'package:fluffychat/pangea/analytics_data/analytics_sync_controller.dart';
|
||||
|
|
@ -19,9 +17,11 @@ import 'package:fluffychat/pangea/analytics_misc/constructs_event.dart';
|
|||
import 'package:fluffychat/pangea/analytics_misc/constructs_model.dart';
|
||||
import 'package:fluffychat/pangea/analytics_settings/analytics_settings_extension.dart';
|
||||
import 'package:fluffychat/pangea/constructs/construct_identifier.dart';
|
||||
import 'package:fluffychat/pangea/constructs/construct_level_enum.dart';
|
||||
import 'package:fluffychat/pangea/languages/language_model.dart';
|
||||
import 'package:fluffychat/pangea/user/analytics_profile_model.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
class _AnalyticsClient {
|
||||
final Client client;
|
||||
|
|
@ -442,6 +442,22 @@ class AnalyticsDataService {
|
|||
events.add(MorphUnlockedEvent(newUnlockedMorphs));
|
||||
}
|
||||
|
||||
for (final entry in newConstructs.entries) {
|
||||
final prevConstruct = prevConstructs[entry.key];
|
||||
if (prevConstruct == null) continue;
|
||||
|
||||
final prevLevel = prevConstruct.lemmaCategory;
|
||||
final newLevel = entry.value.lemmaCategory;
|
||||
if (newLevel.xpNeeded > prevLevel.xpNeeded) {
|
||||
events.add(
|
||||
ConstructLevelUpEvent(
|
||||
entry.key,
|
||||
newLevel,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (update.blockedConstruct != null) {
|
||||
events.add(ConstructBlockedEvent(update.blockedConstruct!));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import 'package:fluffychat/pangea/analytics_data/analytics_data_service.dart';
|
|||
import 'package:fluffychat/pangea/analytics_data/analytics_update_events.dart';
|
||||
import 'package:fluffychat/pangea/analytics_misc/constructs_model.dart';
|
||||
import 'package:fluffychat/pangea/constructs/construct_identifier.dart';
|
||||
import 'package:fluffychat/pangea/constructs/construct_level_enum.dart';
|
||||
import 'package:fluffychat/pangea/lemmas/user_set_lemma_info.dart';
|
||||
|
||||
class LevelUpdate {
|
||||
|
|
@ -46,6 +47,10 @@ class AnalyticsUpdateDispatcher {
|
|||
final StreamController<Set<ConstructIdentifier>> newConstructsStream =
|
||||
StreamController<Set<ConstructIdentifier>>.broadcast();
|
||||
|
||||
final StreamController<MapEntry<ConstructIdentifier, ConstructLevelEnum>>
|
||||
constructLevelUpdateStream = StreamController<
|
||||
MapEntry<ConstructIdentifier, ConstructLevelEnum>>.broadcast();
|
||||
|
||||
final StreamController<MapEntry<ConstructIdentifier, UserSetLemmaInfo>>
|
||||
_lemmaInfoUpdateStream = StreamController<
|
||||
MapEntry<ConstructIdentifier, UserSetLemmaInfo>>.broadcast();
|
||||
|
|
@ -58,6 +63,7 @@ class AnalyticsUpdateDispatcher {
|
|||
unlockedConstructsStream.close();
|
||||
levelUpdateStream.close();
|
||||
_lemmaInfoUpdateStream.close();
|
||||
constructLevelUpdateStream.close();
|
||||
}
|
||||
|
||||
Stream<UserSetLemmaInfo> lemmaUpdateStream(
|
||||
|
|
@ -101,6 +107,9 @@ class AnalyticsUpdateDispatcher {
|
|||
case final ConstructBlockedEvent e:
|
||||
_onBlockedConstruct(e.blockedConstruct);
|
||||
break;
|
||||
case final ConstructLevelUpEvent e:
|
||||
_onConstructLevelUp(e.constructId, e.level);
|
||||
break;
|
||||
case final NewConstructsEvent e:
|
||||
_onNewConstruct(e.newConstructs);
|
||||
break;
|
||||
|
|
@ -144,6 +153,15 @@ class AnalyticsUpdateDispatcher {
|
|||
constructUpdateStream.add(update);
|
||||
}
|
||||
|
||||
void _onConstructLevelUp(
|
||||
ConstructIdentifier constructId,
|
||||
ConstructLevelEnum level,
|
||||
) {
|
||||
constructLevelUpdateStream.add(
|
||||
MapEntry(constructId, level),
|
||||
);
|
||||
}
|
||||
|
||||
void _onNewConstruct(Set<ConstructIdentifier> constructIds) {
|
||||
if (constructIds.isEmpty) return;
|
||||
newConstructsStream.add(constructIds);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:fluffychat/pangea/constructs/construct_identifier.dart';
|
||||
import 'package:fluffychat/pangea/constructs/construct_level_enum.dart';
|
||||
|
||||
sealed class AnalyticsUpdateEvent {}
|
||||
|
||||
|
|
@ -13,6 +14,15 @@ class MorphUnlockedEvent extends AnalyticsUpdateEvent {
|
|||
MorphUnlockedEvent(this.unlocked);
|
||||
}
|
||||
|
||||
class ConstructLevelUpEvent extends AnalyticsUpdateEvent {
|
||||
final ConstructIdentifier constructId;
|
||||
final ConstructLevelEnum level;
|
||||
ConstructLevelUpEvent(
|
||||
this.constructId,
|
||||
this.level,
|
||||
);
|
||||
}
|
||||
|
||||
class XPGainedEvent extends AnalyticsUpdateEvent {
|
||||
final int points;
|
||||
final String? targetID;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue