Merge branch 'new-merge' of https://github.com/pangeachat/client into new-merge

pull/1186/head
Kelrap 1 year ago
commit 1f73058fb4

@ -148,7 +148,28 @@ class MyAnalyticsController extends BaseController {
} }
} }
Completer<void>? _updateCompleter;
Future<void> updateAnalytics() async { Future<void> updateAnalytics() async {
if (!(_updateCompleter?.isCompleted ?? true)) {
await _updateCompleter!.future;
return;
}
_updateCompleter = Completer<void>();
try {
await _updateAnalytics();
} catch (err, s) {
ErrorHandler.logError(
e: err,
m: "Failed to update analytics",
s: s,
);
} finally {
_updateCompleter?.complete();
_updateCompleter = null;
}
}
Future<void> _updateAnalytics() async {
// top level analytics sending function. Send analytics // top level analytics sending function. Send analytics
// for each type of analytics event // for each type of analytics event
// to each of the applicable analytics rooms // to each of the applicable analytics rooms
@ -237,7 +258,11 @@ class MyAnalyticsController extends BaseController {
} }
// send the analytics data to the analytics room // send the analytics data to the analytics room
if (analyticsContent.isEmpty) return; // if there is no data to send, don't send an event,
// unless no events have been sent yet. In that case, send an event
// with no data to indicate that the the system checked for data
// and found none, so the system doesn't repeatedly check for data
if (analyticsContent.isEmpty && lastUpdated != null) return;
await AnalyticsEvent.sendEvent( await AnalyticsEvent.sendEvent(
analyticsRoom, analyticsRoom,
type, type,

Loading…
Cancel
Save