@ -11,6 +11,7 @@ import 'package:fluffychat/pangea/models/analytics/summary_analytics_model.dart'
import ' package:fluffychat/pangea/utils/error_handler.dart ' ;
import ' package:fluffychat/pangea/utils/error_handler.dart ' ;
import ' package:flutter/foundation.dart ' ;
import ' package:flutter/foundation.dart ' ;
import ' package:matrix/matrix.dart ' ;
import ' package:matrix/matrix.dart ' ;
import ' package:sentry_flutter/sentry_flutter.dart ' ;
import ' ../extensions/client_extension/client_extension.dart ' ;
import ' ../extensions/client_extension/client_extension.dart ' ;
import ' ../extensions/pangea_room_extension/pangea_room_extension.dart ' ;
import ' ../extensions/pangea_room_extension/pangea_room_extension.dart ' ;
@ -113,6 +114,7 @@ class MyAnalyticsController {
/ / adds an event ID to the cache of un - added event IDs
/ / adds an event ID to the cache of un - added event IDs
/ / if the event IDs isn ' t already added
/ / if the event IDs isn ' t already added
void addMessageSinceUpdate ( String eventId ) {
void addMessageSinceUpdate ( String eventId ) {
try {
final List < String > currentCache = messagesSinceUpdate ;
final List < String > currentCache = messagesSinceUpdate ;
if ( ! currentCache . contains ( eventId ) ) {
if ( ! currentCache . contains ( eventId ) ) {
currentCache . add ( eventId ) ;
currentCache . add ( eventId ) ;
@ -128,6 +130,21 @@ class MyAnalyticsController {
debugPrint ( " reached max messages, updating " ) ;
debugPrint ( " reached max messages, updating " ) ;
updateAnalytics ( ) ;
updateAnalytics ( ) ;
}
}
} catch ( exception , stackTrace ) {
ErrorHandler . logError (
e: PangeaWarningError ( " Failed to add message since update: $ exception " ) ,
s: stackTrace ,
m: ' Failed to add message since update for eventId: $ eventId '
) ;
Sentry . captureException (
exception ,
stackTrace: stackTrace ,
withScope: ( scope ) {
scope . setExtra ( ' extra_info ' , ' Failed during addMessageSinceUpdate with eventId: $ eventId ' ) ;
scope . setTag ( ' where ' , ' addMessageSinceUpdate ' ) ;
}
) ;
}
}
}
/ / called before updating analytics
/ / called before updating analytics
@ -143,11 +160,14 @@ class MyAnalyticsController {
/ / it ' s possible for this cache to be invalid or deleted
/ / it ' s possible for this cache to be invalid or deleted
/ / It ' s a proxy measure for messages sent since last update
/ / It ' s a proxy measure for messages sent since last update
List < String > get messagesSinceUpdate {
List < String > get messagesSinceUpdate {
try {
Logs ( ) . d ( ' Reading messages since update from local storage ' ) ;
final dynamic locallySaved = _pangeaController . pStoreService . read (
final dynamic locallySaved = _pangeaController . pStoreService . read (
PLocalKey . messagesSinceUpdate ,
PLocalKey . messagesSinceUpdate ,
local: true ,
local: true ,
) ;
) ;
if ( locallySaved = = null ) {
if ( locallySaved = = null ) {
Logs ( ) . d ( ' No locally saved messages found, initializing empty list. ' ) ;
_pangeaController . pStoreService . save (
_pangeaController . pStoreService . save (
PLocalKey . messagesSinceUpdate ,
PLocalKey . messagesSinceUpdate ,
[ ] ,
[ ] ,
@ -155,10 +175,21 @@ class MyAnalyticsController {
) ;
) ;
return [ ] ;
return [ ] ;
}
}
try {
return locallySaved as List < String > ;
return locallySaved as List < String > ;
} catch ( err ) {
} catch ( exception , stackTrace ) {
ErrorHandler . logError (
e: PangeaWarningError ( " Failed to get messages since update: $ exception " ) ,
s: stackTrace ,
m: ' Failed to retrieve messages since update '
) ;
Sentry . captureException (
exception ,
stackTrace: stackTrace ,
withScope: ( scope ) {
scope . setExtra ( ' extra_info ' , ' Error during messagesSinceUpdate getter ' ) ;
scope . setTag ( ' where ' , ' messagesSinceUpdate ' ) ;
}
) ;
_pangeaController . pStoreService . save (
_pangeaController . pStoreService . save (
PLocalKey . messagesSinceUpdate ,
PLocalKey . messagesSinceUpdate ,
[ ] ,
[ ] ,
@ -168,6 +199,7 @@ class MyAnalyticsController {
}
}
}
}
Completer < void > ? _updateCompleter ;
Completer < void > ? _updateCompleter ;
Future < void > updateAnalytics ( ) async {
Future < void > updateAnalytics ( ) async {
if ( ! ( _updateCompleter ? . isCompleted ? ? true ) ) {
if ( ! ( _updateCompleter ? . isCompleted ? ? true ) ) {