mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-06-22 06:42:36 +02:00
sorted the events displayed in channel by time; minor menu word improvements
This commit is contained in:
parent
10bc0d187b
commit
6f6caea6cd
@ -81,11 +81,11 @@ int showMenu(List<String> menuOptions, String menuName) {
|
|||||||
Future<void> otherMenuUi(Tree node, var contactList) async {
|
Future<void> otherMenuUi(Tree node, var contactList) async {
|
||||||
bool continueOtherMenu = true;
|
bool continueOtherMenu = true;
|
||||||
while(continueOtherMenu) {
|
while(continueOtherMenu) {
|
||||||
int option = showMenu([ 'Display Contact List', // 1
|
int option = showMenu([ 'Display contact list', // 1
|
||||||
'Follow new contact', // 2
|
'Follow new contact', // 2
|
||||||
'Change number of days printed', // 3
|
'Change number of days printed', // 3
|
||||||
'Show a user profile', // 4
|
'Show a user profile', // 4
|
||||||
'Show tweets containg word', // 5
|
'Search (a word)', // 5
|
||||||
'Help and About', // 6
|
'Help and About', // 6
|
||||||
'Go back to main menu'], // 7
|
'Go back to main menu'], // 7
|
||||||
"Other Menu"); // menu name
|
"Other Menu"); // menu name
|
||||||
@ -217,13 +217,13 @@ Future<void> chatMenuUi(Tree node, var contactList) async {
|
|||||||
bool continueChatMenu = true;
|
bool continueChatMenu = true;
|
||||||
while(continueChatMenu) {
|
while(continueChatMenu) {
|
||||||
int option = showMenu([ 'Show channels', // 1
|
int option = showMenu([ 'Show channels', // 1
|
||||||
'Enter channel', // 2
|
'Enter a channel', // 2
|
||||||
'Go back to main menu'], // 3
|
'Go back to main menu'], // 3
|
||||||
"Channel Menu"); // name of menu
|
"Channel Menu"); // name of menu
|
||||||
print('You picked: $option');
|
print('You picked: $option');
|
||||||
switch(option) {
|
switch(option) {
|
||||||
case 1:
|
case 1:
|
||||||
node.showChatRooms();
|
node.printAllChannelsInfo();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
bool showChannelOption = true;
|
bool showChannelOption = true;
|
||||||
@ -290,9 +290,9 @@ Future<void> mainMenuUi(Tree node, var contactList) async {
|
|||||||
|
|
||||||
await processNotifications(node);
|
await processNotifications(node);
|
||||||
// the main menu
|
// the main menu
|
||||||
int option = showMenu(['Display events', // 1
|
int option = showMenu(['Display feed', // 1
|
||||||
'Post/Reply', // 2
|
'Post/Reply/Like', // 2
|
||||||
'Chat', // 3
|
'Channels', // 3
|
||||||
'Other Options', // 4
|
'Other Options', // 4
|
||||||
'Quit'], // 5
|
'Quit'], // 5
|
||||||
"Main Menu");
|
"Main Menu");
|
||||||
|
@ -403,9 +403,7 @@ class ChatRoom {
|
|||||||
List<String> messageIds; // all the 42 kind events in this
|
List<String> messageIds; // all the 42 kind events in this
|
||||||
|
|
||||||
ChatRoom(this.chatRoomId, this.name, this.about, this.picture, this.messageIds);
|
ChatRoom(this.chatRoomId, this.name, this.about, this.picture, this.messageIds);
|
||||||
void insertMessage(String msg) {
|
|
||||||
messageIds.add(msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> getpTags(List<Event> events) {
|
List<String> getpTags(List<Event> events) {
|
||||||
|
@ -30,12 +30,12 @@ class Tree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create a map from list of events, key is eventId and value is event itself
|
// create a map from list of events, key is eventId and value is event itself
|
||||||
Map<String, Tree> allChildEventsMap = {};
|
Map<String, Tree> tempChildEventsMap = {};
|
||||||
events.forEach((event) {
|
events.forEach((event) {
|
||||||
// only add in map those kinds that are supported or supposed to be added ( 0 1 3 7 40)
|
// only add in map those kinds that are supported or supposed to be added ( 0 1 3 7 40)
|
||||||
if( event.eventData.kind == 40 || event.eventData.kind == 42) if( gDebug > 0) print("in from Events: got a kind 40/42 event of id ${event.eventData.id} and kind ${event.eventData.kind}" );
|
//if( event.eventData.kind == 40 || event.eventData.kind == 42) if( gDebug > 0) print("in from Events: got a kind 40/42 event of id ${event.eventData.id} and kind ${event.eventData.kind}" );
|
||||||
if( typesInEventMap.contains(event.eventData.kind)) {
|
if( typesInEventMap.contains(event.eventData.kind)) {
|
||||||
allChildEventsMap[event.eventData.id] = Tree(event, [], {}, [], false, {});
|
tempChildEventsMap[event.eventData.id] = Tree(event, [], {}, [], false, {});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ class Tree {
|
|||||||
List<String> tempWithoutParent = [];
|
List<String> tempWithoutParent = [];
|
||||||
Map<String, ChatRoom> rooms = {};
|
Map<String, ChatRoom> rooms = {};
|
||||||
|
|
||||||
allChildEventsMap.forEach((key, value) {
|
tempChildEventsMap.forEach((key, value) {
|
||||||
String eId = value.e.eventData.id;
|
String eId = value.e.eventData.id;
|
||||||
int eKind = value.e.eventData.kind;
|
int eKind = value.e.eventData.kind;
|
||||||
|
|
||||||
@ -53,7 +53,8 @@ class Tree {
|
|||||||
String chatRoomId = value.e.eventData.getChatRoomId();
|
String chatRoomId = value.e.eventData.getChatRoomId();
|
||||||
if( chatRoomId != "") {
|
if( chatRoomId != "") {
|
||||||
if( rooms.containsKey(chatRoomId)) {
|
if( rooms.containsKey(chatRoomId)) {
|
||||||
rooms[chatRoomId]?.insertMessage(eId);
|
if( gDebug > 0) print("Adding new message $key to a chat room $chatRoomId. ");
|
||||||
|
addMessageToChannel(chatRoomId, eId, tempChildEventsMap, rooms);
|
||||||
if( gDebug > 0) print("Added new message to a chat room $chatRoomId. ");
|
if( gDebug > 0) print("Added new message to a chat room $chatRoomId. ");
|
||||||
} else {
|
} else {
|
||||||
List<String> temp = [];
|
List<String> temp = [];
|
||||||
@ -97,16 +98,16 @@ class Tree {
|
|||||||
//stdout.write("added to parent a child\n");
|
//stdout.write("added to parent a child\n");
|
||||||
String id = key;
|
String id = key;
|
||||||
String parentId = value.e.eventData.getParent();
|
String parentId = value.e.eventData.getParent();
|
||||||
if( allChildEventsMap.containsKey(parentId)) {
|
if( tempChildEventsMap.containsKey(parentId)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(allChildEventsMap.containsKey( parentId)) {
|
if(tempChildEventsMap.containsKey( parentId)) {
|
||||||
if( allChildEventsMap[parentId]?.e.eventData.kind != 1) { // since parent can only be a kind 1 event
|
if( tempChildEventsMap[parentId]?.e.eventData.kind != 1) { // since parent can only be a kind 1 event
|
||||||
if( gDebug > 0) print("In Tree.fromEvents: got a kind 1 event whose parent is not a type 1 post: $id");
|
if( gDebug > 0) print("In Tree.fromEvents: got a kind 1 event whose parent is not a type 1 post: $id");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
allChildEventsMap[parentId]?.addChildNode(value); // in this if condition this will get called
|
tempChildEventsMap[parentId]?.addChildNode(value); // in this if condition this will get called
|
||||||
} else {
|
} else {
|
||||||
// in case where the parent of the new event is not in the pool of all events,
|
// in case where the parent of the new event is not in the pool of all events,
|
||||||
// then we create a dummy event and put it at top ( or make this a top event?) TODO handle so that this can be replied to, and is fetched
|
// then we create a dummy event and put it at top ( or make this a top event?) TODO handle so that this can be replied to, and is fetched
|
||||||
@ -122,10 +123,10 @@ class Tree {
|
|||||||
topLevelTrees.add(dummyTopNode);
|
topLevelTrees.add(dummyTopNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}); // going over tempChildEventsMap
|
||||||
|
|
||||||
// add parent trees as top level child trees of this tree
|
// add parent trees as top level child trees of this tree
|
||||||
for( var value in allChildEventsMap.values) {
|
for( var value in tempChildEventsMap.values) {
|
||||||
if( value.e.eventData.kind == 1 && value.e.eventData.eTagsRest.isEmpty) { // only posts which are parents
|
if( value.e.eventData.kind == 1 && value.e.eventData.eTagsRest.isEmpty) { // only posts which are parents
|
||||||
topLevelTrees.add(value);
|
topLevelTrees.add(value);
|
||||||
}
|
}
|
||||||
@ -136,7 +137,7 @@ class Tree {
|
|||||||
|
|
||||||
// create a dummy top level tree and then create the main Tree object
|
// create a dummy top level tree and then create the main Tree object
|
||||||
Event dummy = Event("","", EventData("non","", 0, 1, "Dummy Top event. Should not be printed.", [], [], [], [[]], {}), [""], "[json]");
|
Event dummy = Event("","", EventData("non","", 0, 1, "Dummy Top event. Should not be printed.", [], [], [], [[]], {}), [""], "[json]");
|
||||||
return Tree( dummy, topLevelTrees, allChildEventsMap, tempWithoutParent, true, rooms);
|
return Tree( dummy, topLevelTrees, tempChildEventsMap, tempWithoutParent, true, rooms);
|
||||||
} // end fromEvents()
|
} // end fromEvents()
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -204,7 +205,8 @@ class Tree {
|
|||||||
if( channelId != "") {
|
if( channelId != "") {
|
||||||
if( chatRooms.containsKey(channelId)) {
|
if( chatRooms.containsKey(channelId)) {
|
||||||
print("added event to chat room in insert event");
|
print("added event to chat room in insert event");
|
||||||
chatRooms[channelId]?.messageIds.add(newTree.e.eventData.id);
|
addMessageToChannel(channelId, newTree.e.eventData.id, allChildEventsMap, chatRooms);
|
||||||
|
//chatRooms[channelId]?.messageIds.add(newTree.e.eventData.id);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print("error: in insert events, could not find parent/channel id");
|
print("error: in insert events, could not find parent/channel id");
|
||||||
@ -222,6 +224,7 @@ class Tree {
|
|||||||
return newEventsId;
|
return newEventsId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @printNotifications Add the given events to the Tree, and print the events as notifications
|
* @printNotifications Add the given events to the Tree, and print the events as notifications
|
||||||
* It should be ensured that these are only kind 1 events
|
* It should be ensured that these are only kind 1 events
|
||||||
@ -384,12 +387,8 @@ class Tree {
|
|||||||
return numPrinted;
|
return numPrinted;
|
||||||
}
|
}
|
||||||
|
|
||||||
void showChatRooms() {
|
void printAllChannelsInfo() {
|
||||||
print("\n\nChat Rooms:");
|
print("\n\nChat Rooms:");
|
||||||
printChatRoomInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
void printChatRoomInfo() {
|
|
||||||
chatRooms.forEach((key, value) {
|
chatRooms.forEach((key, value) {
|
||||||
String name = "";
|
String name = "";
|
||||||
if( value.name == "") {
|
if( value.name == "") {
|
||||||
@ -419,7 +418,8 @@ class Tree {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void printRoom(ChatRoom room) {
|
void printChannel(ChatRoom room) {
|
||||||
|
|
||||||
for(int i = 0; i < room.messageIds.length; i++) {
|
for(int i = 0; i < room.messageIds.length; i++) {
|
||||||
String eId = room.messageIds[i];
|
String eId = room.messageIds[i];
|
||||||
Event? e = allChildEventsMap[eId]?.e;
|
Event? e = allChildEventsMap[eId]?.e;
|
||||||
@ -438,7 +438,7 @@ class Tree {
|
|||||||
if( key.substring(0, channelId.length) == channelId ) {
|
if( key.substring(0, channelId.length) == channelId ) {
|
||||||
ChatRoom? room = chatRooms[key];
|
ChatRoom? room = chatRooms[key];
|
||||||
if( room != null) {
|
if( room != null) {
|
||||||
printRoom(room);
|
printChannel(room);
|
||||||
}
|
}
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
@ -454,7 +454,7 @@ class Tree {
|
|||||||
|
|
||||||
print("room = ${room.name} channelId = $channelId");
|
print("room = ${room.name} channelId = $channelId");
|
||||||
if( room.name.substring(0, channelId.length) == channelId ) {
|
if( room.name.substring(0, channelId.length) == channelId ) {
|
||||||
printRoom(room);
|
printChannel(room);
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -707,8 +707,50 @@ class Tree {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end Tree
|
} // end Tree
|
||||||
|
|
||||||
|
void addMessageToChannel(String channelId, String messageId, var tempChildEventsMap, var chatRooms) {
|
||||||
|
//chatRooms[channelId]?.messageIds.add(newTree.e.eventData.id);
|
||||||
|
|
||||||
|
int newEventTime = (tempChildEventsMap[messageId]?.e.eventData.createdAt??0);
|
||||||
|
|
||||||
|
if( chatRooms.containsKey(channelId)) {
|
||||||
|
ChatRoom? room = chatRooms[channelId];
|
||||||
|
if( room != null ) {
|
||||||
|
if( room.messageIds.isEmpty) {
|
||||||
|
if(gDebug> 0) print("room is empty. adding new message and returning. ");
|
||||||
|
room.messageIds.add(messageId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(gDebug> 0) print("room has ${room.messageIds.length} messages already. adding new one to it. ");
|
||||||
|
|
||||||
|
for(int i = 0; i < room.messageIds.length; i++) {
|
||||||
|
int eventTime = (tempChildEventsMap[room.messageIds[i]]?.e.eventData.createdAt??0);
|
||||||
|
if( newEventTime < eventTime) {
|
||||||
|
// shift current i and rest one to the right, and put event Time here
|
||||||
|
room.messageIds.insert(i, messageId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// insert at end
|
||||||
|
room.messageIds.add(messageId);
|
||||||
|
return;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
print("In addMessageToChannel: could not find room");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print("In addMessageToChannel: could not find channel id");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
print("In addMessageToChannel: returning without inserting message");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int ascendingTimeTree(Tree a, Tree b) {
|
int ascendingTimeTree(Tree a, Tree b) {
|
||||||
if(a.e.eventData.createdAt < b.e.eventData.createdAt) {
|
if(a.e.eventData.createdAt < b.e.eventData.createdAt) {
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user