diff --git a/lib/tools/mqtt_core.dart b/lib/tools/mqtt_core.dart index a5f4599..5bd37c7 100644 --- a/lib/tools/mqtt_core.dart +++ b/lib/tools/mqtt_core.dart @@ -143,16 +143,7 @@ class MqttCore with ProducerMixin, ConsumerMixin { Uint8Buffer uint8Buffer = Uint8Buffer(); uint8Buffer.addAll(willMessageUtf8); - _mqttClient!.connectionMessage = MqttConnectMessage() - .withClientIdentifier(Util.getAppUuid()) - .authenticateAs("app", "apppwd") - .withSessionExpiryInterval(2700) - .withWillProperties(willProperties) - .withWillTopic("$_toServerTopic$_clientId/connection_lost") - .withWillQos(MqttQos.atMostOnce) - .keepAliveFor(60) - .withWillPayload(uint8Buffer) - .will(); + _mqttClient!.connectionMessage = MqttConnectMessage().withClientIdentifier(Util.getAppUuid()).authenticateAs("app", "apppwd").withSessionExpiryInterval(2700).withWillProperties(willProperties).withWillTopic("$_toServerTopic$_clientId/connection_lost").withWillQos(MqttQos.atMostOnce).keepAliveFor(60).withWillPayload(uint8Buffer).will(); } await _mqttClient!.connect(); @@ -227,9 +218,7 @@ class MqttCore with ProducerMixin, ConsumerMixin { var topicArray = message.variableHeader?.topicName; var topicArraySplited = topicArray!.split("/"); - var topic = topicArraySplited.length > 7 - ? topicArraySplited.sublist(7).join('/') - : (topicArraySplited.length == 8 ? topicArraySplited[7] : ""); + var topic = topicArraySplited.length > 7 ? topicArraySplited.sublist(7).join('/') : (topicArraySplited.length == 8 ? topicArraySplited[7] : ""); if (topic.endsWith('/')) { topic = topic.substring(0, topic.length - 1); } @@ -385,10 +374,7 @@ class MqttCore with ProducerMixin, ConsumerMixin { box.removeAll(); box.put(ranking); - sendMessage( - routingKey: Constants.messageTopicRankingUpdated, - payload: RankingUpdated(), - ); + sendMessage(routingKey: Constants.messageTopicRankingUpdated, payload: RankingUpdated()); } void _jobMessageReceived(payloadData) async { @@ -404,13 +390,11 @@ class MqttCore with ProducerMixin, ConsumerMixin { if (existingJob != null) { // 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) - .map((e) => TourFile.fromJson(e as Map)) - .toList(); + newJob.files = (payloadData['files'] as List).map((e) => TourFile.fromJson(e as Map)).toList(); } } @@ -478,10 +462,7 @@ class MqttCore with ProducerMixin, ConsumerMixin { var deviceLogRequest = DeviceLogRequest.fromJson(payloadData); final box = MyApp.objectBoxStore.box(); - final query = box.query( - LogEntry_.time.greaterThan(deviceLogRequest.startDateTime.millisecondsSinceEpoch) - .and(LogEntry_.time.lessThan(deviceLogRequest.endDateTime.millisecondsSinceEpoch)) - ).build(); + final query = box.query(LogEntry_.time.greaterThan(deviceLogRequest.startDateTime.millisecondsSinceEpoch).and(LogEntry_.time.lessThan(deviceLogRequest.endDateTime.millisecondsSinceEpoch))).build(); var logEintries = query.find(); query.close(); @@ -502,7 +483,6 @@ class MqttCore with ProducerMixin, ConsumerMixin { box.removeMany(messages.map((e) => e.id).toList()); } - void _startReconnectTimer() { connectionState = ConnectionStateEnum.notConnected; @@ -663,7 +643,6 @@ class MqttCore with ProducerMixin, ConsumerMixin { } else { _publishMessage("track", {}, false); } - } catch (ex) { Util.logException("Error in periodic track timer: {$ex}"); } @@ -763,8 +742,7 @@ class MqttCore with ProducerMixin, ConsumerMixin { void _commandLogoutReceived(Map payload) { try { - String timestamp = payload['timestamp']?.toString() ?? 'Unknown timestamp'; - Util.logInfo('Command logout received with timestamp: $timestamp'); + Util.logInfo('Command logout received'); // Disconnect MQTT client gracefully _disconnectMqttClient();