Improved menu options 2-5 and 2-6

and used the same functions ( which now accept array of pubkeys)
This commit is contained in:
Vishal 2022-12-26 15:28:24 +05:30
parent b6144c1bf4
commit 9abe554bd5
7 changed files with 49 additions and 30 deletions

View File

@ -18,7 +18,7 @@ This is an experimental or pre-alpha software made to show or know what a Nostr
* [ ] 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
* [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] hashtag regexp should have underscore (seems to be working fine)
* [x] add more default users. improve who is fetched.
* [ ] after going to a dm room, screen doesn't clear
* [x] when seeing a profile, if they have liked something, then likes after their name are shown white

View File

@ -364,7 +364,7 @@ Future<void> main(List<String> arguments) async {
if (contactEvent != null ) {
if(gDebug > 0) print("In main: found contact list: \n ${contactEvent.originalJson}");
contactEvent.eventData.contactList.forEach((contact) {
contacts.add(contact.id);
contacts.add(contact.contactPubkey);
});
} else {
print("Could not find your contact list.");

View File

@ -196,7 +196,7 @@ Future<String> sendEvent(Store node, Event e, [int delayAfterSend = 500]) async
if( i == e.eventData.contactList.length - 1) {
comma = "";
}
String strContact = '["p","${e.eventData.contactList[i].id}","$relay"]$comma';
String strContact = '["p","${e.eventData.contactList[i].contactPubkey}","$relay"]$comma';
strTags += strContact;
}
@ -293,7 +293,7 @@ void reAdjustAlignment() {
}
void printProfile(Store node, String profilePubkey) {
bool onlyUserPostAndLike (Tree t) => t.treeSelectorUserPostAndLike(profilePubkey);
bool onlyUserPostAndLike (Tree t) => t.treeSelectorUserPostAndLike({profilePubkey});
node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), onlyUserPostAndLike);
// if contact list was found, get user's feed, and keep the contact list for later use
@ -332,7 +332,7 @@ void printProfile(Store node, String profilePubkey) {
if (profileContactEvent != null ) {
if( profilePubkey != userPublicKey) {
if( profileContactEvent.eventData.contactList.any((x) => (x.id == userPublicKey))) {
if( profileContactEvent.eventData.contactList.any((x) => (x.contactPubkey == userPublicKey))) {
print("* They follow you");
} else {
print("* They don't follow you");
@ -346,7 +346,7 @@ void printProfile(Store node, String profilePubkey) {
// print follow list
stdout.write("$pronoun follow ${profileContactEvent.eventData.contactList.length} accounts: ");
profileContactEvent.eventData.contactList.sort();
profileContactEvent.eventData.contactList.forEach((x) => stdout.write("${getAuthorName(x.id, 0)}, "));
profileContactEvent.eventData.contactList.forEach((x) => stdout.write("${getAuthorName(x.contactPubkey, 0)}, "));
print("\n");
}
@ -1283,7 +1283,7 @@ Future<void> socialMenuUi(Store node) async {
case 3:
clearScreen();
bool selectorTrees_userNotifications (Tree t) => t.treeSelectorRepliesAndLikes({userPublicKey});
bool selectorTrees_userNotifications (Tree t) => t.treeSelectorotificationsFor({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) {
@ -1303,7 +1303,8 @@ Future<void> socialMenuUi(Store node) async {
break;
case 5:
clearScreen();
Point numPrinted = node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_userRepliesLikes);
bool selectorTrees_userActions (Tree t) => t.treeSelectorUserPostAndLike({userPublicKey});
Point numPrinted = node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_userActions);
if( numPrinted.x > 0) {
print("Showed ${numPrinted.x.toInt()} thread where you replied or liked in in last $gHoursDefaultPrint hours.\n");
} else {
@ -1312,7 +1313,8 @@ Future<void> socialMenuUi(Store node) async {
break;
case 6:
clearScreen();
Point numPrinted = node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_followsPosts);
bool selectorTrees_followActions (Tree t) => t.treeSelectorUserPostAndLike(getFollows( userPublicKey));
Point numPrinted = node.printTree(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_followActions);
if( numPrinted.x > 0) {
print("Showed ${numPrinted.x.toInt()} threads where your follows participated.\n");
} else {
@ -1384,7 +1386,7 @@ Future<void> socialMenuUi(Store node) async {
bool alreadyContact = false;
for(int i = 0; i < newContactEvent.eventData.contactList.length; i++) {
if( newContactEvent.eventData.contactList[i].id == pubkey.first) {
if( newContactEvent.eventData.contactList[i].contactPubkey == pubkey.first) {
alreadyContact = true;
break;
}

View File

@ -1027,7 +1027,7 @@ String getRelayOfUser(String userPubkey, String contactPubkey) {
List<Contact>? contacts = gContactLists[userPubkey];
if( contacts != null) {
for( int i = 0; i < contacts.length; i++) {
if( contacts[i].id == contactPubkey) {
if( contacts[i].contactPubkey == contactPubkey) {
relay = contacts[i].relay;
return relay;
}
@ -1392,17 +1392,17 @@ List getLineWithMaxLen(String s, int startIndex, int lenPerLine, String spacesSt
// The contact only stores id and relay of contact. The actual name is stored in a global variable/map
class Contact implements Comparable<Contact> {
String id, relay;
Contact(this.id, this.relay);
String contactPubkey, relay;
Contact(this.contactPubkey, this.relay);
@override
String toString() {
return 'id: $id ( ${getAuthorName(id)}) relay: $relay';
return 'id: $contactPubkey ( ${getAuthorName(contactPubkey)}) relay: $relay';
}
@override
int compareTo(Contact other) {
return getAuthorName(id).compareTo(getAuthorName(other.id));
return getAuthorName(contactPubkey).compareTo(getAuthorName(other.contactPubkey));
}
}

View File

@ -114,7 +114,7 @@ bool followsInvolved(Event e, Event? contactEvent) {
}
// if its an event by any of the contact
if(contactEvent.eventData.contactList.any((contact) => e.eventData.pubkey == contact.id )) {
if(contactEvent.eventData.contactList.any((contact) => e.eventData.pubkey == contact.contactPubkey )) {
return true;
}
@ -124,7 +124,7 @@ bool followsInvolved(Event e, Event? contactEvent) {
if( reactors != null) {
for( var reactor in reactors) {
String reactorPubkey = reactor[0];
if(contactEvent.eventData.contactList.any((contact) => reactorPubkey == contact.id )) {
if(contactEvent.eventData.contactList.any((contact) => reactorPubkey == contact.contactPubkey )) {
return true;
}
}
@ -490,7 +490,7 @@ class Tree {
// 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(Set<String> pubkeys, [bool onlyNew = false]) {
bool treeSelectorotificationsFor(Set<String> pubkeys, [bool onlyNew = false]) {
bool hasReaction = false;
bool childMatches = false;
bool isMentioned = false;
@ -529,7 +529,7 @@ class Tree {
}
for( int i = 0; i < children.length; i++ ) {
if( children[i].treeSelectorRepliesAndLikes(pubkeys)) {
if( children[i].treeSelectorotificationsFor(pubkeys)) {
childMatches = true;
}
}
@ -541,17 +541,16 @@ class Tree {
}
// returns true if the tree or its children has a post or like by user; and notification flags are set for such events
bool treeSelectorUserPostAndLike(String pubkey) {
bool treeSelectorUserPostAndLike(Set<String> pubkeys) {
bool hasReacted = false;
if( gReactions.containsKey(event.eventData.id)) {
List<List<String>>? reactions = gReactions[event.eventData.id];
if( reactions != null) {
for( int i = 0; i < reactions.length; i++) {
if( reactions[i][0] == pubkey) {
event.eventData.newLikes.add(pubkey);
if( pubkeys.contains(reactions[i][0]) ) {
event.eventData.newLikes.add(reactions[i][0]);
hasReacted = true;
break;
}
}
}
@ -559,11 +558,13 @@ class Tree {
bool childMatches = false;
for( int i = 0; i < children.length; i++ ) {
if( children[i].treeSelectorUserPostAndLike(pubkey)) {
if( children[i].treeSelectorUserPostAndLike(pubkeys)) {
childMatches = true;
}
}
if( event.eventData.pubkey == pubkey) {
// if event is by user(s)
if( pubkeys.contains(event.eventData.pubkey)) {
event.eventData.isNotification = true;
return true;
}
@ -2267,7 +2268,7 @@ class Store {
List<Contact>? contactList = userInfo.latestContactEvent?.eventData.contactList;
if( contactList != null ) {
for(int i = 0; i < contactList.length; i ++) {
if( contactList[i].id == pubkey) {
if( contactList[i].contactPubkey == pubkey) {
followers.add(otherPubkey);
return;
}
@ -2298,17 +2299,17 @@ class Store {
selfNumContacts = selfContacts.length;
for(int i = 0; i < selfContacts.length; i ++) {
// check if you follow the other account
if( selfContacts[i].id == otherPubkey) {
if( selfContacts[i].contactPubkey == otherPubkey) {
isFollow = true;
}
// count the number of your contacts who know or follow the other account
List<Contact> followContactList = [];
Event? followContactEvent = getContactEvent(selfContacts[i].id);
Event? followContactEvent = getContactEvent(selfContacts[i].contactPubkey);
if( followContactEvent != null) {
followContactList = followContactEvent.eventData.contactList;
for(int j = 0; j < followContactList.length; j++) {
if( followContactList[j].id == otherPubkey) {
mutualFollows.add(getAuthorName(selfContacts[i].id, 0));
if( followContactList[j].contactPubkey == otherPubkey) {
mutualFollows.add(getAuthorName(selfContacts[i].contactPubkey, 0));
numSecond++;
break;
}

View File

@ -15,6 +15,19 @@ Event? getContactEvent(String pubkey) {
return null;
}
// returns all follows
Set<String> getFollows(String pubkey) {
Set<String> followPubkeys = {};
Event? profileContactEvent = getContactEvent(pubkey);
if( profileContactEvent != null) {
profileContactEvent.eventData.contactList.forEach((x) => followPubkeys.add(x.contactPubkey));
//followPubkeys = profileContactEvent.eventData.contactList.toSet();
}
return followPubkeys;
}
Set<String> getUserChannels(Set<Event> userEvents, String userPublicKey) {
Set<String> userChannels = {};

View File

@ -5,6 +5,9 @@ homepage: https://github.com/vishalxl/nostr_console
# improved user notifications , menu 2 -> 3, now likes are shown as notifications and less informative
# improved 2 -> 5. better printing. and fixed white after reaction highlighed issue
# improved 2 -> 6 too, now follows posts get highlighed, and so do their reactions.
# mentions get highlighed in above menus
# 0.3.0
# added check marks; added more default users