when sending analytics to the server at logout, don't update the getAnalytics stream afterwards
This commit is contained in:
parent
cb333b6802
commit
23b6dd08b5
4 changed files with 27 additions and 10 deletions
|
|
@ -22,7 +22,7 @@ import 'package:sentry_flutter/sentry_flutter.dart';
|
|||
class GetAnalyticsController {
|
||||
late PangeaController _pangeaController;
|
||||
final List<AnalyticsCacheEntry> _cache = [];
|
||||
StreamSubscription<AnalyticsUpdateType>? _analyticsUpdateSubscription;
|
||||
StreamSubscription<AnalyticsUpdate>? _analyticsUpdateSubscription;
|
||||
CachedStreamController<List<OneConstructUse>> analyticsStream =
|
||||
CachedStreamController<List<OneConstructUse>>();
|
||||
|
||||
|
|
@ -87,8 +87,9 @@ class GetAnalyticsController {
|
|||
prevXP = null;
|
||||
}
|
||||
|
||||
Future<void> onAnalyticsUpdate(AnalyticsUpdateType type) async {
|
||||
if (type == AnalyticsUpdateType.server) {
|
||||
Future<void> onAnalyticsUpdate(AnalyticsUpdate analyticsUpdate) async {
|
||||
if (analyticsUpdate.isLogout) return;
|
||||
if (analyticsUpdate.type == AnalyticsUpdateType.server) {
|
||||
await getConstructs(forceUpdate: true);
|
||||
}
|
||||
updateAnalyticsStream();
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ enum AnalyticsUpdateType { server, local }
|
|||
/// 2) constructs used by the user, both in sending messages and doing practice activities
|
||||
class MyAnalyticsController extends BaseController<AnalyticsStream> {
|
||||
late PangeaController _pangeaController;
|
||||
CachedStreamController<AnalyticsUpdateType> analyticsUpdateStream =
|
||||
CachedStreamController<AnalyticsUpdateType>();
|
||||
CachedStreamController<AnalyticsUpdate> analyticsUpdateStream =
|
||||
CachedStreamController<AnalyticsUpdate>();
|
||||
StreamSubscription<AnalyticsStream>? _analyticsStream;
|
||||
Timer? _updateTimer;
|
||||
|
||||
|
|
@ -237,7 +237,9 @@ class MyAnalyticsController extends BaseController<AnalyticsStream> {
|
|||
final int newLevel = _pangeaController.analytics.level;
|
||||
newLevel > prevLevel
|
||||
? sendLocalAnalyticsToAnalyticsRoom()
|
||||
: analyticsUpdateStream.add(AnalyticsUpdateType.local);
|
||||
: analyticsUpdateStream.add(
|
||||
AnalyticsUpdate(AnalyticsUpdateType.local),
|
||||
);
|
||||
}
|
||||
|
||||
/// Clears the local cache of recently sent constructs. Called before updating analytics
|
||||
|
|
@ -281,7 +283,9 @@ class MyAnalyticsController extends BaseController<AnalyticsStream> {
|
|||
/// for the completion of the previous update and returns. Otherwise, it creates a new [_updateCompleter] and
|
||||
/// proceeds with the update process. If the update is successful, it clears any messages that were received
|
||||
/// since the last update and notifies the [analyticsUpdateStream].
|
||||
Future<void> sendLocalAnalyticsToAnalyticsRoom() async {
|
||||
Future<void> sendLocalAnalyticsToAnalyticsRoom({
|
||||
onLogout = false,
|
||||
}) async {
|
||||
if (_pangeaController.matrixState.client.userID == null) return;
|
||||
if (!(_updateCompleter?.isCompleted ?? true)) {
|
||||
await _updateCompleter!.future;
|
||||
|
|
@ -293,7 +297,12 @@ class MyAnalyticsController extends BaseController<AnalyticsStream> {
|
|||
clearMessagesSinceUpdate();
|
||||
|
||||
lastUpdated = DateTime.now();
|
||||
analyticsUpdateStream.add(AnalyticsUpdateType.server);
|
||||
analyticsUpdateStream.add(
|
||||
AnalyticsUpdate(
|
||||
AnalyticsUpdateType.server,
|
||||
isLogout: onLogout,
|
||||
),
|
||||
);
|
||||
} catch (err, s) {
|
||||
ErrorHandler.logError(
|
||||
e: err,
|
||||
|
|
@ -340,3 +349,10 @@ class AnalyticsStream {
|
|||
required this.constructs,
|
||||
});
|
||||
}
|
||||
|
||||
class AnalyticsUpdate {
|
||||
final AnalyticsUpdateType type;
|
||||
final bool isLogout;
|
||||
|
||||
AnalyticsUpdate(this.type, {this.isLogout = false});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ void pLogoutAction(BuildContext context, {bool? isDestructiveAction}) async {
|
|||
|
||||
// before wiping out locally cached construct data, save it to the server
|
||||
await MatrixState.pangeaController.myAnalytics
|
||||
.sendLocalAnalyticsToAnalyticsRoom();
|
||||
.sendLocalAnalyticsToAnalyticsRoom(onLogout: true);
|
||||
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ description: Learn a language while texting your friends.
|
|||
# Pangea#
|
||||
publish_to: none
|
||||
# On version bump also increase the build number for F-Droid
|
||||
version: 1.21.7+3547
|
||||
version: 1.22.3+3553
|
||||
|
||||
environment:
|
||||
sdk: ">=3.0.0 <4.0.0"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue