Skip to content

Commit dd9e9a3

Browse files
committed
changed display filters and saving logic
displyed global feed. and in incoming notifications, only showed notifications for follows. In writing events, only writing follow's events. and the ones they interact with. now all follows have a tick; no tick for defaults
1 parent 9085c8a commit dd9e9a3

6 files changed

+120
-74
lines changed

lib/console_ui.dart

+14-12
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Future<void> processAnyIncomingEvents(Store node, [bool printNotifications = tru
3030

3131
List<int> numPrinted1 = [0,0,0];
3232
if( printNotifications) {
33+
// print all the new trees, the ones that we want to print
3334
numPrinted1 = node.printTreeNotifications(newEventIds);
3435

3536
// need to clear because only top 20 events in each thread are printed or cleared with above
@@ -303,7 +304,7 @@ void printProfile(Store node, String profilePubkey) {
303304
node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), onlyUserPostAndLike);
304305

305306
// if contact list was found, get user's feed, and keep the contact list for later use
306-
String authorName = getAuthorName(profilePubkey, addTickForWellKnown: false );
307+
String authorName = getAuthorName(profilePubkey);
307308
String pronoun = "";
308309
if( profilePubkey == userPublicKey) {
309310
printUnderlined("\nYour profile - $authorName:");
@@ -1280,9 +1281,9 @@ Future<void> socialMenuUi(Store node) async {
12801281

12811282
// the main menu
12821283
int option = showMenu([
1283-
'All Posts', // 1
1284+
'Your Feed', // 1
12841285
'Post/Reply/Like', // 2
1285-
'Your notifications',// 3
1286+
'Replies/Likes to you',// 3
12861287
'Your Posts', // 4
12871288
'Your Replies/Likes',//5
12881289
'Follows\' Posts/Replies/Likes', // 6
@@ -1295,7 +1296,8 @@ Future<void> socialMenuUi(Store node) async {
12951296

12961297
switch(option) {
12971298
case 1:
1298-
node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_all);
1299+
bool selectorTrees_followActionsNoNotifications (Tree t) => t.treeSelectorUserPostAndLike(getFollows( userPublicKey), enableNotifications: false);
1300+
node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_followActionsNoNotifications);
12991301
await processAnyIncomingEvents(node, true);
13001302
break;
13011303

@@ -1341,18 +1343,18 @@ Future<void> socialMenuUi(Store node) async {
13411343
int notificationHours = gHoursDefaultPrint>24? gHoursDefaultPrint: 24; // minimum 24
13421344
List<int> numPrinted = node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:notificationHours)), selectorTrees_userNotifications);
13431345
if( numPrinted[2] > 0) {
1344-
print("Showed ${numPrinted[2]} notifications.\n");
1346+
print("Showed ${numPrinted[2]} replies/likes that were made to your posts.\n");
13451347
} else {
1346-
print("No notifications.");
1348+
print("No replies or likes.");
13471349
}
13481350

13491351
await processAnyIncomingEvents(node, true);
13501352
break;
13511353
case 4:
13521354
clearScreen();
13531355
List<int> numPrinted = node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_selfPosts);
1354-
if( numPrinted[2] > 0) {
1355-
print("Showed ${numPrinted[2]} posts made by you in last $gHoursDefaultPrint hours.\n");
1356+
if( numPrinted[0] > 0) {
1357+
print("Showed ${numPrinted[0]} posts made by you in last $gHoursDefaultPrint hours.\n");
13561358
} else {
13571359
print("No posts made by you in last $gHoursDefaultPrint hours.");
13581360
}
@@ -1373,8 +1375,8 @@ Future<void> socialMenuUi(Store node) async {
13731375

13741376
case 6:
13751377
clearScreen();
1376-
bool selectorTrees_followActions (Tree t) => t.treeSelectorUserPostAndLike(getFollows( userPublicKey));
1377-
List<int> numPrinted = node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_followActions);
1378+
bool selectorTrees_followActionsWithNotifications (Tree t) => t.treeSelectorUserPostAndLike(getFollows( userPublicKey), enableNotifications: true);
1379+
List<int> numPrinted = node.printStoreTrees(0, DateTime.now().subtract(Duration(hours:gHoursDefaultPrint)), selectorTrees_followActionsWithNotifications);
13781380
if( numPrinted[0] > 0) {
13791381
print("Showed ${numPrinted[0]} threads where your follows participated.\n");
13801382
} else {
@@ -1580,8 +1582,8 @@ Future<void> mainMenuUi(Store node) async {
15801582
firstTime = false;
15811583

15821584
// the main menu
1583-
int option = showMenu(['Home Page', // 1
1584-
'Social Network', // 2
1585+
int option = showMenu(['Global Feed', // 1
1586+
'Social Network', // 2
15851587
'Public Channels', // 3
15861588
'Encrypted Channels',// 4
15871589
'Private Messages', // 5

lib/event_ds.dart

+17-11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'dart:math';
44
import 'package:bip340/bip340.dart';
55
import 'package:intl/intl.dart';
66
import 'package:nostr_console/tree_ds.dart';
7+
import 'package:nostr_console/user.dart';
78
import 'package:nostr_console/utils.dart';
89
import 'package:translator/translator.dart';
910
import 'package:crypto/crypto.dart';
@@ -1246,7 +1247,12 @@ String getNip05Name( String pubkey) {
12461247
}
12471248

12481249
// returns name by looking up global list gKindONames, which is populated by kind 0 events
1249-
String getAuthorName(String pubkey, {bool addTickForWellKnown = true, int maxDisplayLen = gMaxInteger, int pubkeyLenShown = 5}) {
1250+
String getAuthorName(String pubkey, {int maxDisplayLen = gMaxInteger, int pubkeyLenShown = 5}) {
1251+
1252+
if( gFollowList.length == 0) {
1253+
gFollowList = getFollows(userPublicKey);
1254+
}
1255+
bool isFollow = gFollowList.contains(pubkey) && (pubkey != userPublicKey);
12501256

12511257
String maxLen(String pubkey) => pubkey.length > pubkeyLenShown? pubkey.substring(0,pubkeyLenShown) : pubkey.substring(0, pubkey.length);
12521258
String name = "";
@@ -1256,19 +1262,19 @@ String getAuthorName(String pubkey, {bool addTickForWellKnown = true, int maxDis
12561262
name = (gKindONames[pubkey]?.name)??maxLen(pubkey);
12571263
}
12581264

1259-
if( addTickForWellKnown) {
1260-
// first remove the check mark if its in any name
1265+
// then add valid check mark in default follows
1266+
if( isFollow) {
1267+
if( name.length >= maxDisplayLen ) {
1268+
name = name.substring(0, maxDisplayLen-1) + gValidCheckMark;
1269+
} else {
1270+
name = name + gValidCheckMark;
1271+
}
1272+
} else {
1273+
// make this tick a specil character
12611274
name = name.replaceAll(gValidCheckMark, "");
12621275

1263-
// then add valid check mark in default follows
1264-
if( gDefaultFollows.contains(pubkey)) {
1265-
if( name.length >= maxDisplayLen ) {
1266-
name = name.substring(0, maxDisplayLen-1) + gValidCheckMark;
1267-
} else {
1268-
name = name + gValidCheckMark;
1269-
}
1270-
}
12711276
}
1277+
12721278
return name;
12731279
}
12741280

lib/settings.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:logging/logging.dart';
33

44
// name of executable
55
const String exename = "nostr_console";
6-
const String version = "0.3.1-beta-b";
6+
const String version = "0.3.2-beta";
77

88
int gDebug = 0;
99
int gSpecificDebug = 0;

lib/tree_ds.dart

+74-28
Original file line numberDiff line numberDiff line change
@@ -559,32 +559,68 @@ class Tree {
559559
return false;
560560
}
561561

562-
// returns true if the tree or its children has a post or like by user; and notification flags are set for such events
563-
bool treeSelectorUserPostAndLike(Set<String> pubkeys) {
562+
// returns true if the tree has a reply by any of the pubkeys sent
563+
// only used by writefile
564+
bool treeSelectorUserPosted(Set<String> pubkeys, [bool checkChildrenToo = false]) {
565+
566+
if( pubkeys.contains(event.eventData.pubkey)) {
567+
return true;
568+
}
569+
570+
for( int i = 0; i < children.length; i++ ) {
571+
if( children[i].treeSelectorUserPosted(pubkeys)) {
572+
return true;
573+
}
574+
}
575+
576+
return false;
577+
}
578+
579+
// returns true if the tree has a reply by any of the pubkeys sent
580+
// only used by writefile
581+
bool treeSelectorUserReplies(Set<String> pubkeys) {
582+
583+
for( int i = 0; i < children.length; i++ ) {
584+
if( children[i].treeSelectorUserPosted(pubkeys)) {
585+
return true;
586+
}
587+
}
588+
589+
return false;
590+
}
591+
592+
593+
// 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
594+
bool treeSelectorUserPostAndLike(Set<String> pubkeys, { bool enableNotifications = true, bool checkChildrenToo = true}) {
564595
bool hasReacted = false;
565596

566597
if( gReactions.containsKey(event.eventData.id)) {
567598
List<List<String>>? reactions = gReactions[event.eventData.id];
568599
if( reactions != null) {
569600
for( int i = 0; i < reactions.length; i++) {
570601
if( pubkeys.contains(reactions[i][0]) ) {
571-
event.eventData.newLikes.add(reactions[i][0]);
602+
if( enableNotifications)
603+
event.eventData.newLikes.add(reactions[i][0]);
572604
hasReacted = true;
573605
}
574606
}
575607
}
576608
}
577609

578610
bool childMatches = false;
579-
for( int i = 0; i < children.length; i++ ) {
580-
if( children[i].treeSelectorUserPostAndLike(pubkeys)) {
581-
childMatches = true;
611+
612+
if( checkChildrenToo ) {
613+
for( int i = 0; i < children.length; i++ ) {
614+
if( children[i].treeSelectorUserPostAndLike(pubkeys)) {
615+
childMatches = true;
616+
}
582617
}
583618
}
584619

585620
// if event is by user(s)
586621
if( pubkeys.contains(event.eventData.pubkey)) {
587-
event.eventData.isNotification = true;
622+
if( enableNotifications)
623+
event.eventData.isNotification = true;
588624
return true;
589625
}
590626
if( hasReacted || childMatches) {
@@ -1605,13 +1641,19 @@ class Store {
16051641

16061642
Store.reCalculateMarkerStr();
16071643

1644+
// update this list, because it is internally used by printEvent
1645+
gFollowList = getFollows(userPublicKey);
1646+
16081647
List<int> ret = [0,0,0];
1609-
topNotificationTree.forEach( (t) {
1610-
List<int> temp = Store.printTopPost(t, 0, DateTime(0));
1611-
ret[0] += temp[0];
1612-
ret[1] += temp[1];
1613-
ret[2] += temp[2];
1614-
print("\n");
1648+
topNotificationTree.forEach( (t) {
1649+
bool selectorTrees_followActionsWithNotifications (Tree t) => t.treeSelectorUserPostAndLike(getFollows( userPublicKey), enableNotifications: true);
1650+
if( selectorTrees_followActionsWithNotifications(t)) {
1651+
List<int> temp = Store.printTopPost(t, 0, DateTime(0));
1652+
ret[0] += temp[0];
1653+
ret[1] += temp[1];
1654+
ret[2] += temp[2];
1655+
print("\n");
1656+
}
16151657
});
16161658

16171659
return ret;
@@ -1642,6 +1684,9 @@ class Store {
16421684
*/
16431685
List<int> printStoreTrees(int depth, DateTime newerThan, fTreeSelector treeSelector, [int maxToPrint = gMaxEventsInThreadPrinted]) {
16441686

1687+
// update this list, because it is internally used by printEvent
1688+
gFollowList = getFollows(userPublicKey);
1689+
16451690
topPosts.sort(sortTreeNewestReply); // sorting done only for top most threads. Lower threads aren't sorted so save cpu etc TODO improve top sorting
16461691

16471692
// https://gist.github.com/dsample/79a97f38bf956f37a0f99ace9df367b9
@@ -2046,18 +2091,26 @@ class Store {
20462091
return room;
20472092
}
20482093

2049-
2050-
// TODO to be finished
2094+
// threads where the user and follows have involved themselves are returnes as true ( relevant)
20512095
bool isRelevant(Tree tree) {
2052-
//Set<String> contacts = getContactList(userPublicKey);
2053-
//contacts = contacts.union(gDefaultFollows);
20542096

2097+
if( tree.treeSelectorUserPostAndLike(gFollowList)
2098+
|| tree.treeSelectorUserPostAndLike({userPublicKey})
2099+
|| tree.treeSelectorUserReplies(gFollowList)) {
2100+
return true;
2101+
}
20552102

2056-
return true;
2103+
return false;
20572104
}
20582105

20592106
// Write the tree's events to file as one event's json per line
20602107
Future<void> writeEventsToFile(String filename) async {
2108+
2109+
// this variable will be used later; update it if needed
2110+
if( gFollowList.length == 0) {
2111+
gFollowList = getFollows(userPublicKey);
2112+
}
2113+
20612114
if( gDebug > 0) print("opening $filename to write to.");
20622115
try {
20632116
final File file = File(filename);
@@ -2075,7 +2128,9 @@ class Store {
20752128
int linesWritten = 0;
20762129
for( var tree in allChildEventsMap.values) {
20772130

2078-
if( tree.event.eventData.isDeleted) { // dont write those deleted
2131+
if( tree.event.eventData.isDeleted // dont write those deleted
2132+
|| gDummyAccountPubkey == tree.event.eventData.pubkey // dont write dummy events
2133+
|| tree.event.originalJson.length < 10) {
20792134
continue;
20802135
}
20812136

@@ -2085,18 +2140,9 @@ class Store {
20852140
}
20862141
}
20872142

2088-
if( gDummyAccountPubkey == tree.event.eventData.pubkey) {
2089-
continue; // dont write dummy events
2090-
}
2091-
2092-
if( tree.event.originalJson.length < 10) {
2093-
continue;
2094-
}
2095-
20962143
if( !isRelevant(tree)) {
20972144
continue;
20982145
}
2099-
21002146

21012147
String temp = tree.event.originalJson.trim();
21022148
String line = "${temp}\n";

lib/user.dart

+5-18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import 'package:nostr_console/event_ds.dart';
33
import 'package:nostr_console/settings.dart';
44
import 'package:nostr_console/utils.dart';
55

6+
7+
// is set intermittently by functions. and used as required. Should be kept in sync as the kind 3 for user are received.
8+
Set<String> gFollowList = {};
9+
610
// From the list of events provided, lookup the lastst contact information for the given user/pubkey
711
Event? getContactEvent(String pubkey) {
812

@@ -28,6 +32,7 @@ Set<String> getFollows(String pubkey) {
2832
return followPubkeys;
2933
}
3034

35+
3136
Set<String> getUserChannels(Set<Event> userEvents, String userPublicKey) {
3237
Set<String> userChannels = {};
3338

@@ -94,21 +99,3 @@ Set<String> getOnlyUserEvents(Set<Event> initialEvents, String userPubkey) {
9499
return userEvents;
95100
}
96101

97-
98-
Set<String> getContactList(String pubkey) {
99-
Set<String> contacts = {};
100-
101-
if( pubkey != "") {
102-
// get the latest kind 3 event for the user, which has the 'follows' list
103-
Event? contactEvent = getContactEvent(userPublicKey);
104-
105-
// if contact list was found, get user's feed; also get some default contacts
106-
if (contactEvent != null ) {
107-
contactEvent.eventData.contactList.forEach((contact) {
108-
contacts.add(contact.contactPubkey);
109-
});
110-
} else {
111-
}
112-
}
113-
return contacts;
114-
}

pubspec.yaml

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
name: nostr_console
22
description: A multi-platform nostr client built for terminal/console
3-
version: 0.3.1-beta-b
3+
version: 0.3.2-beta
44
homepage: https://github.com/vishalxl/nostr_console
55

6-
6+
7+
# 0.3.2
78
# added build for ubuntu arm 64, and mac arm 64
8-
# matrix change , removed old build entries in dart.yml files
9-
# one off build with num channel messages = 40
9+
# fixed or improved mention expansion
10+
# displyed global feed. which has all latest in last 2 hours
11+
# in incoming notifications, only showed notifications for follows.
12+
# In writing events, only writing follow's events. and the ones they interact with.
13+
# now friends have a tick; no tick for defaults
14+
# fixed likes colors issue for notification likes
1015

1116
# 0.3.1
1217
# added nostr.ch as another default relay to sync with anigma

0 commit comments

Comments
 (0)