TF-1600 Implement GetMailboxesNotPutNotificationsInteractor
(cherry picked from commit ba849b288e4e943648c35bf6a494eaa804b049b6)
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
import 'package:core/data/model/source_type/data_source_type.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:fcm/model/firebase_subscription.dart';
|
||||
import 'package:fcm/model/type_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/datasource/mailbox_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/datasource/fcm_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/extensions/fcm_subscription_extensions.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/model/fcm_subscription.dart';
|
||||
@@ -18,10 +22,12 @@ class FCMRepositoryImpl extends FCMRepository {
|
||||
|
||||
final Map<DataSourceType, FCMDatasource> _fcmDatasource;
|
||||
final ThreadDataSource _threadDataSource;
|
||||
final Map<DataSourceType, MailboxDataSource> _mapMailboxDataSource;
|
||||
|
||||
FCMRepositoryImpl(
|
||||
this._fcmDatasource,
|
||||
this._threadDataSource
|
||||
this._threadDataSource,
|
||||
this._mapMailboxDataSource
|
||||
);
|
||||
|
||||
@override
|
||||
@@ -104,4 +110,26 @@ class FCMRepositoryImpl extends FCMRepository {
|
||||
Future<bool> destroySubscription(String subscriptionId) {
|
||||
return _fcmDatasource[DataSourceType.network]!.destroySubscription(subscriptionId);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<PresentationMailbox>> getMailboxesNotPutNotifications(Session session, AccountId accountId) async {
|
||||
final mailboxesCache = await _mapMailboxDataSource[DataSourceType.local]!.getAllMailboxCache();
|
||||
final mailboxesCacheNotPutNotifications = mailboxesCache
|
||||
.map((mailbox) => mailbox.toPresentationMailbox())
|
||||
.where((presentationMailbox) => presentationMailbox.pushNotificationDeactivated)
|
||||
.toList();
|
||||
log('FCMRepositoryImpl::getMailboxesNotPutNotifications():mailboxesCacheNotPutNotifications: $mailboxesCacheNotPutNotifications');
|
||||
if (mailboxesCacheNotPutNotifications.isNotEmpty && mailboxesCacheNotPutNotifications.length == 5) {
|
||||
return mailboxesCacheNotPutNotifications;
|
||||
} else {
|
||||
final mailboxResponse = await _mapMailboxDataSource[DataSourceType.network]!.getAllMailbox(session, accountId);
|
||||
final mailboxes = mailboxResponse.mailboxes ?? [];
|
||||
final mailboxesNotPutNotifications = mailboxes
|
||||
.map((mailbox) => mailbox.toPresentationMailbox())
|
||||
.where((presentationMailbox) => presentationMailbox.pushNotificationDeactivated)
|
||||
.toList();
|
||||
log('FCMRepositoryImpl::getMailboxesNotPutNotifications():mailboxesNotPutNotifications: $mailboxesNotPutNotifications');
|
||||
return mailboxesNotPutNotifications;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import 'package:fcm/model/type_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/model/fcm_subscription.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/model/register_new_token_request.dart';
|
||||
import 'package:tmail_ui_user/features/thread/domain/model/email_response.dart';
|
||||
@@ -34,4 +35,6 @@ abstract class FCMRepository {
|
||||
Future<FCMSubscription> getSubscription();
|
||||
|
||||
Future<bool> destroySubscription(String subscriptionId);
|
||||
|
||||
Future<List<PresentationMailbox>> getMailboxesNotPutNotifications(Session session, AccountId accountId);
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||
|
||||
class GetMailboxesNotPutNotificationsLoading extends UIState {}
|
||||
|
||||
class GetMailboxesNotPutNotificationsSuccess extends UIState {
|
||||
|
||||
final List<PresentationMailbox> mailboxes;
|
||||
|
||||
GetMailboxesNotPutNotificationsSuccess(this.mailboxes);
|
||||
|
||||
@override
|
||||
List<Object> get props => [mailboxes];
|
||||
}
|
||||
|
||||
class GetMailboxesNotPutNotificationsFailure extends FeatureFailure {
|
||||
|
||||
GetMailboxesNotPutNotificationsFailure(exception) : super(exception: exception);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [exception];
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/state/get_mailboxes_not_put_notifications_state.dart';
|
||||
|
||||
class GetMailboxesNotPutNotificationsInteractor {
|
||||
final FCMRepository _fcmRepository;
|
||||
|
||||
GetMailboxesNotPutNotificationsInteractor(this._fcmRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(Session session, AccountId accountId) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(GetMailboxesNotPutNotificationsLoading());
|
||||
final mailboxes = await _fcmRepository.getMailboxesNotPutNotifications(session, accountId);
|
||||
yield Right<Failure, Success>(GetMailboxesNotPutNotificationsSuccess(mailboxes));
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(GetMailboxesNotPutNotificationsFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user