Skip to content

Commit

Permalink
add notifications reactions/reposts/zaps settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Fmar committed Dec 4, 2023
1 parent fd3c5f4 commit 8d1c6fb
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 18 deletions.
6 changes: 3 additions & 3 deletions lib/i18n/i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1209,10 +1209,10 @@ class I18n {
}

/// `Boost`
String get Boost {
String get Repost {
return Intl.message(
'Boost',
name: 'Boost',
'Repost',
name: 'Repost',
desc: '',
args: [],
);
Expand Down
30 changes: 20 additions & 10 deletions lib/provider/notifications_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -61,26 +62,35 @@ class NotificationsProvider extends ChangeNotifier
}

List<int> queryEventKinds() {
return [
List<int> 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) {
Expand Down Expand Up @@ -144,7 +154,7 @@ class NotificationsProvider extends ChangeNotifier
eventBox.sort();

newNotificationsProvider.clear();
notificationsProvider.setTimestampToNewestAndSave();
setTimestampToNewestAndSave();
// update ui
notifyListeners();
}
Expand Down
33 changes: 33 additions & 0 deletions lib/provider/setting_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -479,6 +500,10 @@ class SettingData {

bool? backgroundService;

bool? notificationsReactions;
bool? notificationsReposts;
bool? notificationsZaps;

String? imageService;

int? imagePreview;
Expand Down Expand Up @@ -529,6 +554,9 @@ class SettingData {
this.videoPreview,
this.network,
this.backgroundService,
this.notificationsReactions,
this.notificationsReposts,
this.notificationsZaps,
this.imageService,
this.imagePreview,
this.gossip,
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -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;
Expand Down
30 changes: 30 additions & 0 deletions lib/router/setting/setting_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,36 @@ class _SettingRouter extends State<SettingRouter> 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<AbstractSettingsTile> accountTiles = [];

Expand Down
2 changes: 1 addition & 1 deletion lib/ui/event/event_main_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class _EventMainComponent extends State<EventMainComponent> {
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(
Expand Down
8 changes: 4 additions & 4 deletions lib/ui/event/event_reactions_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ class _EventReactionsComponent extends State<EventReactionsComponent> {
// )),
Expanded(
child: PopupMenuButton<String>(
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",
Expand Down Expand Up @@ -486,7 +486,7 @@ class _EventReactionsComponent extends State<EventReactionsComponent> {

Future<void> 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];
Expand Down

0 comments on commit 8d1c6fb

Please sign in to comment.