Skip to content

Commit

Permalink
TW-692: Implement UploadProfile in presentation layer
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev authored and hoangdat committed Oct 4, 2023
1 parent 240a31f commit a8a9589
Show file tree
Hide file tree
Showing 26 changed files with 1,019 additions and 545 deletions.
7 changes: 3 additions & 4 deletions assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,7 @@
"type": "text",
"placeholders": {}
},
"search": "Search for people and channels",
"searchForPeopleAndChannels": "Search for people and channels",
"@search": {
"type": "text",
"placeholders": {}
Expand Down Expand Up @@ -2647,7 +2647,6 @@
"tapToAllowAccessToYourGallery": "Tap to allow access to your Gallery",
"tapToAllowAccessToYourCamera": "You can enable camera access in the Settings app to make video calls in",
"twake": "Twake",
"dismiss": "Dismiss",
"permissionAccess": "Permission access",
"allow": "Allow",
"explainStoragePermission": "Twake need access to your storage to preview file",
Expand All @@ -2669,7 +2668,6 @@
}
},
"keyboard": "Keyboard",
"tapToAllowAccessToYourGallery": "Tap to allow access to your Gallery",
"changeChatAvatar": "Change the Chat avatar",
"roomAvatarMaxFileSize": "The avatar size is too large",
"@roomAvatarMaxFileSize": {},
Expand Down Expand Up @@ -2755,5 +2753,6 @@
"editProfileDescriptions": "Update your profile with a new name, picture and a short introduction.",
"workIdentitiesInfo": "WORK IDENTITIES INFO",
"editWorkIdentitiesDescriptions": "Edit your work identity settings such as Matrix ID, email or company name.",
"copiedMatrixIdToClipboard": "Copied Matrix ID to clipboard."
"copiedMatrixIdToClipboard": "Copied Matrix ID to clipboard.",
"changeProfilePhoto": "Change profile photo"
}
4 changes: 1 addition & 3 deletions lib/config/go_routes/go_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,7 @@ abstract class AppRoutes {
path: 'profile',
pageBuilder: (context, state) => defaultPageBuilder(
context,
SettingsProfile(
profile: state.extra as Profile?,
),
const SettingsProfile(),
),
),
GoRoute(
Expand Down
6 changes: 3 additions & 3 deletions lib/di/global/get_it_initializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import 'package:fluffychat/domain/usecase/send_file_interactor.dart';
import 'package:fluffychat/domain/usecase/send_file_on_web_interactor.dart';
import 'package:fluffychat/domain/usecase/send_image_interactor.dart';
import 'package:fluffychat/domain/usecase/send_images_interactor.dart';
import 'package:fluffychat/domain/usecase/settings/upload_profile_interactor.dart';
import 'package:fluffychat/domain/usecase/settings/update_profile_interactor.dart';
import 'package:fluffychat/event/twake_event_dispatcher.dart';
import 'package:fluffychat/utils/responsive/responsive_utils.dart';
import 'package:get_it/get_it.dart';
Expand Down Expand Up @@ -178,8 +178,8 @@ class GetItInitializer {
getIt.registerSingleton<TimelineSearchEventInteractor>(
TimelineSearchEventInteractor(),
);
getIt.registerSingleton<UploadProfileInteractor>(
UploadProfileInteractor(),
getIt.registerSingleton<UpdateProfileInteractor>(
UpdateProfileInteractor(),
);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:fluffychat/app_state/failure.dart';

class UploadProfileFailure extends Failure {
class UpdateProfileFailure extends Failure {
final dynamic exception;

const UploadProfileFailure(this.exception) : super();
const UpdateProfileFailure(this.exception) : super();

@override
List<Object?> get props => [exception];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:fluffychat/app_state/success.dart';

class UploadProfileLoading extends Success {
const UploadProfileLoading();
class UpdateProfileLoading extends Success {
const UpdateProfileLoading();

@override
List<Object?> get props => [];
Expand Down
21 changes: 21 additions & 0 deletions lib/domain/app_state/settings/update_profile_success.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:fluffychat/app_state/success.dart';

class UpdateProfileInitial extends Success {
@override
List<Object?> get props => [];
}

class UpdateProfileSuccess extends Success {
final Uri? avatar;
final String? displayName;
final bool isDeleteAvatar;

const UpdateProfileSuccess({
this.avatar,
this.displayName,
this.isDeleteAvatar = false,
});

@override
List<Object?> get props => [avatar, displayName, isDeleteAvatar];
}
19 changes: 0 additions & 19 deletions lib/domain/app_state/settings/upload_profile_success.dart

This file was deleted.

47 changes: 47 additions & 0 deletions lib/domain/usecase/settings/update_profile_interactor.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:dartz/dartz.dart';
import 'package:fluffychat/app_state/failure.dart';
import 'package:fluffychat/app_state/success.dart';
import 'package:fluffychat/domain/app_state/settings/update_profile_failure.dart';
import 'package:fluffychat/domain/app_state/settings/update_profile_loading.dart';
import 'package:fluffychat/domain/app_state/settings/update_profile_success.dart';
import 'package:matrix/matrix.dart';

class UpdateProfileInteractor {
Stream<Either<Failure, Success>> execute({
required Client client,
Uri? avatarUrl,
bool isDeleteAvatar = false,
String? displayName,
}) async* {
yield const Right(UpdateProfileLoading());
try {
Logs().d(
'UploadProfileInteractor::execute(): Uri - $avatarUrl - displayName - $displayName',
);
if (avatarUrl != null || isDeleteAvatar) {
await client.setAvatarUrl(
client.userID!,
avatarUrl ?? Uri.parse(''),
);
}
if (displayName != null) {
await client.setDisplayName(
client.userID!,
displayName,
);
}
yield Right(
UpdateProfileSuccess(
displayName: displayName,
avatar: avatarUrl,
isDeleteAvatar: isDeleteAvatar,
),
);
} catch (e) {
Logs().d(
'UploadAvatarInteractor::execute(): Exception - $e}',
);
yield Left(UpdateProfileFailure(e));
}
}
}
44 changes: 0 additions & 44 deletions lib/domain/usecase/settings/upload_profile_interactor.dart

This file was deleted.

27 changes: 16 additions & 11 deletions lib/pages/settings_dashboard/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ class Settings extends StatefulWidget {
}

class SettingsController extends State<Settings> with ConnectPageMixin {
final ValueNotifier<Profile> profileNotifier = ValueNotifier(
Profile(userId: ''),
);
final ValueNotifier<Uri?> avatarUriNotifier = ValueNotifier(Uri());
final ValueNotifier<String?> displayNameNotifier = ValueNotifier('');

StreamSubscription? onAccountDataSubscription;

Expand All @@ -53,7 +52,7 @@ class SettingsController extends State<Settings> with ConnectPageMixin {
final ValueNotifier<SettingEnum?> optionsSelectNotifier = ValueNotifier(null);

String get displayName =>
profileNotifier.value.displayName ??
displayNameNotifier.value ??
client.mxid(context).localpart ??
client.mxid(context);

Expand Down Expand Up @@ -94,7 +93,8 @@ class SettingsController extends State<Settings> with ConnectPageMixin {
Logs().d(
'Settings::_getCurrentProfile() - currentProfile: $profile',
);
profileNotifier.value = profile;
avatarUriNotifier.value = profile.avatarUrl;
displayNameNotifier.value = profile.displayName;
}

void checkBootstrap() async {
Expand Down Expand Up @@ -135,12 +135,9 @@ class SettingsController extends State<Settings> with ConnectPageMixin {
checkBootstrap();
}

void goToSettingsProfile(Profile? profile) async {
void goToSettingsProfile() async {
optionsSelectNotifier.value = SettingEnum.profile;
context.push(
'/rooms/profile',
extra: profile,
);
context.go('/rooms/profile');
}

void onClickToSettingsItem(SettingEnum settingEnum) {
Expand Down Expand Up @@ -179,7 +176,13 @@ class SettingsController extends State<Settings> with ConnectPageMixin {
void _handleOnAccountDataSubscription() {
onAccountDataSubscription = client.onAccountData.stream.listen((event) {
if (event.type == TwakeInappEventTypes.uploadAvatarEvent) {
profileNotifier.value = Profile.fromJson(event.content);
final newProfile = Profile.fromJson(event.content);
if (newProfile.avatarUrl != avatarUriNotifier.value) {
avatarUriNotifier.value = newProfile.avatarUrl;
}
if (newProfile.displayName != displayNameNotifier.value) {
displayNameNotifier.value = newProfile.displayName;
}
}
});
}
Expand All @@ -197,6 +200,8 @@ class SettingsController extends State<Settings> with ConnectPageMixin {
@override
void dispose() {
onAccountDataSubscription?.cancel();
avatarUriNotifier.dispose();
displayNameNotifier.dispose();
super.dispose();
}

Expand Down
Loading

0 comments on commit a8a9589

Please sign in to comment.