-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
590 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2024 The Coagulate Authors. All rights reserved. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:bloc/bloc.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
import 'package:latlong2/latlong.dart'; | ||
import 'package:location/location.dart'; | ||
|
||
import '../../../data/models/contact_location.dart'; | ||
import '../../../data/repositories/contacts.dart'; | ||
|
||
part 'cubit.g.dart'; | ||
part 'state.dart'; | ||
|
||
class ScheduleCubit extends Cubit<ScheduleState> { | ||
ScheduleCubit(this.contactsRepository) | ||
: super(ScheduleState( | ||
checkingIn: false, circles: contactsRepository.getCircles())); | ||
|
||
final ContactsRepository contactsRepository; | ||
|
||
Future<void> schedule({ | ||
required String name, | ||
required String details, | ||
required DateTime start, | ||
required DateTime end, | ||
required LatLng coordinates, | ||
required List<String> circles, | ||
}) async { | ||
emit(state.copyWith(checkingIn: true)); | ||
|
||
final profileContact = contactsRepository.getProfileContact(); | ||
if (profileContact == null) { | ||
if (!isClosed) { | ||
//TODO: Emit failure state | ||
emit(state.copyWith(checkingIn: false)); | ||
} | ||
return; | ||
} | ||
|
||
// TODO: Switch to unawaited because it'll be synced eventually? | ||
await contactsRepository | ||
.updateContact(profileContact.copyWith(temporaryLocations: [ | ||
...profileContact.temporaryLocations | ||
.map((l) => l.copyWith(checkedIn: false)), | ||
ContactTemporaryLocation( | ||
coagContactId: contactsRepository.profileContactId!, | ||
longitude: coordinates.longitude, | ||
latitude: coordinates.latitude, | ||
start: start, | ||
name: name, | ||
details: details, | ||
end: end, | ||
circles: circles) | ||
])) | ||
// Make sure to regenerate the sharing profiles and update DHT sharing records | ||
.then((_) => contactsRepository | ||
.updateProfileContact(profileContact.coagContactId)); | ||
|
||
if (!isClosed) { | ||
emit(state.copyWith(checkingIn: false)); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2024 The Coagulate Authors. All rights reserved. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
part of 'cubit.dart'; | ||
|
||
@JsonSerializable() | ||
final class ScheduleState extends Equatable { | ||
const ScheduleState({required this.checkingIn, required this.circles}); | ||
|
||
factory ScheduleState.fromJson(Map<String, dynamic> json) => | ||
_$ScheduleStateFromJson(json); | ||
|
||
final bool checkingIn; | ||
final Map<String, String> circles; | ||
|
||
Map<String, dynamic> toJson() => _$ScheduleStateToJson(this); | ||
|
||
ScheduleState copyWith({bool? checkingIn, Map<String, String>? circles}) => | ||
ScheduleState( | ||
checkingIn: checkingIn ?? this.checkingIn, | ||
circles: circles ?? this.circles); | ||
|
||
@override | ||
List<Object?> get props => [checkingIn, circles]; | ||
} |
Oops, something went wrong.