Refine backendless share intake
This commit is contained in:
@@ -39,12 +39,7 @@ Future<SharedMessageIngestResult?> startShareCaptureReview(
|
||||
required WidgetRef ref,
|
||||
required SharedPayload payload,
|
||||
}) {
|
||||
return showShareCaptureReviewSheet(
|
||||
context,
|
||||
ref: ref,
|
||||
payload: payload,
|
||||
initialPersonId: ref.read(selectedPersonIdProvider),
|
||||
);
|
||||
return showShareCaptureReviewSheet(context, ref: ref, payload: payload);
|
||||
}
|
||||
|
||||
void openShareCaptureDestination(
|
||||
@@ -73,10 +68,10 @@ void openShareCaptureDestination(
|
||||
|
||||
String shareCaptureResultMessage(SharedMessageIngestResult result) {
|
||||
if (result.isQueuedForResolution) {
|
||||
return 'Saved shared capture to inbox.';
|
||||
return 'Saved shared text to Capture inbox.';
|
||||
}
|
||||
if (result.createdProfile) {
|
||||
return 'Saved shared capture and created ${result.profileName}.';
|
||||
return 'Saved shared text and created ${result.profileName}.';
|
||||
}
|
||||
return 'Saved shared capture to ${result.profileName}.';
|
||||
return 'Saved shared text to ${result.profileName}.';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
const String _shareIntakeDebugLogKey = 'share_intake_debug_log_v1';
|
||||
const int _maxShareIntakeDebugEvents = 40;
|
||||
|
||||
class ShareIntakeDebugEvent {
|
||||
const ShareIntakeDebugEvent({
|
||||
required this.at,
|
||||
required this.stage,
|
||||
required this.message,
|
||||
});
|
||||
|
||||
factory ShareIntakeDebugEvent.fromJson(Map<String, dynamic> json) {
|
||||
return ShareIntakeDebugEvent(
|
||||
at: DateTime.parse(
|
||||
json['at'] as String? ?? DateTime.now().toUtc().toIso8601String(),
|
||||
).toLocal(),
|
||||
stage: json['stage'] as String? ?? 'unknown',
|
||||
message: json['message'] as String? ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
final DateTime at;
|
||||
final String stage;
|
||||
final String message;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return <String, dynamic>{
|
||||
'at': at.toUtc().toIso8601String(),
|
||||
'stage': stage,
|
||||
'message': message,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class ShareIntakeDebugLog {
|
||||
const ShareIntakeDebugLog();
|
||||
|
||||
Future<List<ShareIntakeDebugEvent>> read() async {
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
final String? raw = prefs.getString(_shareIntakeDebugLogKey);
|
||||
if (raw == null || raw.isEmpty) {
|
||||
return const <ShareIntakeDebugEvent>[];
|
||||
}
|
||||
try {
|
||||
final List<dynamic> items = jsonDecode(raw) as List<dynamic>;
|
||||
return items
|
||||
.whereType<Map<String, dynamic>>()
|
||||
.map(ShareIntakeDebugEvent.fromJson)
|
||||
.toList(growable: false);
|
||||
} on FormatException {
|
||||
return const <ShareIntakeDebugEvent>[];
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> record(String stage, String message) async {
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
final List<ShareIntakeDebugEvent> current = await read();
|
||||
final List<ShareIntakeDebugEvent> next = <ShareIntakeDebugEvent>[
|
||||
ShareIntakeDebugEvent(at: DateTime.now(), stage: stage, message: message),
|
||||
...current,
|
||||
].take(_maxShareIntakeDebugEvents).toList(growable: false);
|
||||
await prefs.setString(
|
||||
_shareIntakeDebugLogKey,
|
||||
jsonEncode(
|
||||
next
|
||||
.map((ShareIntakeDebugEvent event) => event.toJson())
|
||||
.toList(growable: false),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> clear() async {
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
await prefs.remove(_shareIntakeDebugLogKey);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user