updateWithShareLocationAcknowledge method
Updates originally created locationNotificationModel
with originalLocationNotificationModel
data
Implementation
Future<bool> updateWithShareLocationAcknowledge(
LocationNotificationModel originalLocationNotificationModel,
{bool? isSharing,
bool rePrompt = false,
bool shouldCheckForTimeChanges = false}) async {
try {
var locationNotificationModel = LocationNotificationModel.fromJson(
jsonDecode(
LocationNotificationModel.convertLocationNotificationToJson(
originalLocationNotificationModel)));
var atkeyMicrosecondId = locationNotificationModel.key!
.split('sharelocation-')[1]
.split('@')[0];
var response =
await AtLocationNotificationListener().atClientInstance!.getKeys(
regex: 'sharelocation-$atkeyMicrosecondId',
);
var key = getAtKey(response[0]);
key.sharedBy = locationNotificationModel.atsignCreator;
key.sharedWith = locationNotificationModel.receiver;
locationNotificationModel.isAcknowledgment = true;
locationNotificationModel.rePrompt =
rePrompt; // Dont show dialog box again
if (isSharing != null) locationNotificationModel.isSharing = isSharing;
var notification =
LocationNotificationModel.convertLocationNotificationToJson(
locationNotificationModel);
if ((locationNotificationModel.from != null) &&
(locationNotificationModel.to != null)) {
key.metadata.ttl = locationNotificationModel.to!
.difference(locationNotificationModel.from!)
.inMinutes *
60000;
key.metadata.ttr = locationNotificationModel.to!
.difference(locationNotificationModel.from!)
.inMinutes *
60000;
key.metadata.expiresAt = locationNotificationModel.to;
}
if (shouldCheckForTimeChanges) {
var result = await NotifyAndPut().notifyAndPut(
key,
notification,
);
if (result) {
await KeyStreamService().mapUpdatedLocationDataToWidget(
locationNotificationModel,
shouldCheckForTimeChanges: shouldCheckForTimeChanges);
}
_logger.finer('update result - $result');
return result;
} else {
await KeyStreamService()
.mapUpdatedLocationDataToWidget(locationNotificationModel);
return true;
}
} catch (e) {
_logger.severe('update share location failed $e');
return false;
}
}