fixed code so that wrong notifications don't get printed

it was printing every thread where any follow was involved; and was highlighting them too.

now only follows posts/likes are highlighted and shown as notifications. reduces the flood of notifications.
This commit is contained in:
Vishal 2022-12-31 03:00:39 +05:30
parent 2d603c2aec
commit 9a5b0b48ba
2 changed files with 60 additions and 43 deletions

View File

@ -1,6 +1,5 @@
import 'dart:io'; import 'dart:io';
import 'dart:convert'; import 'dart:convert';
import 'dart:math';
import 'package:nostr_console/event_ds.dart'; import 'package:nostr_console/event_ds.dart';
import 'package:nostr_console/tree_ds.dart'; import 'package:nostr_console/tree_ds.dart';
import 'package:nostr_console/relays.dart'; import 'package:nostr_console/relays.dart';
@ -1623,7 +1622,6 @@ Future<void> mainMenuUi(Store node) async {
switch(option) { switch(option) {
case 1: case 1:
node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_all); node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_all);
break; break;

View File

@ -595,7 +595,7 @@ class Tree {
} // end treeSelectorUserPostAndLike() } // end treeSelectorUserPostAndLike()
// returns true if the tree (or its children, depending on flag) has a post or like by user; and notification flags are set for such events // returns true if the tree (or its children, depending on flag) has a post or like by user; and notification flags are set for such events
bool treeSelectorDMtoFromUser(Set<String> pubkeys, { bool enableNotifications = true, bool checkChildrenToo = true}) { bool treeSelectorDMtoFromUser(Set<String> pubkeys, { bool enableNotifications = true}) {
if( event.eventData.kind != 4) { if( event.eventData.kind != 4) {
return false; return false;
@ -1576,6 +1576,7 @@ class Store {
if( gDebug > 0) print("In printNotifications: Could not find event $eventID in tree"); if( gDebug > 0) print("In printNotifications: Could not find event $eventID in tree");
return; return;
} else { } else {
if( isRelevantForNotification(t)) {
switch(t.event.eventData.kind) { switch(t.event.eventData.kind) {
case 1: case 1:
t.event.eventData.isNotification = true; t.event.eventData.isNotification = true;
@ -1596,8 +1597,6 @@ class Store {
reactedToTree.event.eventData.newLikes.add( reactorId); reactedToTree.event.eventData.newLikes.add( reactorId);
Tree topTree = getTopTree(reactedToTree); Tree topTree = getTopTree(reactedToTree);
topNotificationTree.add(topTree); topNotificationTree.add(topTree);
} else if(event.eventData.content == "!" ) {
reactedToTree.event.eventData.isHidden = true;
} }
} else { } else {
if(gDebug > 0) print("Could not find reactedTo tree"); if(gDebug > 0) print("Could not find reactedTo tree");
@ -1611,6 +1610,7 @@ class Store {
break; break;
} }
} }
}
}); });
// remove duplicate top trees // remove duplicate top trees
@ -2070,11 +2070,23 @@ class Store {
} }
// threads where the user and follows have involved themselves are returnes as true ( relevant) // threads where the user and follows have involved themselves are returnes as true ( relevant)
bool isRelevant(Tree tree) { bool isRelevantForNotification(Tree tree) {
if( tree.treeSelectorUserPostAndLike(gFollowList.union(gDefaultFollows).union({userPublicKey}),
enableNotifications: false,
checkChildrenToo: false)
|| tree.treeSelectorDMtoFromUser({userPublicKey},
enableNotifications: false)) {
return true;
}
if( tree.treeSelectorUserPostAndLike(gFollowList) return false;
|| tree.treeSelectorUserPostAndLike({userPublicKey}) }
|| tree.treeSelectorDMtoFromUser({userPublicKey})
// threads where the user and follows have involved themselves are returnes as true ( relevant)
bool isRelevantForFileSave(Tree tree) {
if( tree.treeSelectorUserPostAndLike(gFollowList.union(gDefaultFollows).union({userPublicKey}), enableNotifications: false)
|| tree.treeSelectorDMtoFromUser({userPublicKey}, enableNotifications: false)
|| tree.treeSelectorUserReplies(gFollowList)) { || tree.treeSelectorUserReplies(gFollowList)) {
return true; return true;
} }
@ -2119,7 +2131,7 @@ class Store {
} }
} }
if( !isRelevant(tree)) { if( !isRelevantForFileSave(tree)) {
continue; continue;
} }
@ -2539,6 +2551,18 @@ class Store {
return ""; return "";
} }
// set isHidden for reactedTo if it exists in map
if( comment == "!" ) {
if( event.eventData.pubkey == userPublicKey) {
// is a hide reaction by the user; set reactedToid as hidden
tempChildEventsMap[reactedToId]?.event.eventData.isHidden = true;
return reactedToId;
} else {
// is hidden reaction by someone else; do nothing then
return "";
}
}
// check if the reaction already exists by this user // check if the reaction already exists by this user
if( gReactions.containsKey(reactedToId)) { if( gReactions.containsKey(reactedToId)) {
for( int i = 0; i < ((gReactions[reactedToId]?.length)??0); i++) { for( int i = 0; i < ((gReactions[reactedToId]?.length)??0); i++) {
@ -2575,12 +2599,7 @@ class Store {
newReactorList.add(temp); newReactorList.add(temp);
gReactions[reactedToId] = newReactorList; gReactions[reactedToId] = newReactorList;
} }
// set isHidden for reactedTo if it exists in map
if( comment == "!" && event.eventData.pubkey == userPublicKey) {
tempChildEventsMap[reactedToId]?.event.eventData.isHidden = true;
}
return reactedToId; return reactedToId;
} else { } else {
// case where its not a kind 7 event, or we can't find the reactedTo event due to absense of e tag. // case where its not a kind 7 event, or we can't find the reactedTo event due to absense of e tag.