mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-12-02 00:37:30 +01:00
put dm in separate menu.
fixed issue where new dm decryption was crashing when logged in with pubkey only.
This commit is contained in:
@@ -263,7 +263,7 @@ Future<void> main(List<String> arguments) async {
|
|||||||
gContactLists[userPublicKey] = contactEvent.eventData.contactList;
|
gContactLists[userPublicKey] = contactEvent.eventData.contactList;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if( gDebug >= 0) log.info( "Could not find contact list");
|
if( gDebug > 0) log.info( "Could not find contact list");
|
||||||
}
|
}
|
||||||
|
|
||||||
stdout.write('Waiting for feed to come in..............');
|
stdout.write('Waiting for feed to come in..............');
|
||||||
|
|||||||
@@ -455,21 +455,14 @@ Future<void> channelMenuUI(Store node) async {
|
|||||||
while(continueChatMenu) {
|
while(continueChatMenu) {
|
||||||
int option = showMenu([ 'Show public channels', // 1
|
int option = showMenu([ 'Show public channels', // 1
|
||||||
'Enter a public channel', // 2
|
'Enter a public channel', // 2
|
||||||
'See personal Inbox',
|
'Go back to main menu'], // 3
|
||||||
'Reply or Send a direct message',
|
"Public Channels Menu"); // name of menu
|
||||||
'Go back to main menu'], // 5
|
|
||||||
"Channel Menu"); // name of menu
|
|
||||||
print('You picked: $option');
|
print('You picked: $option');
|
||||||
switch(option) {
|
switch(option) {
|
||||||
case 1:
|
case 1:
|
||||||
node.printAllChannelsInfo();
|
node.printAllChannelsInfo();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// in case the program was invoked with --pubkey, then user can't send messages
|
|
||||||
if( userPrivateKey == "") {
|
|
||||||
print("Since no user private key has been supplied, posts/messages can't be sent. Invoke with --prikey \n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool showChannelOption = true;
|
bool showChannelOption = true;
|
||||||
stdout.write("\nType channel id or name, or their 1st few letters; or type 'x' to go to menu: ");
|
stdout.write("\nType channel id or name, or their 1st few letters; or type 'x' to go to menu: ");
|
||||||
@@ -499,9 +492,16 @@ Future<void> channelMenuUI(Store node) async {
|
|||||||
if( messageToSend.isChannelPageNumber(gMaxChannelPagesDisplayed) ) {
|
if( messageToSend.isChannelPageNumber(gMaxChannelPagesDisplayed) ) {
|
||||||
pageNum = (int.tryParse(messageToSend))??1;
|
pageNum = (int.tryParse(messageToSend))??1;
|
||||||
} else {
|
} else {
|
||||||
// send message to the given room
|
|
||||||
await sendChatMessage(node, fullChannelId, messageToSend);
|
// in case the program was invoked with --pubkey, then user can't send messages
|
||||||
pageNum = 1; // reset it
|
if( userPrivateKey == "") {
|
||||||
|
print("Since no user private key has been supplied, posts/messages can't be sent. Invoke with --prikey \n");
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// send message to the given room
|
||||||
|
await sendChatMessage(node, fullChannelId, messageToSend);
|
||||||
|
pageNum = 1; // reset it
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -513,11 +513,32 @@ Future<void> channelMenuUI(Store node) async {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
|
continueChatMenu = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> PrivateMenuUI(Store node) async {
|
||||||
|
//gDebug = 0;
|
||||||
|
bool continueChatMenu = true;
|
||||||
|
while(continueChatMenu) {
|
||||||
|
int option = showMenu([ 'See personal Inbox',
|
||||||
|
'Reply or Send a direct message',
|
||||||
|
'Go back to main menu'], // 5
|
||||||
|
"Private Message Menu"); // name of menu
|
||||||
|
print('You picked: $option');
|
||||||
|
switch(option) {
|
||||||
|
case 1:
|
||||||
//print("total direct rooms = ${node.directRooms.length}");
|
//print("total direct rooms = ${node.directRooms.length}");
|
||||||
node.printDirectRoomInfo();
|
node.printDirectRoomInfo();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 2:
|
||||||
// in case the program was invoked with --pubkey, then user can't send messages
|
// in case the program was invoked with --pubkey, then user can't send messages
|
||||||
if( userPrivateKey == "") {
|
if( userPrivateKey == "") {
|
||||||
print("Since no private key has been supplied, messages and replies can't be sent. Invoke with --prikey \n");
|
print("Since no private key has been supplied, messages and replies can't be sent. Invoke with --prikey \n");
|
||||||
@@ -552,9 +573,13 @@ Future<void> channelMenuUI(Store node) async {
|
|||||||
if( messageToSend.isChannelPageNumber(gMaxChannelPagesDisplayed) ) {
|
if( messageToSend.isChannelPageNumber(gMaxChannelPagesDisplayed) ) {
|
||||||
pageNum = (int.tryParse(messageToSend))??1;
|
pageNum = (int.tryParse(messageToSend))??1;
|
||||||
} else {
|
} else {
|
||||||
// send message to the given room
|
// in case the program was invoked with --pubkey, then user can't send messages
|
||||||
await sendDirectMessage(node, fullChannelId, messageToSend);
|
if( userPrivateKey == "") {
|
||||||
pageNum = 1; // reset it
|
print("Since no user private key has been supplied, posts/messages can't be sent. Invoke with --prikey \n");
|
||||||
|
}
|
||||||
|
// send message to the given room
|
||||||
|
await sendDirectMessage(node, fullChannelId, messageToSend);
|
||||||
|
pageNum = 1; // reset it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -566,7 +591,7 @@ Future<void> channelMenuUI(Store node) async {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case 5:
|
case 3:
|
||||||
continueChatMenu = false;
|
continueChatMenu = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -577,15 +602,16 @@ Future<void> channelMenuUI(Store node) async {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> mainMenuUi(Store node) async {
|
|
||||||
//gDebug = 0;
|
|
||||||
// at the very beginning, show the tree as it is, and then show the options menu
|
|
||||||
|
|
||||||
|
Future<void> mainMenuUi(Store node) async {
|
||||||
|
|
||||||
|
// 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)), hasRepliesAndLikes);
|
||||||
|
|
||||||
bool userContinue = true;
|
bool userContinue = true;
|
||||||
while(userContinue) {
|
while(userContinue) {
|
||||||
|
|
||||||
// align the text again in case the window size has been changed
|
// align the text again in case the window size has been changed
|
||||||
if( gAlignment == "center") {
|
if( gAlignment == "center") {
|
||||||
try {
|
try {
|
||||||
@@ -600,14 +626,15 @@ Future<void> mainMenuUi(Store node) async {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await processNotifications(node);
|
await processNotifications(node); // this takes 300 ms
|
||||||
|
|
||||||
// the main menu
|
// the main menu
|
||||||
int option = showMenu(['Display feed', // 1
|
int option = showMenu(['Display feed', // 1
|
||||||
'Post/Reply/Like', // 2
|
'Post/Reply/Like', // 2
|
||||||
'Direct Messsage and Public Channels', // 3
|
'Public Channels', // 3
|
||||||
'Other Options', // 4
|
'Private Messages', // 4
|
||||||
'Quit'], // 5
|
'Other Options', // 5
|
||||||
|
'Quit'], // 6
|
||||||
"Main Menu");
|
"Main Menu");
|
||||||
print('You picked: $option');
|
print('You picked: $option');
|
||||||
switch(option) {
|
switch(option) {
|
||||||
@@ -650,10 +677,14 @@ Future<void> mainMenuUi(Store node) async {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
await otherMenuUi(node);
|
await PrivateMenuUI(node);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
|
await otherMenuUi(node);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 6:
|
||||||
default:
|
default:
|
||||||
userContinue = false;
|
userContinue = false;
|
||||||
String authorName = getAuthorName(userPublicKey);
|
String authorName = getAuthorName(userPublicKey);
|
||||||
|
|||||||
@@ -198,7 +198,10 @@ class EventData {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
if( pubkey == userPublicKey) break; // crashes right now otherwise
|
if( userPrivateKey == ""){ // cant process if private key not given
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if( pubkey == userPublicKey ) break; // crashes right now otherwise
|
||||||
if(!isUserDirectMessage(this)) {
|
if(!isUserDirectMessage(this)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -540,7 +543,7 @@ String getAuthorName(String pubkey, [int len = 3]) {
|
|||||||
Set<String> getPublicKeyFromName(String userName) {
|
Set<String> getPublicKeyFromName(String userName) {
|
||||||
Set<String> pubkeys = {};
|
Set<String> pubkeys = {};
|
||||||
|
|
||||||
if(gDebug >= 0) print("In getPublicKeyFromName: doing lookup for $userName len of gKindONames= ${gKindONames.length}");
|
//if(gDebug > 0) print("In getPublicKeyFromName: doing lookup for $userName len of gKindONames= ${gKindONames.length}");
|
||||||
|
|
||||||
gKindONames.forEach((pk, userInfo) {
|
gKindONames.forEach((pk, userInfo) {
|
||||||
// check both the user name, and the pubkey to search for the user
|
// check both the user name, and the pubkey to search for the user
|
||||||
@@ -550,7 +553,7 @@ Set<String> getPublicKeyFromName(String userName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( userName.length <= pk.length) {
|
if( userName.length <= pk.length) {
|
||||||
print("$pk $userName" );
|
//print("$pk $userName" );
|
||||||
if( pk.substring(0, userName.length) == userName) {
|
if( pk.substring(0, userName.length) == userName) {
|
||||||
pubkeys.add(pk);
|
pubkeys.add(pk);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,11 @@ const int gDefaultNumWaitSeconds = 3000; // is used in main()
|
|||||||
const String gDefaultEventsFilename = "all_nostr_events.txt";
|
const String gDefaultEventsFilename = "all_nostr_events.txt";
|
||||||
String gEventsFilename = ""; // is set in arguments, and if set, then file is read from and written to
|
String gEventsFilename = ""; // is set in arguments, and if set, then file is read from and written to
|
||||||
bool gDontWriteOldEvents = true;
|
bool gDontWriteOldEvents = true;
|
||||||
const int gDontSaveBeforeDays = 100; // dont save events older than this many days if gDontWriteOldEvents flag is true
|
const int gDontSaveBeforeDays = 100; // dont save events older than this many days if gDontWriteOldEvents flag is true
|
||||||
|
|
||||||
|
|
||||||
const int gDaysToGetEventsFor = 100; // when getting events, this is the since field (unless a fully formed request is given in command line)
|
const int gDaysToGetEventsFor = 100; // when getting events, this is the since field (unless a fully formed request is given in command line)
|
||||||
const int gLimitPerSubscription = 20000;
|
const int gLimitPerSubscription = 10000;
|
||||||
|
|
||||||
// don't show notifications for events that are older than 5 days and come when program is running
|
// don't show notifications for events that are older than 5 days and come when program is running
|
||||||
// applicable only for notifications and not for search results. Search results set a flag in EventData and don't use this variable
|
// applicable only for notifications and not for search results. Search results set a flag in EventData and don't use this variable
|
||||||
|
|||||||
@@ -825,7 +825,7 @@ class Store {
|
|||||||
*/
|
*/
|
||||||
void printDirectRoomInfo() {
|
void printDirectRoomInfo() {
|
||||||
print("\n\nDirect messages inbox:");
|
print("\n\nDirect messages inbox:");
|
||||||
printUnderlined(" From Num of Messages Latest Message ");
|
printUnderlined(" From Num of Messages Latest Message ");
|
||||||
directRooms.forEach((key, value) {
|
directRooms.forEach((key, value) {
|
||||||
String name = getAuthorName(key, 4);
|
String name = getAuthorName(key, 4);
|
||||||
|
|
||||||
@@ -849,7 +849,7 @@ class Store {
|
|||||||
|
|
||||||
// shows the given directRoomId, where directRoomId is prefix-id or pubkey of the other user. returns full id of other user.
|
// shows the given directRoomId, where directRoomId is prefix-id or pubkey of the other user. returns full id of other user.
|
||||||
String showDirectRoom(String directRoomId, [int page = 1]) {
|
String showDirectRoom(String directRoomId, [int page = 1]) {
|
||||||
print("In show DirectRoom $directRoomId");
|
//print("In show DirectRoom $directRoomId");
|
||||||
if( directRoomId.length > 64) { // TODO revisit cause if name is > 64 should not return
|
if( directRoomId.length > 64) { // TODO revisit cause if name is > 64 should not return
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -857,7 +857,7 @@ class Store {
|
|||||||
|
|
||||||
// TODO improve lookup logic.
|
// TODO improve lookup logic.
|
||||||
directRooms.forEach((roomId, directRoom) {
|
directRooms.forEach((roomId, directRoom) {
|
||||||
print("looking up $directRoomId in $roomId ${directRoom.otherPubkey}");
|
//print("looking up $directRoomId in $roomId ${directRoom.otherPubkey}");
|
||||||
if( directRoomId == roomId) {
|
if( directRoomId == roomId) {
|
||||||
lookedUpName.add(roomId);
|
lookedUpName.add(roomId);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user