Authenticate reviews with Telegram init data
All checks were successful
Build and deploy Flutter Web / build (push) Successful in 3m1s
All checks were successful
Build and deploy Flutter Web / build (push) Successful in 3m1s
This commit is contained in:
@@ -12,12 +12,16 @@ class PlaceState {
|
||||
required this.selectedTrait,
|
||||
required this.places,
|
||||
required this.selectedPlaceId,
|
||||
required this.currentUser,
|
||||
required this.hasTelegramAuth,
|
||||
required this.reviewDraft,
|
||||
});
|
||||
|
||||
final PlaceTrait selectedTrait;
|
||||
final List<PlaceRecommendation> places;
|
||||
final String? selectedPlaceId;
|
||||
final AppUser? currentUser;
|
||||
final bool hasTelegramAuth;
|
||||
final VoiceReviewDraft reviewDraft;
|
||||
|
||||
List<PlaceRecommendation> get recommendations {
|
||||
@@ -43,12 +47,16 @@ class PlaceState {
|
||||
PlaceTrait? selectedTrait,
|
||||
List<PlaceRecommendation>? places,
|
||||
String? selectedPlaceId,
|
||||
AppUser? currentUser,
|
||||
bool? hasTelegramAuth,
|
||||
VoiceReviewDraft? reviewDraft,
|
||||
}) {
|
||||
return PlaceState(
|
||||
selectedTrait: selectedTrait ?? this.selectedTrait,
|
||||
places: places ?? this.places,
|
||||
selectedPlaceId: selectedPlaceId ?? this.selectedPlaceId,
|
||||
currentUser: currentUser ?? this.currentUser,
|
||||
hasTelegramAuth: hasTelegramAuth ?? this.hasTelegramAuth,
|
||||
reviewDraft: reviewDraft ?? this.reviewDraft,
|
||||
);
|
||||
}
|
||||
@@ -59,11 +67,14 @@ class PlaceController extends AsyncNotifier<PlaceState> {
|
||||
|
||||
@override
|
||||
Future<PlaceState> build() async {
|
||||
final currentUser = await _api.authenticateTelegram();
|
||||
final places = await _api.fetchPlaces();
|
||||
return PlaceState(
|
||||
selectedTrait: PlaceTrait.calm,
|
||||
places: places,
|
||||
selectedPlaceId: places.isEmpty ? null : places.first.id,
|
||||
currentUser: currentUser,
|
||||
hasTelegramAuth: _api.hasTelegramAuth,
|
||||
reviewDraft: const VoiceReviewDraft(
|
||||
placeName: '',
|
||||
duration: Duration.zero,
|
||||
@@ -112,6 +123,10 @@ class PlaceController extends AsyncNotifier<PlaceState> {
|
||||
|
||||
Future<void> publishReview({LatLng? coordinate}) async {
|
||||
final value = state.requireValue;
|
||||
if (!value.hasTelegramAuth) {
|
||||
throw StateError('Открой через Telegram, чтобы оставить голос.');
|
||||
}
|
||||
|
||||
final draft = value.reviewDraft;
|
||||
final placeName = draft.placeName.trim().isEmpty
|
||||
? 'Место на карте'
|
||||
|
||||
Reference in New Issue
Block a user