Erweiterungen

This commit is contained in:
Sven committed 2026-02-14 08:52:06 +01:00
1 parent ba1f7d5440
commit bb3dc9e856
28 files changed
+1672 -1291

No files matched your search

+11 -2
View File
@@ -16,6 +16,7 @@ import 'package:stadtbote/model/chat_message.dart';
import 'package:stadtbote/model/location_status.dart';
import 'package:stadtbote/model/rank.dart';
import 'package:stadtbote/model/status.dart';
import 'package:stadtbote/model/tour_file.dart';
import 'package:stadtbote/objectbox.g.dart';
import 'package:stadtbote/network_messages/acknowledge_job.dart';
import 'package:stadtbote/network_messages/acknowledge_message.dart';
@@ -401,8 +402,16 @@ class MqttCore with ProducerMixin, ConsumerMixin {
query.close();
if (existingJob != null) {
// Update existing job
// Update existing job - preserve the ID
newJob.id = existingJob.id;
// Ensure files are updated even if the job already exists
// This handles migration from old app versions without files support
if (payloadData['files'] != null) {
newJob.files = (payloadData['files'] as List<dynamic>)
.map((e) => TourFile.fromJson(e as Map<String, dynamic>))
.toList();
}
}
box.put(newJob);
@@ -754,7 +763,7 @@ class MqttCore with ProducerMixin, ConsumerMixin {
void _commandLogoutReceived(Map<String, dynamic> payload) {
try {
String timestamp = payload['timestamp'] ?? 'Unknown timestamp';
String timestamp = payload['timestamp']?.toString() ?? 'Unknown timestamp';
Util.logInfo('Command logout received with timestamp: $timestamp');
// Disconnect MQTT client gracefully
+23
View File
@@ -9,6 +9,7 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:stadtbote/main.dart';
import 'package:stadtbote/model/job.dart';
import 'package:stadtbote/model/log_entry.dart';
import 'package:stadtbote/objectbox.g.dart';
import 'package:stadtbote/tools/constants.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:uuid/uuid.dart';
@@ -97,6 +98,28 @@ class Util {
final box = MyApp.objectBoxStore.box<LogEntry>();
box.put(logEntry);
// Cleanup old logs (delete entries older than 3 days)
_cleanupOldLogs();
}
static void _cleanupOldLogs() async {
try {
final box = MyApp.objectBoxStore.box<LogEntry>();
// Delete logs older than 3 days
final threeDaysAgo = DateTime.now().subtract(const Duration(days: 3));
final oldLogsQuery = box.query(LogEntry_.time.lessThan(threeDaysAgo.millisecondsSinceEpoch)).build();
final oldLogs = oldLogsQuery.find();
oldLogsQuery.close();
if (oldLogs.isNotEmpty) {
box.removeMany(oldLogs.map((e) => e.id).toList());
}
} catch (e) {
// Silent fail for cleanup - don't log to avoid infinite loop
debugPrint('Log cleanup failed: $e');
}
}
static logInfo(String message) {