Fehler Merge behoben
This commit is contained in:
1 parent
721dbd861c
commit
eb1e18d042
10 files changed
+205
-148
No files matched your search
@@ -202,8 +202,8 @@ class _AssignedJobsPageState extends State<AssignedJobsPage> {
|
|||||||
|
|
||||||
MqttCore.instance.publishText("reaction", jsonEncode(message.toJson()));
|
MqttCore.instance.publishText("reaction", jsonEncode(message.toJson()));
|
||||||
|
|
||||||
MyApp.isarInstance.writeTxnSync(() {
|
await MyApp.isarInstance.writeTxn(() async {
|
||||||
MyApp.isarInstance.jobs.deleteSync(job.id);
|
await MyApp.isarInstance.jobs.delete(job.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
MessageService().publish(Constants.messageTopicRefreshBadges, arguments: RefreshBadgesMessage());
|
MessageService().publish(Constants.messageTopicRefreshBadges, arguments: RefreshBadgesMessage());
|
||||||
|
|||||||
@@ -381,8 +381,6 @@ class _MainPageState extends State<MainPage> {
|
|||||||
logoutMessage.pos!.acc = position.accuracy.toInt();
|
logoutMessage.pos!.acc = position.accuracy.toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
var json = jsonEncode(logoutMessage.toJson());
|
MqttCore.instance.publishText("logout", jsonEncode(logoutMessage.toJson()));
|
||||||
|
|
||||||
MqttCore.instance.publishText("session", jsonEncode(logoutMessage.toJson()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -182,7 +182,7 @@ class _MessagesPageState extends State<MessagesPage> {
|
|||||||
const SizedBox(width: 20),
|
const SizedBox(width: 20),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: getDefaultButton('Ja', () async => {
|
child: getDefaultButton('Ja', () async => {
|
||||||
await MyApp.isarInstance.writeTxnSync(() async => { await MyApp.isarInstance.messages.delete(int.parse(message.id))}),
|
await MyApp.isarInstance.writeTxn(() async => { await MyApp.isarInstance.messages.delete(int.parse(message.id))}),
|
||||||
|
|
||||||
_fetchMessages(),
|
_fetchMessages(),
|
||||||
|
|
||||||
|
|||||||
@@ -379,13 +379,13 @@ class _TaskListPageState extends State<TaskListPage> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _processSignature(TaskInfo taskInfo) {
|
void _processSignature(TaskInfo taskInfo) async {
|
||||||
MyApp.suppressAcceptDialog = true;
|
MyApp.suppressAcceptDialog = true;
|
||||||
|
|
||||||
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft]);
|
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft]);
|
||||||
|
|
||||||
Future.delayed(const Duration(seconds: 1), () async {
|
Future.delayed(const Duration(seconds: 1), () {
|
||||||
showSignaturePopup(context, taskInfo, (String? signature) {
|
showSignaturePopup(context, taskInfo, (String? signature) async {
|
||||||
MyApp.suppressAcceptDialog = false;
|
MyApp.suppressAcceptDialog = false;
|
||||||
|
|
||||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||||
@@ -399,15 +399,15 @@ class _TaskListPageState extends State<TaskListPage> {
|
|||||||
|
|
||||||
_sendFinTourMessage();
|
_sendFinTourMessage();
|
||||||
|
|
||||||
_finishTaskProcessing(taskInfo);
|
await _finishTaskProcessing(taskInfo);
|
||||||
|
|
||||||
MessageService().publish<PopContentViewMessage>(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: 2));
|
MessageService().publish<PopContentViewMessage>(Constants.messageTopicPopContentView, arguments: PopContentViewMessage(count: widget.job.state == 1 ? 2 : 3));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_finishTaskProcessing(TaskInfo taskInfo) async {
|
Future<void> _finishTaskProcessing(TaskInfo taskInfo) async {
|
||||||
await MyApp.isarInstance.writeTxn(() async {
|
await MyApp.isarInstance.writeTxn(() async {
|
||||||
await MyApp.isarInstance.taskInfos.put(taskInfo);
|
await MyApp.isarInstance.taskInfos.put(taskInfo);
|
||||||
});
|
});
|
||||||
@@ -444,7 +444,7 @@ class _TaskListPageState extends State<TaskListPage> {
|
|||||||
message.task.pos!.long = position.longitude;
|
message.task.pos!.long = position.longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
MqttCore.instance.publishText("job", jsonEncode(message.toJson()));
|
MqttCore.instance.publishText("fin_task", jsonEncode(message.toJson()));
|
||||||
}
|
}
|
||||||
|
|
||||||
FinTourTask _createAnswerHeader(TaskInfo taskInfo) {
|
FinTourTask _createAnswerHeader(TaskInfo taskInfo) {
|
||||||
@@ -463,10 +463,10 @@ class _TaskListPageState extends State<TaskListPage> {
|
|||||||
return finTourTask;
|
return finTourTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
_sendFinTourMessage() async {
|
Future<void> _sendFinTourMessage() async {
|
||||||
var message = FinTour();
|
var message = FinTour();
|
||||||
message.trId = widget.tour.id;
|
message.trId = widget.tour.id;
|
||||||
message.com = "Mir doch egal!";
|
message.com = _commisionNumber;
|
||||||
|
|
||||||
var position = MyApp.currentPosition;
|
var position = MyApp.currentPosition;
|
||||||
if (position != null) {
|
if (position != null) {
|
||||||
@@ -489,8 +489,31 @@ class _TaskListPageState extends State<TaskListPage> {
|
|||||||
MqttCore.instance.publishText("fin_tour", jsonEncode(message.toJson()));
|
MqttCore.instance.publishText("fin_tour", jsonEncode(message.toJson()));
|
||||||
|
|
||||||
widget.tour.state = Constants.stateFinishedNotConfirmed;
|
widget.tour.state = Constants.stateFinishedNotConfirmed;
|
||||||
await MyApp.isarInstance.writeTxn(() async {
|
await MyApp.isarInstance.writeTxn(() async {
|
||||||
await MyApp.isarInstance.jobs.put(widget.job);
|
await MyApp.isarInstance.jobs.put(widget.job);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
checkJobFinished();
|
||||||
|
}
|
||||||
|
|
||||||
|
void checkJobFinished() async {
|
||||||
|
var jobFinished = true;
|
||||||
|
|
||||||
|
for(var tour in widget.job.tours) {
|
||||||
|
if (tour.state < 1) {
|
||||||
|
jobFinished = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jobFinished) {
|
||||||
|
widget.job.state = 2;
|
||||||
|
for(var tour in widget.job.tours) {
|
||||||
|
tour.state = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
await MyApp.isarInstance.writeTxn(() async {
|
||||||
|
await MyApp.isarInstance.jobs.put(widget.job);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-12
@@ -6,23 +6,12 @@ import 'package:stadtbote/model/tour_task.dart';
|
|||||||
|
|
||||||
part 'job.g.dart';
|
part 'job.g.dart';
|
||||||
|
|
||||||
@JsonSerializable()
|
|
||||||
class JobsPayload {
|
|
||||||
List<Job>? jobs;
|
|
||||||
|
|
||||||
JobsPayload({this.jobs});
|
|
||||||
|
|
||||||
factory JobsPayload.fromJson(Map<String, dynamic> json) => _$JobsPayloadFromJson(json);
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => _$JobsPayloadToJson(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@collection
|
@collection
|
||||||
@JsonSerializable()
|
@JsonSerializable()
|
||||||
class Job {
|
class Job {
|
||||||
late Id id;
|
late Id id;
|
||||||
@JsonKey(name: 'ver')
|
@JsonKey(name: 'ver')
|
||||||
late int ver;
|
late String ver;
|
||||||
@JsonKey(name: 'state')
|
@JsonKey(name: 'state')
|
||||||
late int state;
|
late int state;
|
||||||
@JsonKey(name: 'cr_filter')
|
@JsonKey(name: 'cr_filter')
|
||||||
|
|||||||
+90
-24
@@ -56,7 +56,7 @@ const JobSchema = CollectionSchema(
|
|||||||
r'ver': PropertySchema(
|
r'ver': PropertySchema(
|
||||||
id: 7,
|
id: 7,
|
||||||
name: r'ver',
|
name: r'ver',
|
||||||
type: IsarType.long,
|
type: IsarType.string,
|
||||||
),
|
),
|
||||||
r'vhtId': PropertySchema(
|
r'vhtId': PropertySchema(
|
||||||
id: 8,
|
id: 8,
|
||||||
@@ -105,6 +105,7 @@ int _jobEstimateSize(
|
|||||||
bytesCount += JobTourSchema.estimateSize(value, offsets, allOffsets);
|
bytesCount += JobTourSchema.estimateSize(value, offsets, allOffsets);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bytesCount += 3 + object.ver.length * 3;
|
||||||
return bytesCount;
|
return bytesCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +127,7 @@ void _jobSerialize(
|
|||||||
JobTourSchema.serialize,
|
JobTourSchema.serialize,
|
||||||
object.tours,
|
object.tours,
|
||||||
);
|
);
|
||||||
writer.writeLong(offsets[7], object.ver);
|
writer.writeString(offsets[7], object.ver);
|
||||||
writer.writeLong(offsets[8], object.vhtId);
|
writer.writeLong(offsets[8], object.vhtId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,7 +152,7 @@ Job _jobDeserialize(
|
|||||||
JobTour(),
|
JobTour(),
|
||||||
) ??
|
) ??
|
||||||
[];
|
[];
|
||||||
object.ver = reader.readLong(offsets[7]);
|
object.ver = reader.readString(offsets[7]);
|
||||||
object.vhtId = reader.readLong(offsets[8]);
|
object.vhtId = reader.readLong(offsets[8]);
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
@@ -184,7 +185,7 @@ P _jobDeserializeProp<P>(
|
|||||||
) ??
|
) ??
|
||||||
[]) as P;
|
[]) as P;
|
||||||
case 7:
|
case 7:
|
||||||
return (reader.readLong(offset)) as P;
|
return (reader.readString(offset)) as P;
|
||||||
case 8:
|
case 8:
|
||||||
return (reader.readLong(offset)) as P;
|
return (reader.readLong(offset)) as P;
|
||||||
default:
|
default:
|
||||||
@@ -928,46 +929,55 @@ extension JobQueryFilter on QueryBuilder<Job, Job, QFilterCondition> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryBuilder<Job, Job, QAfterFilterCondition> verEqualTo(int value) {
|
QueryBuilder<Job, Job, QAfterFilterCondition> verEqualTo(
|
||||||
|
String value, {
|
||||||
|
bool caseSensitive = true,
|
||||||
|
}) {
|
||||||
return QueryBuilder.apply(this, (query) {
|
return QueryBuilder.apply(this, (query) {
|
||||||
return query.addFilterCondition(FilterCondition.equalTo(
|
return query.addFilterCondition(FilterCondition.equalTo(
|
||||||
property: r'ver',
|
property: r'ver',
|
||||||
value: value,
|
value: value,
|
||||||
|
caseSensitive: caseSensitive,
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryBuilder<Job, Job, QAfterFilterCondition> verGreaterThan(
|
QueryBuilder<Job, Job, QAfterFilterCondition> verGreaterThan(
|
||||||
int value, {
|
String value, {
|
||||||
bool include = false,
|
bool include = false,
|
||||||
|
bool caseSensitive = true,
|
||||||
}) {
|
}) {
|
||||||
return QueryBuilder.apply(this, (query) {
|
return QueryBuilder.apply(this, (query) {
|
||||||
return query.addFilterCondition(FilterCondition.greaterThan(
|
return query.addFilterCondition(FilterCondition.greaterThan(
|
||||||
include: include,
|
include: include,
|
||||||
property: r'ver',
|
property: r'ver',
|
||||||
value: value,
|
value: value,
|
||||||
|
caseSensitive: caseSensitive,
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryBuilder<Job, Job, QAfterFilterCondition> verLessThan(
|
QueryBuilder<Job, Job, QAfterFilterCondition> verLessThan(
|
||||||
int value, {
|
String value, {
|
||||||
bool include = false,
|
bool include = false,
|
||||||
|
bool caseSensitive = true,
|
||||||
}) {
|
}) {
|
||||||
return QueryBuilder.apply(this, (query) {
|
return QueryBuilder.apply(this, (query) {
|
||||||
return query.addFilterCondition(FilterCondition.lessThan(
|
return query.addFilterCondition(FilterCondition.lessThan(
|
||||||
include: include,
|
include: include,
|
||||||
property: r'ver',
|
property: r'ver',
|
||||||
value: value,
|
value: value,
|
||||||
|
caseSensitive: caseSensitive,
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryBuilder<Job, Job, QAfterFilterCondition> verBetween(
|
QueryBuilder<Job, Job, QAfterFilterCondition> verBetween(
|
||||||
int lower,
|
String lower,
|
||||||
int upper, {
|
String upper, {
|
||||||
bool includeLower = true,
|
bool includeLower = true,
|
||||||
bool includeUpper = true,
|
bool includeUpper = true,
|
||||||
|
bool caseSensitive = true,
|
||||||
}) {
|
}) {
|
||||||
return QueryBuilder.apply(this, (query) {
|
return QueryBuilder.apply(this, (query) {
|
||||||
return query.addFilterCondition(FilterCondition.between(
|
return query.addFilterCondition(FilterCondition.between(
|
||||||
@@ -976,6 +986,73 @@ extension JobQueryFilter on QueryBuilder<Job, Job, QFilterCondition> {
|
|||||||
includeLower: includeLower,
|
includeLower: includeLower,
|
||||||
upper: upper,
|
upper: upper,
|
||||||
includeUpper: includeUpper,
|
includeUpper: includeUpper,
|
||||||
|
caseSensitive: caseSensitive,
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
QueryBuilder<Job, Job, QAfterFilterCondition> verStartsWith(
|
||||||
|
String value, {
|
||||||
|
bool caseSensitive = true,
|
||||||
|
}) {
|
||||||
|
return QueryBuilder.apply(this, (query) {
|
||||||
|
return query.addFilterCondition(FilterCondition.startsWith(
|
||||||
|
property: r'ver',
|
||||||
|
value: value,
|
||||||
|
caseSensitive: caseSensitive,
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
QueryBuilder<Job, Job, QAfterFilterCondition> verEndsWith(
|
||||||
|
String value, {
|
||||||
|
bool caseSensitive = true,
|
||||||
|
}) {
|
||||||
|
return QueryBuilder.apply(this, (query) {
|
||||||
|
return query.addFilterCondition(FilterCondition.endsWith(
|
||||||
|
property: r'ver',
|
||||||
|
value: value,
|
||||||
|
caseSensitive: caseSensitive,
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
QueryBuilder<Job, Job, QAfterFilterCondition> verContains(String value,
|
||||||
|
{bool caseSensitive = true}) {
|
||||||
|
return QueryBuilder.apply(this, (query) {
|
||||||
|
return query.addFilterCondition(FilterCondition.contains(
|
||||||
|
property: r'ver',
|
||||||
|
value: value,
|
||||||
|
caseSensitive: caseSensitive,
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
QueryBuilder<Job, Job, QAfterFilterCondition> verMatches(String pattern,
|
||||||
|
{bool caseSensitive = true}) {
|
||||||
|
return QueryBuilder.apply(this, (query) {
|
||||||
|
return query.addFilterCondition(FilterCondition.matches(
|
||||||
|
property: r'ver',
|
||||||
|
wildcard: pattern,
|
||||||
|
caseSensitive: caseSensitive,
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
QueryBuilder<Job, Job, QAfterFilterCondition> verIsEmpty() {
|
||||||
|
return QueryBuilder.apply(this, (query) {
|
||||||
|
return query.addFilterCondition(FilterCondition.equalTo(
|
||||||
|
property: r'ver',
|
||||||
|
value: '',
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
QueryBuilder<Job, Job, QAfterFilterCondition> verIsNotEmpty() {
|
||||||
|
return QueryBuilder.apply(this, (query) {
|
||||||
|
return query.addFilterCondition(FilterCondition.greaterThan(
|
||||||
|
property: r'ver',
|
||||||
|
value: '',
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1291,9 +1368,9 @@ extension JobQueryWhereDistinct on QueryBuilder<Job, Job, QDistinct> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryBuilder<Job, Job, QDistinct> distinctByVer() {
|
QueryBuilder<Job, Job, QDistinct> distinctByVer({bool caseSensitive = true}) {
|
||||||
return QueryBuilder.apply(this, (query) {
|
return QueryBuilder.apply(this, (query) {
|
||||||
return query.addDistinctBy(r'ver');
|
return query.addDistinctBy(r'ver', caseSensitive: caseSensitive);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1353,7 +1430,7 @@ extension JobQueryProperty on QueryBuilder<Job, Job, QQueryProperty> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryBuilder<Job, int, QQueryOperations> verProperty() {
|
QueryBuilder<Job, String, QQueryOperations> verProperty() {
|
||||||
return QueryBuilder.apply(this, (query) {
|
return QueryBuilder.apply(this, (query) {
|
||||||
return query.addPropertyName(r'ver');
|
return query.addPropertyName(r'ver');
|
||||||
});
|
});
|
||||||
@@ -1370,20 +1447,9 @@ extension JobQueryProperty on QueryBuilder<Job, Job, QQueryProperty> {
|
|||||||
// JsonSerializableGenerator
|
// JsonSerializableGenerator
|
||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
|
||||||
JobsPayload _$JobsPayloadFromJson(Map<String, dynamic> json) => JobsPayload(
|
|
||||||
jobs: (json['jobs'] as List<dynamic>?)
|
|
||||||
?.map((e) => Job.fromJson(e as Map<String, dynamic>))
|
|
||||||
.toList(),
|
|
||||||
);
|
|
||||||
|
|
||||||
Map<String, dynamic> _$JobsPayloadToJson(JobsPayload instance) =>
|
|
||||||
<String, dynamic>{
|
|
||||||
'jobs': instance.jobs,
|
|
||||||
};
|
|
||||||
|
|
||||||
Job _$JobFromJson(Map<String, dynamic> json) => Job()
|
Job _$JobFromJson(Map<String, dynamic> json) => Job()
|
||||||
..id = json['id'] as int
|
..id = json['id'] as int
|
||||||
..ver = json['ver'] as int
|
..ver = json['ver'] as String
|
||||||
..state = json['state'] as int
|
..state = json['state'] as int
|
||||||
..crFilter = json['cr_filter'] as String?
|
..crFilter = json['cr_filter'] as String?
|
||||||
..ordertime = json['ordertime'] as String
|
..ordertime = json['ordertime'] as String
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ Future<void> showAcceptJobsPopup(BuildContext context, List<Job> jobs, Function(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_sendAnswer(Job job, int item) {
|
_sendAnswer(Job job, int item) async {
|
||||||
var currentPosition = MyApp.currentPosition;
|
var currentPosition = MyApp.currentPosition;
|
||||||
|
|
||||||
var message = Reaction();
|
var message = Reaction();
|
||||||
@@ -219,8 +219,8 @@ _sendAnswer(Job job, int item) {
|
|||||||
|
|
||||||
MqttCore.instance.publishText("reaction", jsonEncode(message.toJson()));
|
MqttCore.instance.publishText("reaction", jsonEncode(message.toJson()));
|
||||||
|
|
||||||
MyApp.isarInstance.writeTxnSync(() {
|
await MyApp.isarInstance.writeTxn(() async{
|
||||||
MyApp.isarInstance.jobs.deleteSync(job.id);
|
await MyApp.isarInstance.jobs.delete(job.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
MessageService().publish(Constants.messageTopicRefreshBadges, arguments: RefreshBadgesMessage());
|
MessageService().publish(Constants.messageTopicRefreshBadges, arguments: RefreshBadgesMessage());
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class AcknowledgeJobReceived {
|
|||||||
|
|
||||||
late int state;
|
late int state;
|
||||||
|
|
||||||
late int ver;
|
late String ver;
|
||||||
|
|
||||||
late int utc;
|
late int utc;
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ AcknowledgeJobReceived _$AcknowledgeJobReceivedFromJson(
|
|||||||
AcknowledgeJobReceived()
|
AcknowledgeJobReceived()
|
||||||
..id = json['id'] as int
|
..id = json['id'] as int
|
||||||
..state = json['state'] as int
|
..state = json['state'] as int
|
||||||
..ver = json['ver'] as int
|
..ver = json['ver'] as String
|
||||||
..utc = json['utc'] as int;
|
..utc = json['utc'] as int;
|
||||||
|
|
||||||
Map<String, dynamic> _$AcknowledgeJobReceivedToJson(
|
Map<String, dynamic> _$AcknowledgeJobReceivedToJson(
|
||||||
|
|||||||
+72
-91
@@ -4,11 +4,14 @@ import 'dart:math';
|
|||||||
|
|
||||||
import 'package:archive/archive.dart';
|
import 'package:archive/archive.dart';
|
||||||
import 'package:device_info_plus/device_info_plus.dart';
|
import 'package:device_info_plus/device_info_plus.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:isar/isar.dart';
|
import 'package:isar/isar.dart';
|
||||||
import 'package:mqtt_client/mqtt_client.dart';
|
import 'package:mqtt_client/mqtt_client.dart';
|
||||||
import 'package:mqtt_client/mqtt_server_client.dart';
|
import 'package:mqtt_client/mqtt_server_client.dart';
|
||||||
import 'package:stadtbote/model/enqueued_message.dart';
|
import 'package:stadtbote/model/enqueued_message.dart';
|
||||||
|
import 'package:stadtbote/model/job.dart';
|
||||||
import 'package:stadtbote/model/log_entry.dart';
|
import 'package:stadtbote/model/log_entry.dart';
|
||||||
|
import 'package:stadtbote/model/message.dart';
|
||||||
import 'package:stadtbote/model/status.dart';
|
import 'package:stadtbote/model/status.dart';
|
||||||
import 'package:stadtbote/protocoll_messages/acknowledge_job.dart';
|
import 'package:stadtbote/protocoll_messages/acknowledge_job.dart';
|
||||||
import 'package:stadtbote/protocoll_messages/bootstrap_request.dart';
|
import 'package:stadtbote/protocoll_messages/bootstrap_request.dart';
|
||||||
@@ -16,9 +19,6 @@ import 'package:stadtbote/protocoll_messages/bootstrap_response_payload.dart';
|
|||||||
import 'package:stadtbote/protocoll_messages/device_log_request.dart';
|
import 'package:stadtbote/protocoll_messages/device_log_request.dart';
|
||||||
import 'package:stadtbote/protocoll_messages/device_log_response.dart';
|
import 'package:stadtbote/protocoll_messages/device_log_response.dart';
|
||||||
import 'package:stadtbote/protocoll_messages/device_object.dart';
|
import 'package:stadtbote/protocoll_messages/device_object.dart';
|
||||||
import 'package:stadtbote/model/job.dart';
|
|
||||||
import 'package:stadtbote/model/message.dart';
|
|
||||||
import 'package:stadtbote/protocoll_messages/payload_container.dart';
|
|
||||||
import 'package:stadtbote/protocoll_messages/start_session_message.dart';
|
import 'package:stadtbote/protocoll_messages/start_session_message.dart';
|
||||||
import 'package:stadtbote/protocoll_messages/sync_jobs_message.dart';
|
import 'package:stadtbote/protocoll_messages/sync_jobs_message.dart';
|
||||||
import 'package:stadtbote/protocoll_messages/track_message.dart';
|
import 'package:stadtbote/protocoll_messages/track_message.dart';
|
||||||
@@ -31,8 +31,6 @@ import 'package:stadtbote/tools/messages/session_info_update.dart';
|
|||||||
import 'package:stadtbote/tools/messages/status_info_update.dart';
|
import 'package:stadtbote/tools/messages/status_info_update.dart';
|
||||||
// ignore: depend_on_referenced_packages
|
// ignore: depend_on_referenced_packages
|
||||||
import 'package:typed_data/typed_buffers.dart';
|
import 'package:typed_data/typed_buffers.dart';
|
||||||
import 'package:http/http.dart' as http;
|
|
||||||
import 'package:uuid/uuid.dart';
|
|
||||||
|
|
||||||
import '../main.dart';
|
import '../main.dart';
|
||||||
import '../model/session_status.dart';
|
import '../model/session_status.dart';
|
||||||
@@ -52,6 +50,7 @@ class MqttCore {
|
|||||||
late bool _disconnectInProgress = false;
|
late bool _disconnectInProgress = false;
|
||||||
|
|
||||||
late String _brokerUri;
|
late String _brokerUri;
|
||||||
|
late String _clientId;
|
||||||
late int _brokerPort;
|
late int _brokerPort;
|
||||||
late String _fromServerTopic;
|
late String _fromServerTopic;
|
||||||
late String _toServerTopic;
|
late String _toServerTopic;
|
||||||
@@ -101,8 +100,8 @@ class MqttCore {
|
|||||||
_mqttClient.connectionMessage = MqttConnectMessage()
|
_mqttClient.connectionMessage = MqttConnectMessage()
|
||||||
.withClientIdentifier(await Util.getAppUuid())
|
.withClientIdentifier(await Util.getAppUuid())
|
||||||
.withWillQos(MqttQos.atMostOnce)
|
.withWillQos(MqttQos.atMostOnce)
|
||||||
.withWillTopic('willTopic')
|
//.withWillTopic('willTopic')
|
||||||
.withWillMessage('willMessage')
|
//.withWillMessage('willMessage')
|
||||||
.authenticateAs("app", "apppwd");
|
.authenticateAs("app", "apppwd");
|
||||||
|
|
||||||
await _mqttClient.connect();
|
await _mqttClient.connect();
|
||||||
@@ -145,83 +144,65 @@ class MqttCore {
|
|||||||
var buffer = Uint8Buffer();
|
var buffer = Uint8Buffer();
|
||||||
buffer.addAll(utf8.encode(text));
|
buffer.addAll(utf8.encode(text));
|
||||||
|
|
||||||
_mqttClient.publishMessage(topic, MqttQos.exactlyOnce, buffer);
|
var fullTopic = "$_toServerTopic$topic/$_clientId";
|
||||||
|
|
||||||
Util.logInfo("message\n$text\nsend to $topic");
|
_mqttClient.publishMessage(fullTopic, MqttQos.exactlyOnce, buffer);
|
||||||
}
|
|
||||||
|
|
||||||
publishPayloadMessage(String topic, Map<String, dynamic> payload) {
|
Util.logInfo("message\n$text\nsend to $fullTopic");
|
||||||
var payloadContainer = PayloadContainer();
|
|
||||||
payloadContainer.id = const Uuid().v4().toString();
|
|
||||||
payloadContainer.recv = topic;
|
|
||||||
payloadContainer.store = true;
|
|
||||||
payloadContainer.payload = payload;
|
|
||||||
|
|
||||||
var json = jsonEncode(payloadContainer.toJson());
|
|
||||||
|
|
||||||
try {
|
|
||||||
publishText(_toServerTopic, json);
|
|
||||||
} catch (e) {
|
|
||||||
_enqueueMessage(_toServerTopic, jsonEncode(payloadContainer.toJson()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setupSubscriptions() async {
|
void _setupSubscriptions() async {
|
||||||
Util.logInfo('_setupSubscriptions called');
|
Util.logInfo('_setupSubscriptions called');
|
||||||
|
|
||||||
_mqttClient.updates?.listen((List<MqttReceivedMessage<MqttMessage>> c) {
|
_mqttClient.updates?.listen((List<MqttReceivedMessage<MqttMessage>> messages) {
|
||||||
try {
|
try {
|
||||||
final MqttPublishMessage message = c[0].payload as MqttPublishMessage;
|
for (var mqttMessage in messages) {
|
||||||
String payload = utf8.decode(MqttPublishPayload.bytesToStringAsString(message.payload.message).codeUnits);
|
final MqttPublishMessage message = mqttMessage.payload as MqttPublishMessage;
|
||||||
var topic = message.variableHeader?.topicName;
|
|
||||||
|
|
||||||
Util.logInfo('message received\ntopic: $topic\nmessage: $payload');
|
if (message.variableHeader!.topicName.endsWith(_clientId)) {
|
||||||
|
String payload = utf8.decode(MqttPublishPayload.bytesToStringAsString(message.payload.message).codeUnits);
|
||||||
|
var topicArray = message.variableHeader?.topicName;
|
||||||
|
var topicArraySplited = topicArray!.split("/");
|
||||||
|
var topic = topicArraySplited[3];
|
||||||
|
|
||||||
Map<String, dynamic> messageData = jsonDecode(payload);
|
Util.logInfo('message received\ntopic: $topic\nmessage: $payload');
|
||||||
|
|
||||||
for (var entry in messageData.keys) {
|
switch(topic) {
|
||||||
if (entry == 'payload') {
|
case 'session':
|
||||||
var payload = messageData[entry];
|
_sessionMessageReceived(jsonDecode(payload));
|
||||||
for (var payloadEntry in payload.keys) {
|
break;
|
||||||
var payloadData = payload[payloadEntry];
|
|
||||||
|
|
||||||
switch(payloadEntry) {
|
case 'status':
|
||||||
case 'session':
|
_statusMessageReceived(jsonDecode(payload));
|
||||||
_sessionMessageReceived(payloadData);
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case 'status':
|
case 'ranks':
|
||||||
_statusMessageReceived(payloadData);
|
//_rankingMessageReceived(messageData);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'ranks':
|
case 'job':
|
||||||
_rankingMessageReceived(payloadData);
|
_jobMessageReceived(jsonDecode(payload));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'jobs':
|
case 'job_del':
|
||||||
_jobMessageReceived(payloadData);
|
_jobDeleteReceived(jsonDecode(payload));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'job_del':
|
case 'sync_request':
|
||||||
_jobDeleteReceived(payloadData);
|
_syncRequestReceived(jsonDecode(payload));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'sync_request':
|
case "mssg":
|
||||||
_syncRequestReceived(payloadData);
|
_messageMessageReceived(jsonDecode(payload));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "mssg":
|
case "upload_device_log":
|
||||||
_messageMessageReceived(payloadData);
|
_messageUploadDeviceLogReceived(jsonDecode(payload));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "upload_device_log":
|
default:
|
||||||
_messageUploadDeviceLogReceived(payloadData);
|
Util.logInfo('Unknown topic: $topic');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
|
||||||
Util.logInfo('Unknown topic: $payloadEntry');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -230,8 +211,9 @@ class MqttCore {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_mqttClient.subscribe(_fromServerTopic, MqttQos.exactlyOnce);
|
var fromServerTopic = "$_fromServerTopic#";
|
||||||
Util.logInfo('subscribed to topic: $_fromServerTopic');
|
_mqttClient.subscribe(fromServerTopic, MqttQos.exactlyOnce);
|
||||||
|
Util.logInfo('subscribed to topic: $fromServerTopic');
|
||||||
|
|
||||||
MessageService().publish<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, arguments: ConnectionStatus(status: ConnectionStatusEnum.connected));
|
MessageService().publish<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, arguments: ConnectionStatus(status: ConnectionStatusEnum.connected));
|
||||||
}
|
}
|
||||||
@@ -243,7 +225,7 @@ class MqttCore {
|
|||||||
|
|
||||||
await _sendEnqueuedMessages();
|
await _sendEnqueuedMessages();
|
||||||
|
|
||||||
var sessionStatusMessage = SessionStatus.fromJson(payloadData['status']);
|
var sessionStatusMessage = SessionStatus.fromJson(payloadData);
|
||||||
|
|
||||||
await MyApp.isarInstance.writeTxn(() async {
|
await MyApp.isarInstance.writeTxn(() async {
|
||||||
await MyApp.isarInstance.sessionStatus.clear();
|
await MyApp.isarInstance.sessionStatus.clear();
|
||||||
@@ -279,28 +261,26 @@ class MqttCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _jobMessageReceived(payloadData) async {
|
void _jobMessageReceived(payloadData) async {
|
||||||
for (var foundJobData in payloadData) {
|
Job newJob = Job.fromJson(payloadData);
|
||||||
Job newJob = Job.fromJson(foundJobData);
|
|
||||||
|
|
||||||
await MyApp.isarInstance.writeTxn(() async {
|
await MyApp.isarInstance.writeTxn(() async {
|
||||||
await MyApp.isarInstance.jobs.put(newJob);
|
await MyApp.isarInstance.jobs.put(newJob);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (newJob.state == Constants.stateAssigned) {
|
if (newJob.state == Constants.stateAssigned) {
|
||||||
if (newJob.global) {
|
if (newJob.global) {
|
||||||
await Util.playMp3('aaa.mp3');
|
await Util.playMp3('aaa.mp3');
|
||||||
} else {
|
} else {
|
||||||
await Util.playMp3('job_received.mp3');
|
await Util.playMp3('job_received.mp3');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
_acknowlegdeJob(newJob);
|
||||||
MessageService().publish<JobReceivedMessage>(Constants.messageTopicJobReceived, arguments: JobReceivedMessage(job: newJob));
|
|
||||||
} catch (ex) {
|
|
||||||
Util.logException("publish messageTopicJobReceived failed!");
|
|
||||||
}
|
|
||||||
|
|
||||||
_acknowlegdeJob(newJob);
|
try {
|
||||||
|
MessageService().publish<JobReceivedMessage>(Constants.messageTopicJobReceived, arguments: JobReceivedMessage(job: newJob));
|
||||||
|
} catch (ex) {
|
||||||
|
Util.logException("publish messageTopicJobReceived failed!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,18 +382,19 @@ class MqttCore {
|
|||||||
handshakeMessage.ver = await Util.getAppVersion();
|
handshakeMessage.ver = await Util.getAppVersion();
|
||||||
|
|
||||||
var jsonMap = handshakeMessage.toJson();
|
var jsonMap = handshakeMessage.toJson();
|
||||||
var json = jsonEncode(jsonMap);
|
var json = Uri.encodeFull(jsonEncode(jsonMap));
|
||||||
var uri = "http://test-app-server.dns.army:8080=$json";
|
var uri = "http://test-app-server.dns.army:8080/bootstrap?json=$json";
|
||||||
Util.logInfo("Bootstrap request: $uri");
|
Util.logInfo("Bootstrap request: $uri");
|
||||||
|
|
||||||
var response = await http.get(Uri.parse(uri));
|
var response = await http.get(Uri.parse(uri));
|
||||||
var responseText = response.body;
|
var responseText = response.body;
|
||||||
|
|
||||||
var bootstrapResponsePayload = BootstrapResponse.fromJson(jsonDecode(responseText)["payload"]);
|
var bootstrapResponsePayload = BootstrapResponse.fromJson(jsonDecode(responseText));
|
||||||
|
|
||||||
var brokerUriAndPortArray = bootstrapResponsePayload.broker.replaceFirst("mqtt://", "").split(":");
|
var brokerUriAndPortArray = bootstrapResponsePayload.broker.replaceFirst("mqtt://", "").split(":");
|
||||||
_brokerUri = brokerUriAndPortArray[0];
|
_brokerUri = brokerUriAndPortArray[0];
|
||||||
_brokerPort = int.parse(brokerUriAndPortArray[1]);
|
_brokerPort = int.parse(brokerUriAndPortArray[1]);
|
||||||
|
_clientId = bootstrapResponsePayload.id;
|
||||||
_fromServerTopic = bootstrapResponsePayload.fromServer;
|
_fromServerTopic = bootstrapResponsePayload.fromServer;
|
||||||
_toServerTopic = bootstrapResponsePayload.toServer;
|
_toServerTopic = bootstrapResponsePayload.toServer;
|
||||||
|
|
||||||
@@ -446,7 +427,7 @@ class MqttCore {
|
|||||||
answer.sync.jobs.add(syncJob);
|
answer.sync.jobs.add(syncJob);
|
||||||
}
|
}
|
||||||
|
|
||||||
MqttCore.instance.publishPayloadMessage("server", answer.toJson());
|
MqttCore.instance.publishText("sync_request_response", jsonEncode(answer.toJson()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _startTrackTimer() {
|
void _startTrackTimer() {
|
||||||
@@ -460,7 +441,7 @@ class MqttCore {
|
|||||||
trackMessage.pos!.long = position.longitude;
|
trackMessage.pos!.long = position.longitude;
|
||||||
trackMessage.pos!.acc = position.accuracy.toInt();
|
trackMessage.pos!.acc = position.accuracy.toInt();
|
||||||
|
|
||||||
publishPayloadMessage("track", trackMessage.toJson());
|
publishText("track", jsonEncode(trackMessage.toJson()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -507,6 +488,6 @@ class MqttCore {
|
|||||||
message.received.ver = job.ver;
|
message.received.ver = job.ver;
|
||||||
message.received.utc = DateTime.now().millisecondsSinceEpoch;
|
message.received.utc = DateTime.now().millisecondsSinceEpoch;
|
||||||
|
|
||||||
MqttCore.instance.publishPayloadMessage('job', message.toJson());
|
MqttCore.instance.publishText('job', jsonEncode(message.toJson()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user