calculateLocationSharingAllEvents method
dynamic
calculateLocationSharingAllEvents({
- List<
EventKeyLocationModel> ? listOfEvents, - bool initLocationSharing = false,
will calculate LocationDataModel
for allEventNotifications if listOfEvents
is not provided
Implementation
calculateLocationSharingAllEvents(
{List<EventKeyLocationModel>? listOfEvents,
bool initLocationSharing = false}) async {
List<String> atsignToShareLocWith = [];
List<LocationDataModel> locationToShareWith = [];
for (var eventKeyLocationModel in (listOfEvents ?? allEventNotifications)) {
if ((eventKeyLocationModel.eventNotificationModel == null) ||
(eventKeyLocationModel.eventNotificationModel!.isCancelled == true)) {
continue;
}
var eventNotificationModel =
eventKeyLocationModel.eventNotificationModel!;
/// calculate atsigns to share loc with
atsignToShareLocWith = [];
if (!compareAtSign(
eventKeyLocationModel.eventNotificationModel!.atsignCreator!,
AtClientManager.getInstance().atClient.getCurrentAtSign()!)) {
atsignToShareLocWith
.add(eventKeyLocationModel.eventNotificationModel!.atsignCreator!);
}
if (eventKeyLocationModel
.eventNotificationModel!.group!.members!.isNotEmpty) {
Set<AtContact>? groupMembers =
eventKeyLocationModel.eventNotificationModel!.group!.members!;
// ignore: avoid_function_literals_in_foreach_calls
groupMembers.forEach((member) {
if (!compareAtSign(member.atSign!,
AtClientManager.getInstance().atClient.getCurrentAtSign()!)) {
atsignToShareLocWith.add(member.atSign!);
}
});
}
// converting event data to locationDataModel
locationToShareWith = [
...locationToShareWith,
...eventNotificationToLocationDataModel(
eventKeyLocationModel.eventNotificationModel!, atsignToShareLocWith)
];
}
if (initLocationSharing) {
SendLocationNotification().initEventData(locationToShareWith);
} else {
await Future.forEach(locationToShareWith,
(LocationDataModel _locationDataModel) async {
await SendLocationNotification().addMember(_locationDataModel);
});
}
}