mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-12-01 00:07:16 +01:00
improved channel name lookup and now initially network events are shown as notifications
This commit is contained in:
@@ -484,7 +484,7 @@ Future<void> channelMenuUI(Store node) async {
|
|||||||
readjustAlignment();
|
readjustAlignment();
|
||||||
String fullChannelId = node.showChannel(channelId, pageNum);
|
String fullChannelId = node.showChannel(channelId, pageNum);
|
||||||
if( fullChannelId == "") {
|
if( fullChannelId == "") {
|
||||||
print("Could not find the given channel.");
|
//print("Could not find the given channel.");
|
||||||
showChannelOption = false;
|
showChannelOption = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -614,8 +614,8 @@ Future<void> PrivateMenuUI(Store node) async {
|
|||||||
Future<void> mainMenuUi(Store node) async {
|
Future<void> mainMenuUi(Store node) async {
|
||||||
|
|
||||||
// at the very beginning, show the tree with re reply and likes, and then show the options menu
|
// at the very beginning, show the tree with re reply and likes, and then show the options menu
|
||||||
bool hasRepliesAndLikes (Tree t) => t.hasRepliesAndLikes(userPublicKey);
|
//bool hasRepliesAndLikes (Tree t) => t.hasRepliesAndLikes(userPublicKey);
|
||||||
node.printTree(0, DateTime.now().subtract(Duration(days:gNumLastDays)), hasRepliesAndLikes);
|
node.printTree(0, DateTime.now().subtract(Duration(days:gNumLastDays)), selectAll);
|
||||||
|
|
||||||
bool userContinue = true;
|
bool userContinue = true;
|
||||||
while(userContinue) {
|
while(userContinue) {
|
||||||
|
|||||||
@@ -403,7 +403,10 @@ class Event {
|
|||||||
e = json.length > 1? json[0]: "";
|
e = json.length > 1? json[0]: "";
|
||||||
return Event(e,"",EventData("non","", 0, 0, "", [], [], [], [[]], {}), [relay], "[json]", fromFile);
|
return Event(e,"",EventData("non","", 0, 0, "", [], [], [], [[]], {}), [relay], "[json]", fromFile);
|
||||||
}
|
}
|
||||||
return Event(json[0] as String, json[1] as String, EventData.fromJson(json[2]), [relay], d, fromFile );
|
EventData newEventData = EventData.fromJson(json[2]);
|
||||||
|
if( !fromFile)
|
||||||
|
newEventData.isNotification = true;
|
||||||
|
return Event(json[0] as String, json[1] as String, newEventData, [relay], d, fromFile );
|
||||||
} on Exception catch(e) {
|
} on Exception catch(e) {
|
||||||
if( gDebug> 0) {
|
if( gDebug> 0) {
|
||||||
print("Could not create event. returning dummy event. $e");
|
print("Could not create event. returning dummy event. $e");
|
||||||
@@ -662,23 +665,27 @@ String getNumDashes(int num) {
|
|||||||
|
|
||||||
String rightShiftContent(String s, int numSpaces) {
|
String rightShiftContent(String s, int numSpaces) {
|
||||||
String newString = "";
|
String newString = "";
|
||||||
int newlineCounter = 0;
|
int numCharsInCurLine = 0;
|
||||||
String spacesString = getNumSpaces(numSpaces + gNumLeftMarginSpaces);
|
String spacesString = getNumSpaces(numSpaces + gNumLeftMarginSpaces);
|
||||||
|
|
||||||
for(int i = 0; i < s.length; i++) {
|
for(int i = 0; i < s.length; i++) {
|
||||||
if( s[i] == '\n') {
|
if( s[i] == '\n') {
|
||||||
newString += "\n";
|
newString += "\n";
|
||||||
newString += spacesString;
|
newString += spacesString;
|
||||||
newlineCounter = 0;
|
numCharsInCurLine = 0;
|
||||||
} else {
|
} else {
|
||||||
if( newlineCounter >= (gTextWidth - numSpaces)) {
|
if( numCharsInCurLine >= (gTextWidth - numSpaces)) {
|
||||||
|
if( i > 1 && (!isWordSeparater(s[i-1]) && !isWordSeparater(s[i])) ) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
newString += "\n";
|
newString += "\n";
|
||||||
newString += spacesString;
|
newString += spacesString;
|
||||||
newlineCounter = 0;
|
numCharsInCurLine = 0;
|
||||||
}
|
}
|
||||||
newString += s[i];
|
newString += s[i];
|
||||||
}
|
}
|
||||||
newlineCounter++;
|
numCharsInCurLine++;
|
||||||
}
|
}
|
||||||
return newString;
|
return newString;
|
||||||
}
|
}
|
||||||
@@ -692,6 +699,15 @@ bool isNumeric(String s) {
|
|||||||
return double.tryParse(s) != null;
|
return double.tryParse(s) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isWordSeparater(String s) {
|
||||||
|
if( s.length != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return s[0] == ' ' || s[0] == '\n' || s[0] == '\r' || s[0] == '\t'
|
||||||
|
|| s[0] == ',' || s[0] == '.' || s[0] == '-' || s[0] == '('|| s[0] == ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool isWhitespace(String s) {
|
bool isWhitespace(String s) {
|
||||||
if( s.length != 1) {
|
if( s.length != 1) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -922,35 +922,49 @@ class Store {
|
|||||||
|
|
||||||
|
|
||||||
// shows the given channelId, where channelId is prefix-id or channel name as mentioned in room.name. returns full id of channel.
|
// shows the given channelId, where channelId is prefix-id or channel name as mentioned in room.name. returns full id of channel.
|
||||||
|
// looks for channelId in id first, then in names.
|
||||||
String showChannel(String channelId, [int page = 1]) {
|
String showChannel(String channelId, [int page = 1]) {
|
||||||
if( channelId.length > 64 ) {
|
if( channelId.length > 64 ) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Set<String> fullChannelId = {};
|
||||||
for( String key in chatRooms.keys) {
|
for( String key in chatRooms.keys) {
|
||||||
if( key.substring(0, channelId.length) == channelId ) {
|
if( key.substring(0, channelId.length) == channelId ) {
|
||||||
ChatRoom? room = chatRooms[key];
|
fullChannelId.add(key);
|
||||||
if( room != null) {
|
|
||||||
printChannel(room, page);
|
|
||||||
}
|
|
||||||
return key;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// since channelId was not found in channel id, search for it in channel name
|
if(fullChannelId.length != 1) {
|
||||||
for( String key in chatRooms.keys) {
|
for( String key in chatRooms.keys) {
|
||||||
ChatRoom? room = chatRooms[key];
|
ChatRoom? room = chatRooms[key];
|
||||||
if( room != null) {
|
if( room != null) {
|
||||||
if( room.chatRoomName.length < channelId.length) {
|
if( room.chatRoomName.length < channelId.length) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
if( gDebug > 0) print("room = ${room.chatRoomName} channelId = $channelId");
|
||||||
|
if( room.chatRoomName.substring(0, channelId.length) == channelId ) {
|
||||||
|
fullChannelId.add(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if( gDebug > 0) print("room = ${room.chatRoomName} channelId = $channelId");
|
} // end for
|
||||||
if( room.chatRoomName.substring(0, channelId.length) == channelId ) {
|
|
||||||
printChannel(room);
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( fullChannelId.length == 1) {
|
||||||
|
ChatRoom? room = chatRooms[fullChannelId.first];
|
||||||
|
if( room != null) {
|
||||||
|
printChannel(room, page);
|
||||||
|
}
|
||||||
|
return fullChannelId.first;
|
||||||
|
} else {
|
||||||
|
if( fullChannelId.length == 0) {
|
||||||
|
print("Could not find the channel.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
print("Found more than 1 channel: $fullChannelId");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1216,7 +1230,6 @@ class Store {
|
|||||||
if( gDebug > 0 && event.eventData.id == "e8a8a1f526af1023ba85ab3874d2310871e034eb8a0bcb3c289be671065ad03e")
|
if( gDebug > 0 && event.eventData.id == "e8a8a1f526af1023ba85ab3874d2310871e034eb8a0bcb3c289be671065ad03e")
|
||||||
print("in processReaction: 0 got reaction e8a8a1f526af1023ba85ab3874d2310871e034eb8a0bcb3c289be671065ad03e");
|
print("in processReaction: 0 got reaction e8a8a1f526af1023ba85ab3874d2310871e034eb8a0bcb3c289be671065ad03e");
|
||||||
|
|
||||||
|
|
||||||
List<String> validReactionList = ["+", "!"]; // TODO support opposite reactions
|
List<String> validReactionList = ["+", "!"]; // TODO support opposite reactions
|
||||||
List<String> opppositeReactions = ['-', "~"];
|
List<String> opppositeReactions = ['-', "~"];
|
||||||
|
|
||||||
@@ -1362,7 +1375,6 @@ void addMessageToDirectRoom(String directRoomId, String messageId, Map<String, T
|
|||||||
print("In addMessageToChannel: returning without inserting message");
|
print("In addMessageToChannel: returning without inserting message");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int ascendingTimeTree(Tree a, Tree b) {
|
int ascendingTimeTree(Tree a, Tree b) {
|
||||||
if(a.event.eventData.createdAt < b.event.eventData.createdAt) {
|
if(a.event.eventData.createdAt < b.event.eventData.createdAt) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -1390,7 +1402,6 @@ int sortTreeNewestReply(Tree a, Tree b) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @function getTree Creates a Tree out of these received List of events.
|
* @function getTree Creates a Tree out of these received List of events.
|
||||||
* Will remove duplicate events( which should not ideally exists because we have a set),
|
* Will remove duplicate events( which should not ideally exists because we have a set),
|
||||||
@@ -1454,7 +1465,6 @@ String getDirectRoomId(EventData eventData) {
|
|||||||
String uniqueId = "";
|
String uniqueId = "";
|
||||||
participantIds.forEach((element) {uniqueId += element;}); // TODO ensure its only one thats added s
|
participantIds.forEach((element) {uniqueId += element;}); // TODO ensure its only one thats added s
|
||||||
|
|
||||||
|
|
||||||
// send the other persons pubkey as identifier
|
// send the other persons pubkey as identifier
|
||||||
if( eventData.pubkey == userPublicKey) {
|
if( eventData.pubkey == userPublicKey) {
|
||||||
return uniqueId;
|
return uniqueId;
|
||||||
|
|||||||
Reference in New Issue
Block a user