2024-06-17 23:23:35 +02:00
|
|
|
import 'package:simplecloudnotifier/models/scn_message.dart';
|
2024-09-19 19:46:46 +02:00
|
|
|
import 'package:simplecloudnotifier/pages/message_list/message_filter_chiplet.dart';
|
2024-06-17 23:23:35 +02:00
|
|
|
import 'package:simplecloudnotifier/state/application_log.dart';
|
|
|
|
|
|
|
|
class AppEvents {
|
|
|
|
static AppEvents? _singleton = AppEvents._internal();
|
|
|
|
|
|
|
|
factory AppEvents() {
|
|
|
|
return _singleton ?? (_singleton = AppEvents._internal());
|
|
|
|
}
|
|
|
|
|
|
|
|
AppEvents._internal() {}
|
|
|
|
|
2024-09-19 19:46:46 +02:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
List<void Function(List<MessageFilterChipletType> types, List<MessageFilterChiplet>)> _filterListeners = [];
|
2024-06-17 23:23:35 +02:00
|
|
|
|
2024-09-19 19:46:46 +02:00
|
|
|
void subscribeFilterListener(void Function(List<MessageFilterChipletType> types, List<MessageFilterChiplet>) listener) {
|
|
|
|
_filterListeners.add(listener);
|
2024-06-17 23:23:35 +02:00
|
|
|
}
|
|
|
|
|
2024-09-19 19:46:46 +02:00
|
|
|
void unsubscribeFilterListener(void Function(List<MessageFilterChipletType> types, List<MessageFilterChiplet>) listener) {
|
|
|
|
_filterListeners.remove(listener);
|
2024-06-17 23:23:35 +02:00
|
|
|
}
|
|
|
|
|
2024-09-19 19:46:46 +02:00
|
|
|
void notifyFilterListeners(List<MessageFilterChipletType> types, List<MessageFilterChiplet> query) {
|
|
|
|
ApplicationLog.debug('[AppEvents] onFilter: [${types.join(" ; ")}], [${query.map((e) => e.label).join('|')}]');
|
2024-06-17 23:23:35 +02:00
|
|
|
|
2024-09-19 19:46:46 +02:00
|
|
|
for (var listener in _filterListeners) {
|
|
|
|
listener(types, query);
|
2024-06-17 23:23:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-19 19:46:46 +02:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
List<void Function(SCNMessage)> _messageReceivedListeners = [];
|
|
|
|
|
2024-06-17 23:23:35 +02:00
|
|
|
void subscribeMessageReceivedListener(void Function(SCNMessage) listener) {
|
|
|
|
_messageReceivedListeners.add(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
void unsubscribeMessageReceivedListener(void Function(SCNMessage) listener) {
|
|
|
|
_messageReceivedListeners.remove(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
void notifyMessageReceivedListeners(SCNMessage msg) {
|
|
|
|
ApplicationLog.debug('[AppEvents] onMessageReceived: ${msg.messageID}');
|
|
|
|
|
|
|
|
for (var listener in _messageReceivedListeners) {
|
|
|
|
listener(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|