chore: rename package
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
export './exceptions/notification_exeption.dart';
|
||||
export './extensions/build_context_extension.dart';
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:wyatt_architecture/wyatt_architecture.dart';
|
||||
|
||||
class NotificationException extends AppException {
|
||||
const NotificationException([super.message]);
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:wyatt_cloud_messaging_bloc_base/wyatt_cloud_messaging_bloc.dart';
|
||||
|
||||
extension BuildContextExtension on BuildContext {
|
||||
CloudmessagingCubit get cloudMessaging => read<CloudmessagingCubit>();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
export 'repositories/notification_repository_impl.dart';
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:wyatt_architecture/wyatt_architecture.dart';
|
||||
import 'package:wyatt_cloud_messaging_bloc_base/src/core/exceptions/notification_exeption.dart';
|
||||
import 'package:wyatt_cloud_messaging_bloc_base/src/domain/data_sources/remote/notification_remote_data_source.dart';
|
||||
import 'package:wyatt_cloud_messaging_bloc_base/src/domain/entities/remote_notifications.dart';
|
||||
import 'package:wyatt_cloud_messaging_bloc_base/src/domain/repositories/notification_repository.dart';
|
||||
import 'package:wyatt_type_utils/wyatt_type_utils.dart';
|
||||
|
||||
class NotificationRepositoryImpl extends NotificationRepository {
|
||||
final NotificationRemoteDataSource _notificationRemoteDataSource;
|
||||
|
||||
NotificationRepositoryImpl({
|
||||
required NotificationRemoteDataSource notificationRemoteDataSource,
|
||||
}) : _notificationRemoteDataSource = notificationRemoteDataSource;
|
||||
@override
|
||||
FutureOrResult<void> register() => Result.tryCatchAsync(
|
||||
_notificationRemoteDataSource.register,
|
||||
(error) => error is AppException
|
||||
? error
|
||||
: NotificationException(error.toString()),
|
||||
);
|
||||
|
||||
@override
|
||||
FutureOrResult<String> getToken() => Result.tryCatchAsync(
|
||||
_notificationRemoteDataSource.getToken,
|
||||
(error) => error is AppException
|
||||
? error
|
||||
: NotificationException(error.toString()),
|
||||
);
|
||||
|
||||
@override
|
||||
FutureOrResult<void> subscribeToTopic(String topic) => Result.tryCatchAsync(
|
||||
() => _notificationRemoteDataSource.subscribeToTopic(topic),
|
||||
(error) => error is AppException
|
||||
? error
|
||||
: NotificationException(error.toString()),
|
||||
);
|
||||
|
||||
@override
|
||||
FutureOrResult<void> unsubscribeFromTopic(String topic) =>
|
||||
Result.tryCatchAsync(
|
||||
() => _notificationRemoteDataSource.unsubscribeFromTopic(topic),
|
||||
(error) => error is AppException
|
||||
? error
|
||||
: NotificationException(error.toString()),
|
||||
);
|
||||
|
||||
@override
|
||||
FutureOrResult<void> requestPermissions() => Result.tryCatchAsync(
|
||||
_notificationRemoteDataSource.requestPermissions,
|
||||
(error) => error is AppException
|
||||
? error
|
||||
: NotificationException(error.toString()),
|
||||
);
|
||||
|
||||
@override
|
||||
FutureOrResult<Stream<RemoteNotification>> onNotificationAccepted() =>
|
||||
Result.tryCatchAsync(
|
||||
_notificationRemoteDataSource.onNotificationBackgroundAccepted,
|
||||
(error) => error is AppException
|
||||
? error
|
||||
: NotificationException(error.toString()),
|
||||
);
|
||||
|
||||
@override
|
||||
FutureOrResult<Stream<RemoteNotification>>
|
||||
onNotificationBackgroundAccepted() => Result.tryCatchAsync(
|
||||
_notificationRemoteDataSource.onNotificationBackgroundAccepted,
|
||||
(error) => error is AppException
|
||||
? error
|
||||
: NotificationException(error.toString()),
|
||||
);
|
||||
|
||||
@override
|
||||
FutureOrResult<Stream<RemoteNotification>>
|
||||
onNotificationForegroundAccepted() => Result.tryCatchAsync(
|
||||
_notificationRemoteDataSource.onNotificationForegroundAccepted,
|
||||
(error) => error is AppException
|
||||
? error
|
||||
: NotificationException(error.toString()),
|
||||
);
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:wyatt_architecture/wyatt_architecture.dart';
|
||||
import 'package:wyatt_cloud_messaging_bloc_base/src/domain/entities/remote_notifications.dart';
|
||||
|
||||
abstract class NotificationRemoteDataSource extends BaseRepository {
|
||||
Future<void> register();
|
||||
|
||||
Future<Stream<RemoteNotification>> onNotificationAccepted();
|
||||
|
||||
Future<Stream<RemoteNotification>> onNotificationBackgroundAccepted();
|
||||
|
||||
Future<Stream<RemoteNotification>> onNotificationForegroundAccepted();
|
||||
|
||||
Future<void> requestPermissions();
|
||||
|
||||
Future<String> getToken();
|
||||
|
||||
Future<void> subscribeToTopic(String topic);
|
||||
|
||||
Future<void> unsubscribeFromTopic(String topic);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
export 'entities/entities.dart';
|
||||
export 'repositories/repositories.dart';
|
||||
export 'usecases/usecases.dart';
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
export 'remote_notifications.dart';
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:wyatt_architecture/wyatt_architecture.dart';
|
||||
|
||||
class RemoteNotification extends Entity {
|
||||
const RemoteNotification({
|
||||
this.senderId,
|
||||
this.messageId,
|
||||
this.data,
|
||||
this.sentTime,
|
||||
});
|
||||
|
||||
final String? senderId;
|
||||
final String? messageId;
|
||||
final Map<String, dynamic>? data;
|
||||
final DateTime? sentTime;
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:wyatt_architecture/wyatt_architecture.dart';
|
||||
import 'package:wyatt_cloud_messaging_bloc_base/src/domain/entities/remote_notifications.dart';
|
||||
|
||||
abstract class NotificationRepository extends BaseRepository {
|
||||
FutureOrResult<void> register();
|
||||
|
||||
FutureOrResult<Stream<RemoteNotification>> onNotificationAccepted();
|
||||
|
||||
FutureOrResult<Stream<RemoteNotification>> onNotificationBackgroundAccepted();
|
||||
|
||||
FutureOrResult<Stream<RemoteNotification>> onNotificationForegroundAccepted();
|
||||
|
||||
FutureOrResult<void> requestPermissions();
|
||||
|
||||
FutureOrResult<String> getToken();
|
||||
|
||||
FutureOrResult<void> subscribeToTopic(String topic);
|
||||
|
||||
FutureOrResult<void> unsubscribeFromTopic(String topic);
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
export 'notification_repository.dart';
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:wyatt_architecture/wyatt_architecture.dart';
|
||||
import 'package:wyatt_cloud_messaging_bloc_base/src/domain/repositories/notification_repository.dart';
|
||||
|
||||
class GetCloudMessagingTokenUseCase extends AsyncUseCase<void, String> {
|
||||
final NotificationRepository _notificationRepository;
|
||||
|
||||
GetCloudMessagingTokenUseCase({
|
||||
required NotificationRepository notificationRepository,
|
||||
}) : _notificationRepository = notificationRepository;
|
||||
|
||||
@override
|
||||
FutureOrResult<String> execute(void params) =>
|
||||
_notificationRepository.getToken();
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:wyatt_architecture/wyatt_architecture.dart';
|
||||
import 'package:wyatt_cloud_messaging_bloc_base/src/domain/repositories/notification_repository.dart';
|
||||
|
||||
class InitCloudmessagingUseCase extends AsyncUseCase<NoParam, void> {
|
||||
final NotificationRepository _notificationRepository;
|
||||
|
||||
InitCloudmessagingUseCase({
|
||||
required NotificationRepository notificationRepository,
|
||||
}) : _notificationRepository = notificationRepository;
|
||||
@override
|
||||
FutureOrResult<void> execute(NoParam? params) =>
|
||||
_notificationRepository.register();
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
import 'package:wyatt_architecture/wyatt_architecture.dart';
|
||||
import 'package:wyatt_cloud_messaging_bloc_base/src/core/exceptions/notification_exeption.dart';
|
||||
import 'package:wyatt_cloud_messaging_bloc_base/src/domain/entities/remote_notifications.dart';
|
||||
import 'package:wyatt_cloud_messaging_bloc_base/src/domain/repositories/notification_repository.dart';
|
||||
import 'package:wyatt_type_utils/wyatt_type_utils.dart';
|
||||
|
||||
class ListenNotification extends StreamUseCase<NoParam, RemoteNotification> {
|
||||
final NotificationRepository _notificationRepository;
|
||||
|
||||
ListenNotification({required NotificationRepository notificationRepository})
|
||||
: _notificationRepository = notificationRepository;
|
||||
@override
|
||||
FutureOrResult<Stream<RemoteNotification>> execute(NoParam? params) async {
|
||||
Stream<RemoteNotification>? notificationStream;
|
||||
|
||||
final notificationStreamResponse =
|
||||
await _notificationRepository.onNotificationAccepted();
|
||||
|
||||
if (notificationStreamResponse.isOk) {
|
||||
notificationStream = notificationStreamResponse.ok;
|
||||
} else if (notificationStreamResponse.isErr) {
|
||||
final notificationBackgroundStreamResponse =
|
||||
await _notificationRepository.onNotificationBackgroundAccepted();
|
||||
|
||||
if (notificationBackgroundStreamResponse.isErr) {
|
||||
return Err(notificationBackgroundStreamResponse.err!);
|
||||
}
|
||||
|
||||
final notificationForegroundStreamResponse =
|
||||
await _notificationRepository.onNotificationForegroundAccepted();
|
||||
|
||||
if (notificationForegroundStreamResponse.isErr) {
|
||||
return Err(notificationBackgroundStreamResponse.err!);
|
||||
}
|
||||
|
||||
notificationStream = Rx.merge([
|
||||
notificationBackgroundStreamResponse.ok!,
|
||||
notificationBackgroundStreamResponse.ok!,
|
||||
]);
|
||||
}
|
||||
|
||||
if (notificationStream == null) {
|
||||
return const Err(NotificationException('Cannot listen notifications'));
|
||||
}
|
||||
|
||||
return Ok(notificationStream);
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:wyatt_architecture/wyatt_architecture.dart';
|
||||
import 'package:wyatt_cloud_messaging_bloc_base/src/domain/repositories/notification_repository.dart';
|
||||
|
||||
class RequestCloudMessagingPermissionUseCase extends AsyncUseCase<void, void> {
|
||||
final NotificationRepository _notificationRepository;
|
||||
|
||||
RequestCloudMessagingPermissionUseCase({
|
||||
required NotificationRepository notificationRepository,
|
||||
}) : _notificationRepository = notificationRepository;
|
||||
|
||||
@override
|
||||
FutureOrResult<void> execute(void params) =>
|
||||
_notificationRepository.register();
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:wyatt_architecture/wyatt_architecture.dart';
|
||||
import 'package:wyatt_cloud_messaging_bloc_base/src/domain/repositories/notification_repository.dart';
|
||||
|
||||
class Subscribe extends AsyncUseCase<String, void> {
|
||||
final NotificationRepository _notificationRepository;
|
||||
|
||||
Subscribe({required NotificationRepository notificationRepository})
|
||||
: _notificationRepository = notificationRepository;
|
||||
|
||||
@override
|
||||
FutureOr<void> onStart(String? params) {
|
||||
if (params == null) {
|
||||
throw const ClientException('Topic is not valid');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
FutureOrResult<void> execute(String? params) =>
|
||||
_notificationRepository.subscribeToTopic(params!);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:wyatt_architecture/wyatt_architecture.dart';
|
||||
import 'package:wyatt_cloud_messaging_bloc_base/src/domain/repositories/notification_repository.dart';
|
||||
|
||||
class Unsubscribe extends AsyncUseCase<String, void> {
|
||||
final NotificationRepository _notificationRepository;
|
||||
|
||||
Unsubscribe({required NotificationRepository notificationRepository})
|
||||
: _notificationRepository = notificationRepository;
|
||||
|
||||
@override
|
||||
FutureOr<void> onStart(String? params) {
|
||||
if (params == null) {
|
||||
throw const ClientException('Topic is not valid');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
FutureOrResult<void> execute(String? params) =>
|
||||
_notificationRepository.unsubscribeFromTopic(params!);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
export './get_cloud_messaging_token_use_case.dart';
|
||||
export './init_cloud_messaging_use_case.dart';
|
||||
export './listen_notification_use_case.dart';
|
||||
export './request_cloud_messaging_permission_use_case.dart';
|
||||
export './subscribe.dart';
|
||||
export './unsubscribe.dart';
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:wyatt_architecture/wyatt_architecture.dart';
|
||||
import 'package:wyatt_cloud_messaging_bloc_base/src/domain/entities/remote_notifications.dart';
|
||||
import 'package:wyatt_cloud_messaging_bloc_base/src/domain/usecases/listen_notification_use_case.dart';
|
||||
import 'package:wyatt_cloud_messaging_bloc_base/src/domain/usecases/subscribe.dart';
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'package:wyatt_cloud_messaging_bloc_base/src/domain/usecases/unsubscribe.dart';
|
||||
|
||||
part 'cloud_messaging_state.dart';
|
||||
|
||||
typedef OnNotification = void Function(RemoteNotification);
|
||||
|
||||
class CloudmessagingCubit extends Cubit<CloudmessagingState> {
|
||||
final ListenNotification _listenNotification;
|
||||
final Subscribe _subscribe;
|
||||
final Unsubscribe _unsubscribe;
|
||||
|
||||
final OnNotification? handleNotification;
|
||||
CloudmessagingCubit({
|
||||
required ListenNotification listenNotification,
|
||||
required Subscribe subscribe,
|
||||
required Unsubscribe unsubscribe,
|
||||
this.handleNotification,
|
||||
}) : _listenNotification = listenNotification,
|
||||
_subscribe = subscribe,
|
||||
_unsubscribe = unsubscribe,
|
||||
super(const CloudmessagingState());
|
||||
|
||||
Future<void> listenNotification() async {
|
||||
final notificaitons = await _listenNotification.execute(const NoParam());
|
||||
if (notificaitons.isOk) {
|
||||
notificaitons.ok?.listen((notification) {
|
||||
emit(CloudmessagingState(notification));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> subscribe(String topic) => _subscribe.execute(topic);
|
||||
|
||||
FutureOr<void> unsubscribe(String topic) => _unsubscribe.execute(topic);
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
part of 'cloud_messaging_cubit.dart';
|
||||
|
||||
class CloudmessagingState extends Equatable {
|
||||
final RemoteNotification? remoteNotification;
|
||||
|
||||
const CloudmessagingState([this.remoteNotification]);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [remoteNotification];
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
export 'data/data.dart';
|
||||
export 'domain/domain.dart';
|
||||
export 'features/notifications/bloc/cloud_messaging_cubit.dart';
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright (C) 2023 WYATT GROUP
|
||||
// Please see the AUTHORS file for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/// An notification library for BLoC.
|
||||
library wyatt_cloud_messaging_bloc_base;
|
||||
|
||||
export 'src/src.dart';
|
||||
Reference in New Issue
Block a user