Merge pull request #836 from pangeachat/logout-analytics-stream-fix

when sending analytics to the server at logout, don't update the getA…
pull/1428/head
ggurdin 1 year ago committed by GitHub
commit 17261600d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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.22.2+3552
version: 1.22.3+3553
environment:
sdk: ">=3.0.0 <4.0.0"

Loading…
Cancel
Save