Annahmedialog auf Auftragsliste unterdrückt und MQTT-Wiederholungen abgesichert
This commit is contained in:
1 parent
684e8a57fc
commit
c63018918b
3 files changed
+353
-9
No files matched your search
+3
-1
@@ -7,6 +7,7 @@ import 'package:flutter/services.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:shared_map/shared_map.dart';
|
||||
import 'package:stadtbote/content_views/assigned_jobs_page.dart';
|
||||
import 'package:stadtbote/messages/pop_content_view_message.dart';
|
||||
import 'package:stadtbote/model/log_entry.dart';
|
||||
import 'package:stadtbote/popups/accept_jobs_popup.dart';
|
||||
@@ -529,7 +530,8 @@ class _MainState extends State<Main> with SingleTickerProviderStateMixin, Produc
|
||||
|
||||
void _startCheckForNewState0JobsJobsTimer() {
|
||||
_checkForNewState0JobsJobsTimer ??= Timer.periodic(const Duration(seconds: 5), (Timer t) async {
|
||||
if (await _jobMap!.length() > 0 && !_dialogOpened) {
|
||||
// Auf der Auftragsliste können neue Aufträge direkt beantwortet werden.
|
||||
if (await _jobMap!.length() > 0 && !_dialogOpened && _currentContent is! AssignedJobsPage) {
|
||||
_dialogOpened = true;
|
||||
await showAcceptJobsPopup(_jobMap!.sharedReference(), () async {
|
||||
_dialogOpened = false;
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'dart:math';
|
||||
import 'package:archive/archive.dart';
|
||||
import 'package:dart_mq/dart_mq.dart';
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:mqtt5_client/mqtt5_client.dart';
|
||||
@@ -98,6 +99,22 @@ class MqttCore with ProducerMixin, ConsumerMixin {
|
||||
_processBootstrap();
|
||||
}
|
||||
|
||||
/// Ermöglicht Tests des Nachrichtenflusses ohne Bootstrap und Netzwerkzugriff.
|
||||
@visibleForTesting
|
||||
MqttCore.withClient({
|
||||
required MqttServerClient client,
|
||||
required String clientId,
|
||||
required String fromServerTopic,
|
||||
required String toServerTopic,
|
||||
}) : _mqttClient = client,
|
||||
_clientId = clientId,
|
||||
_fromServerTopic = fromServerTopic,
|
||||
_toServerTopic = toServerTopic {
|
||||
instance = this;
|
||||
initMessages();
|
||||
_setupMqtt();
|
||||
}
|
||||
|
||||
ConnectionStateEnum getConnectionStatus() {
|
||||
return connectionState;
|
||||
}
|
||||
@@ -185,15 +202,24 @@ class MqttCore with ProducerMixin, ConsumerMixin {
|
||||
}
|
||||
}
|
||||
|
||||
bool _publishMessage(String topic, Map<String, dynamic> message, bool acknowledgeRequired, {bool enqueueOnError = true}) {
|
||||
bool _publishMessage(String topic, Map<String, dynamic> message, bool acknowledgeRequired) {
|
||||
try {
|
||||
String messageId = const Uuid().v4();
|
||||
String messageText = jsonEncode(message);
|
||||
final messageId = const Uuid().v4();
|
||||
|
||||
if (acknowledgeRequired) {
|
||||
_enqueueMessage(messageId, topic, messageText);
|
||||
// Vor dem ersten Versand speichern; erst die Serverbestätigung entfernt den Eintrag.
|
||||
_enqueueMessage(messageId, topic, jsonEncode(message));
|
||||
}
|
||||
|
||||
return _sendMessage(topic, message, acknowledgeRequired, messageId);
|
||||
} catch (ex) {
|
||||
Util.logInfo("send failed: $ex");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool _sendMessage(String topic, Map<String, dynamic> message, bool acknowledgeRequired, String messageId) {
|
||||
try {
|
||||
var encapsulatedMessageText = _encapsulateMessage(messageId, acknowledgeRequired, message);
|
||||
|
||||
var buffer = Uint8Buffer();
|
||||
@@ -761,7 +787,7 @@ class MqttCore with ProducerMixin, ConsumerMixin {
|
||||
}
|
||||
}
|
||||
|
||||
void _enqueueMessage(String uuid, String receiver, String payload) async {
|
||||
void _enqueueMessage(String uuid, String receiver, String payload) {
|
||||
var enqueuedMessage = EnqueuedMessage();
|
||||
enqueuedMessage.messageId = uuid;
|
||||
enqueuedMessage.topic = receiver;
|
||||
@@ -780,9 +806,8 @@ class MqttCore with ProducerMixin, ConsumerMixin {
|
||||
try {
|
||||
var json = jsonDecode(enqueuedMessage.payload);
|
||||
|
||||
if (_publishMessage(enqueuedMessage.topic, json, false, enqueueOnError: false)) {
|
||||
box.remove(enqueuedMessage.id);
|
||||
}
|
||||
// Wiederholungen behalten ihre ID und benötigen weiterhin eine Bestätigung.
|
||||
_sendMessage(enqueuedMessage.topic, json, true, enqueuedMessage.messageId);
|
||||
} catch (ex) {
|
||||
Util.logInfo("resend enqueued message failed: $ex");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user