put dm in separate menu.

fixed issue where new dm decryption was crashing when logged in with pubkey only.
This commit is contained in:
Vishal
2022-09-03 04:55:30 +05:30
parent 7457c78605
commit e4e5be6bf9
5 changed files with 69 additions and 34 deletions

View File

@@ -263,7 +263,7 @@ Future<void> main(List<String> arguments) async {
gContactLists[userPublicKey] = contactEvent.eventData.contactList;
}
} 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..............');

View File

@@ -455,21 +455,14 @@ Future<void> channelMenuUI(Store node) async {
while(continueChatMenu) {
int option = showMenu([ 'Show public channels', // 1
'Enter a public channel', // 2
'See personal Inbox',
'Reply or Send a direct message',
'Go back to main menu'], // 5
"Channel Menu"); // name of menu
'Go back to main menu'], // 3
"Public Channels Menu"); // name of menu
print('You picked: $option');
switch(option) {
case 1:
node.printAllChannelsInfo();
break;
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;
stdout.write("\nType channel id or name, or their 1st few letters; or type 'x' to go to menu: ");
@@ -498,12 +491,19 @@ Future<void> channelMenuUI(Store node) async {
} else {
if( messageToSend.isChannelPageNumber(gMaxChannelPagesDisplayed) ) {
pageNum = (int.tryParse(messageToSend))??1;
} else {
// 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");
} else {
// send message to the given room
await sendChatMessage(node, fullChannelId, messageToSend);
pageNum = 1; // reset it
}
}
}
} else {
print("Refreshing...");
}
@@ -513,11 +513,32 @@ Future<void> channelMenuUI(Store node) async {
break;
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}");
node.printDirectRoomInfo();
break;
case 4:
case 2:
// in case the program was invoked with --pubkey, then user can't send messages
if( userPrivateKey == "") {
print("Since no private key has been supplied, messages and replies can't be sent. Invoke with --prikey \n");
@@ -552,6 +573,10 @@ Future<void> channelMenuUI(Store node) async {
if( messageToSend.isChannelPageNumber(gMaxChannelPagesDisplayed) ) {
pageNum = (int.tryParse(messageToSend))??1;
} else {
// 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");
}
// send message to the given room
await sendDirectMessage(node, fullChannelId, messageToSend);
pageNum = 1; // reset it
@@ -566,7 +591,7 @@ Future<void> channelMenuUI(Store node) async {
break;
case 5:
case 3:
continueChatMenu = false;
break;
@@ -577,15 +602,16 @@ Future<void> channelMenuUI(Store node) async {
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);
node.printTree(0, DateTime.now().subtract(Duration(days:gNumLastDays)), hasRepliesAndLikes);
bool userContinue = true;
while(userContinue) {
// align the text again in case the window size has been changed
if( gAlignment == "center") {
try {
@@ -600,14 +626,15 @@ Future<void> mainMenuUi(Store node) async {
}
}
await processNotifications(node);
await processNotifications(node); // this takes 300 ms
// the main menu
int option = showMenu(['Display feed', // 1
'Post/Reply/Like', // 2
'Direct Messsage and Public Channels', // 3
'Other Options', // 4
'Quit'], // 5
'Public Channels', // 3
'Private Messages', // 4
'Other Options', // 5
'Quit'], // 6
"Main Menu");
print('You picked: $option');
switch(option) {
@@ -650,10 +677,14 @@ Future<void> mainMenuUi(Store node) async {
break;
case 4:
await otherMenuUi(node);
await PrivateMenuUI(node);
break;
case 5:
await otherMenuUi(node);
break;
case 6:
default:
userContinue = false;
String authorName = getAuthorName(userPublicKey);

View File

@@ -198,6 +198,9 @@ class EventData {
break;
case 4:
if( userPrivateKey == ""){ // cant process if private key not given
break;
}
if( pubkey == userPublicKey ) break; // crashes right now otherwise
if(!isUserDirectMessage(this)) {
break;
@@ -540,7 +543,7 @@ String getAuthorName(String pubkey, [int len = 3]) {
Set<String> getPublicKeyFromName(String userName) {
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) {
// 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) {
print("$pk $userName" );
//print("$pk $userName" );
if( pk.substring(0, userName.length) == userName) {
pubkeys.add(pk);
}

View File

@@ -12,8 +12,9 @@ String gEventsFilename = ""; // is set in arguments, and if set, th
bool gDontWriteOldEvents = 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 gLimitPerSubscription = 20000;
const int gLimitPerSubscription = 10000;
// 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

View File

@@ -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.
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
return "";
}
@@ -857,7 +857,7 @@ class Store {
// TODO improve lookup logic.
directRooms.forEach((roomId, directRoom) {
print("looking up $directRoomId in $roomId ${directRoom.otherPubkey}");
//print("looking up $directRoomId in $roomId ${directRoom.otherPubkey}");
if( directRoomId == roomId) {
lookedUpName.add(roomId);
}