diff --git a/lib/i18n/i18n.dart b/lib/i18n/i18n.dart index 8231da88..30fc0e98 100644 --- a/lib/i18n/i18n.dart +++ b/lib/i18n/i18n.dart @@ -1209,10 +1209,10 @@ class I18n { } /// `Boost` - String get Boost { + String get Repost { return Intl.message( - 'Boost', - name: 'Boost', + 'Repost', + name: 'Repost', desc: '', args: [], ); diff --git a/lib/provider/notifications_provider.dart b/lib/provider/notifications_provider.dart index 7b3b359b..f481b24e 100644 --- a/lib/provider/notifications_provider.dart +++ b/lib/provider/notifications_provider.dart @@ -44,6 +44,7 @@ class NotificationsProvider extends ChangeNotifier void refresh() { _initTime = DateTime.now().millisecondsSinceEpoch ~/ 1000; eventBox.clear(); + timestamp = null; startSubscription(); sharedPreferences.remove(DataKey.NOTIFICATIONS_TIMESTAMP); newNotificationsProvider.clear(); @@ -61,26 +62,35 @@ class NotificationsProvider extends ChangeNotifier } List queryEventKinds() { - return [ + List kinds = [ Nip01Event.TEXT_NODE_KIND, - Reaction.KIND, - kind.EventKind.REPOST, - kind.EventKind.GENERIC_REPOST, - kind.EventKind.ZAP_RECEIPT, kind.EventKind.LONG_FORM, ]; + if (settingProvider.notificationsReactions) { + kinds.add(Reaction.KIND); + } + if (settingProvider.notificationsReposts) { + kinds.add(kind.EventKind.REPOST); + kinds.add(kind.EventKind.GENERIC_REPOST); + } + if (settingProvider.notificationsZaps) { + kinds.add(kind.EventKind.ZAP_RECEIPT); + } + return kinds; } NostrRequest? subscription; - void startSubscription() async { + void startSubscription({bool refreshed=false}) async { if (subscription != null) { await relayManager.closeNostrRequest(subscription!); } int? since; - var newestPost = eventBox.newestEvent; - if (newestPost != null) { - since = newestPost!.createdAt; + if (!refreshed) { + var newestPost = eventBox.newestEvent; + if (newestPost != null) { + since = newestPost!.createdAt; + } } if (myInboxRelaySet!=null) { @@ -144,7 +154,7 @@ class NotificationsProvider extends ChangeNotifier eventBox.sort(); newNotificationsProvider.clear(); - notificationsProvider.setTimestampToNewestAndSave(); + setTimestampToNewestAndSave(); // update ui notifyListeners(); } diff --git a/lib/provider/setting_provider.dart b/lib/provider/setting_provider.dart index ab504318..ab8ba4d1 100644 --- a/lib/provider/setting_provider.dart +++ b/lib/provider/setting_provider.dart @@ -193,6 +193,12 @@ class SettingProvider extends ChangeNotifier { bool get backgroundService => _settingData!.backgroundService ?? true; + bool get notificationsReactions => _settingData!.notificationsReactions ?? true; + + bool get notificationsReposts => _settingData!.notificationsReposts ?? true; + + bool get notificationsZaps => _settingData!.notificationsZaps ?? true; + int get linkPreview => _settingData!.linkPreview != null ? _settingData!.linkPreview! : OpenStatus.OPEN; @@ -340,6 +346,21 @@ class SettingProvider extends ChangeNotifier { initBackgroundService(backgroundService); } + set notificationsReactions(bool? o) { + _settingData!.notificationsReactions = o; + saveAndNotifyListeners(); + } + + set notificationsReposts(bool? o) { + _settingData!.notificationsReposts = o; + saveAndNotifyListeners(); + } + + set notificationsZaps(bool? o) { + _settingData!.notificationsZaps = o; + saveAndNotifyListeners(); + } + /// i18n set i18n(String? o) { _settingData!.i18n = o; @@ -479,6 +500,10 @@ class SettingData { bool? backgroundService; + bool? notificationsReactions; + bool? notificationsReposts; + bool? notificationsZaps; + String? imageService; int? imagePreview; @@ -529,6 +554,9 @@ class SettingData { this.videoPreview, this.network, this.backgroundService, + this.notificationsReactions, + this.notificationsReposts, + this.notificationsZaps, this.imageService, this.imagePreview, this.gossip, @@ -561,6 +589,9 @@ class SettingData { lockOpen = OpenStatus.CLOSE; } backgroundService = json['backgroundService']; + notificationsReactions = json['notificationsReactions']; + notificationsReposts = json['notificationsReposts']; + notificationsZaps = json['notificationsZaps']; defaultIndex = json['defaultIndex']; defaultTab = json['defaultTab']; linkPreview = json['linkPreview']; @@ -631,6 +662,8 @@ class SettingData { data['videoPreview'] = this.videoPreview; data['network'] = this.network; data['backgroundService'] = this.backgroundService; + data['notificationsReactions'] = this.notificationsReactions; + data['notificationsReposts'] = this.notificationsReactions; data['imageService'] = this.imageService; data['videoPreview'] = this.videoPreview; data['imagePreview'] = this.imagePreview; diff --git a/lib/router/setting/setting_router.dart b/lib/router/setting/setting_router.dart index a7d7b6a7..c5d575e0 100644 --- a/lib/router/setting/setting_router.dart +++ b/lib/router/setting/setting_router.dart @@ -518,6 +518,36 @@ class _SettingRouter extends State with WhenStopFunction { title: const Text("Use background service"), )); } + notificationTiles.add(SettingsTile.switchTile( + activeSwitchColor: themeData.primaryColor, + onToggle: (value) { + settingProvider.notificationsReactions = value; + notificationsProvider.refresh(); + }, + initialValue: settingProvider.notificationsReactions, + leading: const Icon(Icons.favorite_border), + title: const Text("Include reactions"), + )); + notificationTiles.add(SettingsTile.switchTile( + activeSwitchColor: themeData.primaryColor, + onToggle: (value) { + settingProvider.notificationsReposts = value; + notificationsProvider.refresh(); + }, + initialValue: settingProvider.notificationsReposts, + leading: const Icon(Icons.repeat), + title: const Text("Include reposts"), + )); + notificationTiles.add(SettingsTile.switchTile( + activeSwitchColor: themeData.primaryColor, + onToggle: (value) { + settingProvider.notificationsZaps = value; + notificationsProvider.refresh(); + }, + initialValue: settingProvider.notificationsZaps, + leading: const Icon(Icons.bolt), + title: const Text("Include zaps"), + )); List accountTiles = []; diff --git a/lib/ui/event/event_main_component.dart b/lib/ui/event/event_main_component.dart index 6b083f18..f995040a 100644 --- a/lib/ui/event/event_main_component.dart +++ b/lib/ui/event/event_main_component.dart @@ -264,7 +264,7 @@ class _EventMainComponent extends State { widget.event.kind == kind.EventKind.GENERIC_REPOST) { list.add(Container( alignment: Alignment.centerLeft, - child: Text("${s.Boost}:"), + child: Text("${s.Repost}:"), )); if (repostEvent != null) { list.add(EventQuoteComponent( diff --git a/lib/ui/event/event_reactions_component.dart b/lib/ui/event/event_reactions_component.dart index 1d68ae62..e3e17049 100644 --- a/lib/ui/event/event_reactions_component.dart +++ b/lib/ui/event/event_reactions_component.dart @@ -129,12 +129,12 @@ class _EventReactionsComponent extends State { // )), Expanded( child: PopupMenuButton( - tooltip: s.Boost, + tooltip: s.Repost, itemBuilder: (context) { return [ PopupMenuItem( - value: "boost", - child: Text(s.Boost), + value: "repost", + child: Text(s.Repost), ), PopupMenuItem( value: "quote", @@ -486,7 +486,7 @@ class _EventReactionsComponent extends State { Future onRepostTap(String value) async { if (loggedUserSigner!.canSign()) { - if (value == "boost") { + if (value == "repost") { String? relayAddr; if (widget.event.sources.isNotEmpty) { relayAddr = widget.event.sources[0];