linagora / twake-on-matrix

A multi-platform (Flutter) application for connecting to Matrix - an open network for secure, decentralized communication, with your favorite devices.
GNU Affero General Public License v3.0
64 stars 18 forks source link

[BUG] Creating group chat with space only in name #2046

Open dab246 opened 2 months ago

dab246 commented 2 months ago

Env:

Steps to reproduce

  1. Click on the Pen icon at the bottom of the left sidebar
  2. Click “New group chat”
  3. Select one or multiple contact by checking the checkbox on the left
  4. Click ->
  5. Enter space in name input field
  6. Clicking Done icon to creates a group chat

Expectation

Evidence

https://github.com/user-attachments/assets/d613ae51-8941-4a51-946a-26049d053eed

hoangdat commented 3 weeks ago
hoangdat commented 3 weeks ago

Desc:

Validator:

abstract class Validator<T> {
  Either<Failure, Success> validate(T value);
}

EmptyNameValidator

class EmptyNameValidator extends Validator<NewNameRequest> {

  @override
  Either<Failure, Success> validate(NewNameRequest value) {
    if (value.value == null || value.value!.isEmpty) {
      return Left<Failure, Success>(VerifyNameFailure(const EmptyNameException()));
    } else {
      return Right<Failure, Success>(VerifyNameViewState());
    }
  }
}

CompositeNameValidator

class CompositeNameValidator extends Validator<NewNameRequest> {

  final List<Validator> _listValidator;

  CompositeNameValidator(this._listValidator);

  @override
  Either<Failure, Success> validate(NewNameRequest value) {
    return _listValidator.isNotEmpty
      ? _listValidator.getValidatorNameViewState(value)
      : Right<Failure, Success>(VerifyNameViewState());
  }
}

VerifyNameInteractor

class VerifyNameInteractor {
  Either<Failure, Success> execute(String? newName, List<Validator> listValidator) {
    try {
      return CompositeNameValidator(listValidator).validate(NewNameRequest(newName));
    } catch (exception) {
      return Left<Failure, Success>(VerifyNameFailure(exception));
    }
  }
}