From b6144c1bf4b7f363f26ba078237f2e79539b6139 Mon Sep 17 00:00:00 2001 From: Vishal <64505169+vishalxl@users.noreply.github.com> Date: Mon, 26 Dec 2022 13:57:44 +0530 Subject: [PATCH] made treeSelectorRepliesAndLikes more generic which can be invoked with set of pubkeys. to be used with follows too. --- README.md | 4 ++-- lib/console_ui.dart | 2 +- lib/tree_ds.dart | 28 +++++++++++++++------------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index d7daaad..baeefac 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,12 @@ This is an experimental or pre-alpha software made to show or know what a Nostr * [ ] fix --help that's dated * [x] show lightning invoice as qr code * [ ] in mention expansion, if p tag is not found in user store, then its left as #[n], whereas it should be replaced by the pubkey -* [ ] notifications should show mentions too ( it does not yet) +* [x] notifications should show mentions too ( it does not yet) * [x] notifications , option 3, is shown only for one entry in whole thread * [ ] hashtag regexp should have underscore * [x] add more default users. improve who is fetched. * [ ] after going to a dm room, screen doesn't clear -* [ ] when seeing a profile, if they have liked something, then likes after their name are shown white +* [x] when seeing a profile, if they have liked something, then likes after their name are shown white * [ ] kind 7 tags are messed up. for example for reaction: 066cdb716e250069c4078565c9d9046af483c43bbd8497aad9c60d41ec462034 and 137289198ff1c57a14711d87b059e5fc5f9b11b257672503595ac31bad450a22 * [ ] A F for friend or follow should be shown after each name that's a follow of the logged in user. F1 if the name is follow of a follow, and F2 if next level. * [ ] allow special character input, and 256 limit [info](https://www.reddit.com/r/dartlang/comments/xcdsyx/i_am_seeing_that_stdinreadlinesync_returns_only/) diff --git a/lib/console_ui.dart b/lib/console_ui.dart index 0d7edef..277e42e 100644 --- a/lib/console_ui.dart +++ b/lib/console_ui.dart @@ -1283,7 +1283,7 @@ Future socialMenuUi(Store node) async { case 3: clearScreen(); - bool selectorTrees_userNotifications (Tree t) => t.treeSelectorRepliesAndLikes(userPublicKey); + bool selectorTrees_userNotifications (Tree t) => t.treeSelectorRepliesAndLikes({userPublicKey}); int notificationHours = gHoursDefaultPrint>24? gHoursDefaultPrint: 24; // minimum 24 Point numPrinted = node.printTree(0, DateTime.now().subtract(Duration(hours:notificationHours)), selectorTrees_userNotifications); if( numPrinted.y > 0) { diff --git a/lib/tree_ds.dart b/lib/tree_ds.dart index 4f9a916..834e477 100644 --- a/lib/tree_ds.dart +++ b/lib/tree_ds.dart @@ -488,46 +488,48 @@ class Tree { } } - // returns true if the treee or its children has a reply or like for the user with public key pk; and notification flags are set for such events + // returns true if the tree or its children has a reply or like for the user with public key pk; and notification flags are set for such events // only new controls whether replies/likes recieved are ignored if the user has already - bool treeSelectorRepliesAndLikes(String pubkey, [bool onlyNew = false]) { + bool treeSelectorRepliesAndLikes(Set pubkeys, [bool onlyNew = false]) { bool hasReaction = false; bool childMatches = false; bool isMentioned = false; // check if there are any likes to this event if its user's event - if( event.eventData.pubkey == pubkey && gReactions.containsKey(event.eventData.id)) { + if( pubkeys.contains(event.eventData.pubkey) && gReactions.containsKey(event.eventData.id)) { List>? reactions = gReactions[event.eventData.id]; if( reactions != null) { if( reactions.length > 0) { // set every reaction as a new like so they all get highlighted; these are all later reset after first printing Set reactorPubkeys = getReactorPubkeys(event.eventData.id); event.eventData.newLikes = reactorPubkeys; + hasReaction = true; } } } + // check if any of the users has been tagged in this event + List pTags = event.eventData.pTags; + Set pplTagged = pTags.toSet().intersection(pubkeys); - // check if user has been tagged in this event - if( event.eventData.pubkey != pubkey) { - List pTags = event.eventData.pTags; - if( pTags.contains(pubkey)) { - isMentioned = true; - } + // 2nd condition: person making the event should not be on this list; they would already be considered in other test + if( pplTagged.length > 0 && !pubkeys.contains(event.eventData.pubkey)) { + event.eventData.isNotification = isMentioned = true; } - // check if there are any replies from other people to this event - if( event.eventData.pubkey == pubkey && children.length > 0) { + // check if there are any replies from other people to an event made by someone in list + if( pubkeys.contains(event.eventData.pubkey) && children.length > 0) { for( int i = 0; i < children.length; i++ ) { children.forEach((child) { // if child is someone else then set notifications and flag, means there are replies to this event - childMatches = child.event.eventData.isNotification = ((child.event.eventData.pubkey != pubkey)? true: false) ; + if(child.event.eventData.pubkey != event.eventData.pubkey ) // tests reply is not from same user + childMatches = child.event.eventData.isNotification = true; }); } } for( int i = 0; i < children.length; i++ ) { - if( children[i].treeSelectorRepliesAndLikes(pubkey)) { + if( children[i].treeSelectorRepliesAndLikes(pubkeys)) { childMatches = true; } }