migrate chatty

This commit is contained in:
Salvatore Giordano
2021-05-18 17:15:37 +02:00
parent 33622093e0
commit bc655e0dc4
27 changed files with 181 additions and 159 deletions
@@ -1,6 +1,6 @@
class ChatUser {
const ChatUser({this.name, this.image, this.id});
final String name;
final String image;
final String id;
final String? name;
final String? image;
final String? id;
}
@@ -7,9 +7,9 @@ import 'package:uuid/uuid.dart';
class CreateGroupInput {
CreateGroupInput({this.imageFile, this.name, this.members});
final File imageFile;
final String name;
final List<String> members;
final File? imageFile;
final String? name;
final List<String?>? members;
}
class CreateGroupUseCase {
@@ -23,7 +23,7 @@ class CreateGroupUseCase {
Future<Channel> createGroup(CreateGroupInput input) async {
final channelId = Uuid().v4();
String image;
String? image;
if (input.imageFile != null) {
image = await _uploadStorageRepository.uploadPhoto(
input.imageFile, 'channels/$channelId');
@@ -5,10 +5,12 @@ import 'package:stream_chatter/data/stream_api_repository.dart';
import 'package:stream_chatter/data/upload_storage_repository.dart';
import 'package:stream_chatter/domain/models/chat_user.dart';
import '../exceptions/auth_exception.dart';
class ProfileInput {
ProfileInput({this.imageFile, this.name});
final File imageFile;
final String name;
final File? imageFile;
final String? name;
}
class ProfileSignInUseCase {
@@ -24,13 +26,21 @@ class ProfileSignInUseCase {
Future<void> verify(ProfileInput input) async {
final auth = await _authRepository.getAuthUser();
if (auth == null) {
throw AuthException(AuthErrorCode.not_auth);
}
final token = await _streamApiRepository.getToken(auth.id);
String image;
String? image;
if (input.imageFile != null) {
image = await _uploadStorageRepository.uploadPhoto(
input.imageFile, 'users/${auth.id}');
}
await _streamApiRepository.connectUser(
ChatUser(name: input.name, id: auth.id, image: image), token);
ChatUser(
name: input.name,
id: auth.id,
image: image,
),
token);
}
}