|
|
|
|
@ -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});
|
|
|
|
|
}
|
|
|
|
|
|