forked from eatvio/eatvio_app
Use chat_id from the consultations payload for direct navigation and keep the chat lookup as a fallback for legacy rows without chat_id. - validate chat id in ChatRepository and make it nullable - guard repeated taps while opening chat - handle nullable chat id in ProfileCubit and EmptyChatScreen related to #1106
36 lines
1.4 KiB
Dart
36 lines
1.4 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:eatvio_app/core/enums/base_state.dart';
|
|
import 'package:eatvio_app/features/chat/repositories/chat_repository.dart';
|
|
import 'package:eatvio_app/features/consultations/presentation/cubit/consultations_state.dart';
|
|
import 'package:eatvio_app/features/consultations/repositories/consultations_repository.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:eatvio_app/core/error_reporting/report_from.dart';
|
|
|
|
class ConsultationsCubit extends Cubit<ConsultationsState> {
|
|
final ConsultationsRepository consultationsRepository;
|
|
final ChatRepository chatRepository;
|
|
ConsultationsCubit({required this.consultationsRepository, required this.chatRepository}) : super(ConsultationsState());
|
|
|
|
Future<void> loadConsultations() async {
|
|
try {
|
|
final consultations = await consultationsRepository.getConsultations();
|
|
emit(state.copyWith(consultations: consultations, state: BaseState.success));
|
|
} catch (e, st) {
|
|
await reportFrom(e, st, this);
|
|
log(e.toString(), stackTrace: st);
|
|
emit(state.copyWith(state: BaseState.error));
|
|
}
|
|
}
|
|
|
|
Future<String?> getChatIdByUserSlug(String slug) async {
|
|
try {
|
|
return await chatRepository.getChatByUserSlug(slug);
|
|
} catch (e, st) {
|
|
await reportFrom(e, st, this);
|
|
log(e.toString(), stackTrace: st);
|
|
return null;
|
|
}
|
|
}
|
|
}
|