Refactoring

This commit is contained in:
Sven committed 2024-05-06 10:03:36 +02:00
1 parent 66321f710b
commit 007aa8dd1a
3 files changed
+51 -48

No files matched your search

+1
View File
@@ -7,6 +7,7 @@ class Constants {
static const String messageTopicConnectionStatusChanged = "connection_status_changed";
static const String messageTopicSessionInfoUpdate = "status_info_updated";
static const String messageTopicSessionStatusInfoUpdate = "session_status_info_updated";
static const String messageTopicStatusInfoUpdated = "status_info_updated";
static const String messageTopicLocationStatusUpdated = "location_status_updated";
static const String messageTopicRankingUpdated = "ranking_updated";
static const String messageTopicJobReceived = "job_received";
+46 -43
View File
@@ -23,6 +23,7 @@ import 'package:stadtbote/protocoll_messages/device_log_response.dart';
import 'package:stadtbote/protocoll_messages/device_object.dart';
import 'package:stadtbote/protocoll_messages/payload_container.dart';
import 'package:stadtbote/protocoll_messages/start_session_message.dart';
import 'package:stadtbote/protocoll_messages/status_info_update.dart';
import 'package:stadtbote/protocoll_messages/sync_jobs_message.dart';
import 'package:stadtbote/protocoll_messages/track_message.dart';
import 'package:stadtbote/tools/connection_status.dart';
@@ -180,61 +181,63 @@ class MqttCore {
void _setupMqtt() async {
Util.logInfo('_setupMqtt called');
_mqttClient!.updates?.listen((List<MqttReceivedMessage<MqttMessage>> c) {
for (var message in c) {
_mqttClient!.updates?.listen((List<MqttReceivedMessage<MqttMessage>> messages) {
for (var mqttMessage in messages) {
try {
if (message.topic.endsWith(_clientId)) {
var messageBytes = message.payload.;
String payload = utf8.decode(GZipDecoder().decodeBytes(messageBytes));
final MqttPublishMessage message = mqttMessage.payload as MqttPublishMessage;
var topicArray = message.variableHeader?.topicName;
var topicArraySplited = topicArray!.split("/");
var topic = topicArraySplited[3];
if (message.variableHeader!.topicName.endsWith(_clientId)) {
var messageBytes = message.payload.message;
String payload = utf8.decode(GZipDecoder().decodeBytes(messageBytes));
Util.logInfo('message received\ntopic: $topic\nmessage: $payload');
var topicArray = message.variableHeader?.topicName;
var topicArraySplited = topicArray!.split("/");
var topic = topicArraySplited[3];
switch(topic) {
case 'session':
_sessionMessageReceived(jsonDecode(payload));
break;
Util.logInfo('message received\ntopic: $topic\nmessage: $payload');
case 'status':
_statusMessageReceived(jsonDecode(payload));
break;
switch (topic) {
case 'session':
_sessionMessageReceived(jsonDecode(payload));
break;
case 'ranks':
_rankingMessageReceived(jsonDecode(payload));
break;
case 'status':
_statusMessageReceived(jsonDecode(payload));
break;
case 'job':
_jobMessageReceived(jsonDecode(payload));
break;
case 'ranks':
_rankingMessageReceived(jsonDecode(payload));
break;
case 'job_del':
_jobDeleteReceived(jsonDecode(payload));
break;
case 'job':
_jobMessageReceived(jsonDecode(payload));
break;
case 'sync_request':
_syncRequestReceived(jsonDecode(payload));
break;
case 'job_del':
_jobDeleteReceived(jsonDecode(payload));
break;
case "mssg":
_messageMessageReceived(jsonDecode(payload));
break;
case 'sync_request':
_syncRequestReceived(jsonDecode(payload));
break;
case "upload_device_log":
_messageUploadDeviceLogReceived(jsonDecode(payload));
break;
case "mssg":
_messageMessageReceived(jsonDecode(payload));
break;
default:
Util.logInfo('Unknown topic: $topic');
break;
}
case "upload_device_log":
_messageUploadDeviceLogReceived(jsonDecode(payload));
break;
default:
Util.logInfo('Unknown topic: $topic');
break;
}
} catch(ex) {
Util.logException(ex.toString());
}
});
}
} catch(ex) {
Util.logException(ex.toString());
}
}});
if (await Util.preferencesContainsKey(Constants.prefsPreviousMqttSubscription)) {
String previousMqttSubscription = await Util.preferencesGetString(Constants.prefsPreviousMqttSubscription, "") as String;
@@ -284,7 +287,7 @@ class MqttCore {
MessageService().publish<StatusInfoUpdate>(Constants.messageTopicStatusInfoUpdated, arguments: StatusInfoUpdate(status: statusMessage));
}
void _locationSatusMessageReceived(payloadData) async {
void _locationStatusMessageReceived(payloadData) async {
var locationStatus = LocationStatus.fromJson(payloadData);
await MyApp.isarInstance.writeTxn(() async {