feat(server): user preferences (#9736)
* refactor(server): user endpoints * feat(server): user preferences * mobile: user preference * wording --------- Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
@@ -27,8 +27,10 @@ class User {
|
||||
|
||||
Id get isarId => fastHash(id);
|
||||
|
||||
User.fromUserDto(UserAdminResponseDto dto)
|
||||
: id = dto.id,
|
||||
User.fromUserDto(
|
||||
UserAdminResponseDto dto,
|
||||
UserPreferencesResponseDto? preferences,
|
||||
) : id = dto.id,
|
||||
updatedAt = dto.updatedAt,
|
||||
email = dto.email,
|
||||
name = dto.name,
|
||||
@@ -36,7 +38,7 @@ class User {
|
||||
isPartnerSharedWith = false,
|
||||
profileImagePath = dto.profileImagePath,
|
||||
isAdmin = dto.isAdmin,
|
||||
memoryEnabled = dto.memoriesEnabled ?? false,
|
||||
memoryEnabled = preferences?.memories.enabled ?? false,
|
||||
avatarColor = dto.avatarColor.toAvatarColor(),
|
||||
inTimeline = false,
|
||||
quotaUsageInBytes = dto.quotaUsageInBytes ?? 0,
|
||||
|
||||
@@ -177,8 +177,10 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
|
||||
retResult = false;
|
||||
} else {
|
||||
UserAdminResponseDto? userResponseDto;
|
||||
UserPreferencesResponseDto? userPreferences;
|
||||
try {
|
||||
userResponseDto = await _apiService.userApi.getMyUser();
|
||||
userPreferences = await _apiService.userApi.getMyPreferences();
|
||||
} on ApiException catch (error, stackTrace) {
|
||||
_log.severe(
|
||||
"Error getting user information from the server [API EXCEPTION]",
|
||||
@@ -201,13 +203,13 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
|
||||
Store.put(StoreKey.deviceIdHash, fastHash(deviceId));
|
||||
Store.put(
|
||||
StoreKey.currentUser,
|
||||
User.fromUserDto(userResponseDto),
|
||||
User.fromUserDto(userResponseDto, userPreferences),
|
||||
);
|
||||
Store.put(StoreKey.serverUrl, serverUrl);
|
||||
Store.put(StoreKey.accessToken, accessToken);
|
||||
|
||||
shouldChangePassword = userResponseDto.shouldChangePassword;
|
||||
user = User.fromUserDto(userResponseDto);
|
||||
user = User.fromUserDto(userResponseDto, userPreferences);
|
||||
|
||||
retResult = true;
|
||||
} else {
|
||||
|
||||
@@ -21,10 +21,11 @@ class CurrentUserProvider extends StateNotifier<User?> {
|
||||
refresh() async {
|
||||
try {
|
||||
final user = await _apiService.userApi.getMyUser();
|
||||
final userPreferences = await _apiService.userApi.getMyPreferences();
|
||||
if (user != null) {
|
||||
Store.put(
|
||||
StoreKey.currentUser,
|
||||
User.fromUserDto(user),
|
||||
User.fromUserDto(user, userPreferences),
|
||||
);
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
@@ -58,6 +58,8 @@ class TabNavigationObserver extends AutoRouterObserver {
|
||||
try {
|
||||
final userResponseDto =
|
||||
await ref.read(apiServiceProvider).userApi.getMyUser();
|
||||
final userPreferences =
|
||||
await ref.read(apiServiceProvider).userApi.getMyPreferences();
|
||||
|
||||
if (userResponseDto == null) {
|
||||
return;
|
||||
@@ -65,7 +67,7 @@ class TabNavigationObserver extends AutoRouterObserver {
|
||||
|
||||
Store.put(
|
||||
StoreKey.currentUser,
|
||||
User.fromUserDto(userResponseDto),
|
||||
User.fromUserDto(userResponseDto, userPreferences),
|
||||
);
|
||||
ref.read(serverInfoProvider.notifier).getServerVersion();
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user