add profile page, privacy options
All checks were successful
Release / meta (push) Successful in 11s
Release / linux-build (push) Successful in 1m0s
Release / web-build (push) Successful in 2m29s
Release / android-build (push) Successful in 10m26s
Release / release-master (push) Successful in 37s
Release / release-dev (push) Successful in 49s
All checks were successful
Release / meta (push) Successful in 11s
Release / linux-build (push) Successful in 1m0s
Release / web-build (push) Successful in 2m29s
Release / android-build (push) Successful in 10m26s
Release / release-master (push) Successful in 37s
Release / release-dev (push) Successful in 49s
This commit is contained in:
@@ -21,6 +21,8 @@ class AuthService extends ChangeNotifier {
|
||||
String? get userId => _user?.userId;
|
||||
String? get username => _user?.username;
|
||||
String? get fullName => _user?.fullName;
|
||||
String get entriesVisibility => _user?.entriesVisibility ?? 'private';
|
||||
String get mileageVisibility => _user?.mileageVisibility ?? 'private';
|
||||
bool get isElevated => _user?.isElevated ?? false;
|
||||
bool get isAdmin => isElevated; // alias for old name
|
||||
bool get isDisabled => _user?.disabled ?? false;
|
||||
@@ -31,6 +33,8 @@ class AuthService extends ChangeNotifier {
|
||||
required String fullName,
|
||||
required String accessToken,
|
||||
required String email,
|
||||
String entriesVisibility = 'private',
|
||||
String mileageVisibility = 'private',
|
||||
bool isElevated = false,
|
||||
bool isDisabled = false,
|
||||
}) {
|
||||
@@ -40,6 +44,8 @@ class AuthService extends ChangeNotifier {
|
||||
fullName: fullName,
|
||||
accessToken: accessToken,
|
||||
email: email,
|
||||
entriesVisibility: entriesVisibility,
|
||||
mileageVisibility: mileageVisibility,
|
||||
isElevated: isElevated,
|
||||
disabled: isDisabled,
|
||||
);
|
||||
@@ -77,6 +83,14 @@ class AuthService extends ChangeNotifier {
|
||||
fullName: userResponse['full_name'],
|
||||
accessToken: accessToken,
|
||||
email: userResponse['email'],
|
||||
entriesVisibility: _parseVisibility(
|
||||
userResponse['user_entries_visibility'] ?? userResponse['entries_visibility'],
|
||||
'private',
|
||||
),
|
||||
mileageVisibility: _parseVisibility(
|
||||
userResponse['user_mileage_visibility'] ?? userResponse['mileage_visibility'],
|
||||
'private',
|
||||
),
|
||||
isElevated: _parseIsElevated(userResponse),
|
||||
isDisabled: _parseIsDisabled(userResponse),
|
||||
);
|
||||
@@ -98,16 +112,24 @@ class AuthService extends ChangeNotifier {
|
||||
},
|
||||
);
|
||||
|
||||
setLoginData(
|
||||
userId: userResponse['user_id'],
|
||||
username: userResponse['username'],
|
||||
fullName: userResponse['full_name'],
|
||||
accessToken: token,
|
||||
email: userResponse['email'],
|
||||
isElevated: _parseIsElevated(userResponse),
|
||||
isDisabled: _parseIsDisabled(userResponse),
|
||||
);
|
||||
} catch (_) {
|
||||
setLoginData(
|
||||
userId: userResponse['user_id'],
|
||||
username: userResponse['username'],
|
||||
fullName: userResponse['full_name'],
|
||||
accessToken: token,
|
||||
email: userResponse['email'],
|
||||
entriesVisibility: _parseVisibility(
|
||||
userResponse['user_entries_visibility'] ?? userResponse['entries_visibility'],
|
||||
'private',
|
||||
),
|
||||
mileageVisibility: _parseVisibility(
|
||||
userResponse['user_mileage_visibility'] ?? userResponse['mileage_visibility'],
|
||||
'private',
|
||||
),
|
||||
isElevated: _parseIsElevated(userResponse),
|
||||
isDisabled: _parseIsDisabled(userResponse),
|
||||
);
|
||||
} catch (_) {
|
||||
await _clearToken();
|
||||
} finally {
|
||||
_restoring = false;
|
||||
@@ -224,4 +246,11 @@ class AuthService extends ChangeNotifier {
|
||||
if (str == null || str.isEmpty) return false;
|
||||
return ['1', 'true', 'yes', 'y', 'disabled'].contains(str);
|
||||
}
|
||||
|
||||
String _parseVisibility(dynamic value, String fallback) {
|
||||
const allowed = ['private', 'friends', 'public'];
|
||||
final str = value?.toString().toLowerCase().trim();
|
||||
if (str != null && allowed.contains(str)) return str;
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ class _LegFetchOptions {
|
||||
final int sortDirection;
|
||||
final String? dateRangeStart;
|
||||
final String? dateRangeEnd;
|
||||
final bool unallocatedOnly;
|
||||
|
||||
const _LegFetchOptions({
|
||||
this.limit = 100,
|
||||
@@ -13,6 +14,7 @@ class _LegFetchOptions {
|
||||
this.sortDirection = 0,
|
||||
this.dateRangeStart,
|
||||
this.dateRangeEnd,
|
||||
this.unallocatedOnly = false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -119,6 +121,16 @@ class DataService extends ChangeNotifier {
|
||||
bool _isNotificationsLoading = false;
|
||||
bool get isNotificationsLoading => _isNotificationsLoading;
|
||||
|
||||
// Privacy
|
||||
String _userEntriesVisibility = 'private';
|
||||
String _userMileageVisibility = 'private';
|
||||
bool _isPrivacyLoading = false;
|
||||
bool _isPrivacySaving = false;
|
||||
String get userEntriesVisibility => _userEntriesVisibility;
|
||||
String get userMileageVisibility => _userMileageVisibility;
|
||||
bool get isPrivacyLoading => _isPrivacyLoading;
|
||||
bool get isPrivacySaving => _isPrivacySaving;
|
||||
|
||||
// Badges
|
||||
List<BadgeAward> _badgeAwards = [];
|
||||
List<BadgeAward> get badgeAwards => _badgeAwards;
|
||||
@@ -161,6 +173,127 @@ class DataService extends ChangeNotifier {
|
||||
});
|
||||
}
|
||||
|
||||
int _visibilityRank(String value) {
|
||||
switch (value.toLowerCase()) {
|
||||
case 'public':
|
||||
return 2;
|
||||
case 'friends':
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
String _normaliseVisibility(
|
||||
dynamic value, {
|
||||
required String fallback,
|
||||
}) {
|
||||
const allowed = ['private', 'friends', 'public'];
|
||||
final str = value?.toString().toLowerCase().trim();
|
||||
if (str != null && allowed.contains(str)) return str;
|
||||
return fallback;
|
||||
}
|
||||
|
||||
String _clampMileageVisibility(String entries, String mileage) {
|
||||
return _visibilityRank(mileage) < _visibilityRank(entries)
|
||||
? entries
|
||||
: mileage;
|
||||
}
|
||||
|
||||
void _applyPrivacy(dynamic source) {
|
||||
String entries = _userEntriesVisibility;
|
||||
String mileage = _userMileageVisibility;
|
||||
if (source is Map) {
|
||||
entries = _normaliseVisibility(
|
||||
source['user_entries_visibility'] ?? source['entries_visibility'],
|
||||
fallback: entries,
|
||||
);
|
||||
mileage = _normaliseVisibility(
|
||||
source['user_mileage_visibility'] ?? source['mileage_visibility'],
|
||||
fallback: mileage,
|
||||
);
|
||||
} else if (source is UserData) {
|
||||
entries = _normaliseVisibility(
|
||||
source.entriesVisibility,
|
||||
fallback: entries,
|
||||
);
|
||||
mileage = _normaliseVisibility(
|
||||
source.mileageVisibility,
|
||||
fallback: mileage,
|
||||
);
|
||||
}
|
||||
_userEntriesVisibility = entries;
|
||||
_userMileageVisibility = _clampMileageVisibility(entries, mileage);
|
||||
}
|
||||
|
||||
Future<void> fetchPrivacySettings({String? targetUserId}) async {
|
||||
_isPrivacyLoading = true;
|
||||
_notifyAsync();
|
||||
try {
|
||||
Map<String, dynamic>? payload;
|
||||
final hasTarget = targetUserId?.isNotEmpty ?? false;
|
||||
if (!hasTarget) {
|
||||
try {
|
||||
final json = await api.get('/users/me');
|
||||
if (json is Map<String, dynamic>) {
|
||||
payload = json;
|
||||
} else if (json is Map) {
|
||||
payload = json.map((k, v) => MapEntry(k.toString(), v));
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('Failed to fetch /users/me: $e');
|
||||
}
|
||||
}
|
||||
if (payload == null) {
|
||||
final query = hasTarget ? '?target_user_id=$targetUserId' : '';
|
||||
try {
|
||||
final json = await api.get('/users/privacy$query');
|
||||
if (json is Map<String, dynamic>) {
|
||||
payload = json;
|
||||
} else if (json is Map) {
|
||||
payload = json.map((k, v) => MapEntry(k.toString(), v));
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('Failed to fetch /users/privacy: $e');
|
||||
}
|
||||
}
|
||||
if (payload != null) {
|
||||
_applyPrivacy(payload);
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('Failed to fetch privacy settings: $e');
|
||||
} finally {
|
||||
_isPrivacyLoading = false;
|
||||
_notifyAsync();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updatePrivacySettings({
|
||||
required String entriesVisibility,
|
||||
required String mileageVisibility,
|
||||
String? targetUserId,
|
||||
}) async {
|
||||
_isPrivacySaving = true;
|
||||
_notifyAsync();
|
||||
try {
|
||||
final query = (targetUserId?.isNotEmpty ?? false)
|
||||
? '?target_user_id=$targetUserId'
|
||||
: '';
|
||||
await api.post('/users/privacy$query', {
|
||||
'user_entries_visibility': entriesVisibility,
|
||||
'user_mileage_visibility': mileageVisibility,
|
||||
});
|
||||
_userEntriesVisibility = entriesVisibility;
|
||||
_userMileageVisibility = mileageVisibility;
|
||||
} catch (e) {
|
||||
debugPrint('Failed to update privacy settings: $e');
|
||||
rethrow;
|
||||
} finally {
|
||||
_isPrivacySaving = false;
|
||||
_notifyAsync();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchHomepageStats() async {
|
||||
_isHomepageLoading = true;
|
||||
|
||||
@@ -170,6 +303,9 @@ class DataService extends ChangeNotifier {
|
||||
_trips = [...(_homepageStats?.trips ?? const [])]
|
||||
..sort(TripSummary.compareByDateDesc);
|
||||
_friendsLeaderboard = _homepageStats?.friendsLeaderboard ?? [];
|
||||
if (_homepageStats?.user != null) {
|
||||
_applyPrivacy(_homepageStats!.user!);
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('Failed to fetch homepage stats: $e');
|
||||
_homepageStats = null;
|
||||
@@ -181,6 +317,53 @@ class DataService extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Future<UserProfileDetail?> fetchUserProfileDetail(String userId) async {
|
||||
try {
|
||||
final json = await api.get('/user/$userId');
|
||||
if (json is Map) {
|
||||
return UserProfileDetail.fromJson(
|
||||
json.map((k, v) => MapEntry(k.toString(), v)),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('Failed to fetch user profile for $userId: $e');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<List<Leg>> fetchUserLegs({
|
||||
required String userId,
|
||||
int offset = 0,
|
||||
int limit = 25,
|
||||
}) async {
|
||||
try {
|
||||
final json =
|
||||
await api.get('/legs/user/$userId?offset=$offset&limit=$limit');
|
||||
List<dynamic>? list;
|
||||
if (json is List) {
|
||||
list = json;
|
||||
} else if (json is Map) {
|
||||
for (final key in ['legs', 'data', 'results', 'items']) {
|
||||
final value = json[key];
|
||||
if (value is List) {
|
||||
list = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (list == null) return const [];
|
||||
return list
|
||||
.whereType<Map>()
|
||||
.map((e) => Leg.fromJson(
|
||||
e.map((k, v) => MapEntry(k.toString(), v)),
|
||||
))
|
||||
.toList();
|
||||
} catch (e) {
|
||||
debugPrint('Failed to fetch user legs for $userId: $e');
|
||||
return const [];
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchLegs({
|
||||
int offset = 0,
|
||||
int limit = 100,
|
||||
@@ -189,6 +372,7 @@ class DataService extends ChangeNotifier {
|
||||
String? dateRangeStart,
|
||||
String? dateRangeEnd,
|
||||
bool append = false,
|
||||
bool unallocatedOnly = false,
|
||||
}) async {
|
||||
_isLegsLoading = true;
|
||||
if (!append) {
|
||||
@@ -198,6 +382,7 @@ class DataService extends ChangeNotifier {
|
||||
sortDirection: sortDirection,
|
||||
dateRangeStart: dateRangeStart,
|
||||
dateRangeEnd: dateRangeEnd,
|
||||
unallocatedOnly: unallocatedOnly,
|
||||
);
|
||||
}
|
||||
final buffer = StringBuffer(
|
||||
@@ -209,6 +394,9 @@ class DataService extends ChangeNotifier {
|
||||
if (dateRangeEnd != null && dateRangeEnd.isNotEmpty) {
|
||||
buffer.write('&date_range_end=$dateRangeEnd');
|
||||
}
|
||||
if (unallocatedOnly) {
|
||||
buffer.write('&unallocated_only=true');
|
||||
}
|
||||
try {
|
||||
final json = await api.get('/user/legs${buffer.toString()}');
|
||||
|
||||
@@ -237,6 +425,7 @@ class DataService extends ChangeNotifier {
|
||||
sortDirection: _lastLegsFetch.sortDirection,
|
||||
dateRangeStart: _lastLegsFetch.dateRangeStart,
|
||||
dateRangeEnd: _lastLegsFetch.dateRangeEnd,
|
||||
unallocatedOnly: _lastLegsFetch.unallocatedOnly,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -431,6 +620,10 @@ class DataService extends ChangeNotifier {
|
||||
_stationFiltersFetchedAt = null;
|
||||
_notifications = [];
|
||||
_isNotificationsLoading = false;
|
||||
_userEntriesVisibility = 'private';
|
||||
_userMileageVisibility = 'private';
|
||||
_isPrivacyLoading = false;
|
||||
_isPrivacySaving = false;
|
||||
_badgeAwards = [];
|
||||
_badgeAwardsHasMore = false;
|
||||
_isBadgeAwardsLoading = false;
|
||||
@@ -443,11 +636,24 @@ class DataService extends ChangeNotifier {
|
||||
_notifyAsync();
|
||||
}
|
||||
|
||||
void handleAuthChanged(String? userId) {
|
||||
if (_currentUserId == userId) return;
|
||||
_currentUserId = userId;
|
||||
clear();
|
||||
void handleAuthChanged(
|
||||
String? userId, {
|
||||
String? entriesVisibility,
|
||||
String? mileageVisibility,
|
||||
}) {
|
||||
final sameUser = _currentUserId == userId;
|
||||
_currentUserId = userId;
|
||||
if (!sameUser) {
|
||||
clear();
|
||||
_currentUserId = userId;
|
||||
}
|
||||
if (entriesVisibility != null || mileageVisibility != null) {
|
||||
_applyPrivacy({
|
||||
'user_entries_visibility': entriesVisibility,
|
||||
'user_mileage_visibility': mileageVisibility,
|
||||
});
|
||||
_notifyAsync();
|
||||
}
|
||||
}
|
||||
|
||||
double getMileageForCurrentYear() {
|
||||
|
||||
Reference in New Issue
Block a user