Skip to content

Commit

Permalink
TW-2046 Added name validation in group creation
Browse files Browse the repository at this point in the history
  • Loading branch information
KhaledNjim committed Nov 3, 2024
1 parent 3262301 commit 5153df0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/pages/new_group/new_group_chat_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import 'package:fluffychat/app_state/failure.dart';
import 'package:fluffychat/app_state/success.dart';
import 'package:fluffychat/domain/app_state/room/create_new_group_chat_state.dart';
import 'package:fluffychat/domain/app_state/room/upload_content_state.dart';
import 'package:fluffychat/domain/app_state/validator/verify_name_view_state.dart';
import 'package:fluffychat/domain/model/verification/name_with_space_only_validator.dart';
import 'package:fluffychat/domain/usecase/verify_name_interactor.dart';
import 'package:fluffychat/pages/new_group/new_group_chat_info_view.dart';
import 'package:fluffychat/pages/new_group/new_group_info_controller.dart';
import 'package:fluffychat/presentation/mixins/common_media_picker_mixin.dart';
Expand Down Expand Up @@ -55,6 +58,7 @@ class NewGroupChatInfoController extends State<NewGroupChatInfo>
final groupNameTextEditingController = TextEditingController();
final avatarAssetEntityNotifier = ValueNotifier<AssetEntity?>(null);
final avatarFilePickerNotifier = ValueNotifier<MatrixFile?>(null);
VerifyNameInteractor verifyNameInteractor = VerifyNameInteractor();

final groupNameFocusNode = FocusNode();
StreamSubscription? createNewGroupChatInteractorStreamSubscription;
Expand Down Expand Up @@ -309,6 +313,20 @@ class NewGroupChatInfoController extends State<NewGroupChatInfo>
);
}

String? getErrorMessage(String content) {
verifyNameInteractor.execute(content, [NameWithSpaceOnlyValidator()]).fold(
(failure) {
if (failure is VerifyNameFailure) {
return failure.exception.getMessage(context);
} else {
return null;
}
},
(success) => null,
);
return null;
}

@override
void initState() {
listenGroupNameChanged();
Expand Down
3 changes: 3 additions & 0 deletions lib/pages/new_group/new_group_chat_info_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ class NewGroupChatInfoView extends StatelessWidget {
borderSide:
BorderSide(color: Theme.of(context).colorScheme.shadow),
),
errorText: newGroupInfoController.getErrorMessage(
newGroupInfoController.groupNameTextEditingController.text,
),
labelText: L10n.of(context)!.widgetName,
labelStyle: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface,
Expand Down

0 comments on commit 5153df0

Please sign in to comment.