diff --git a/lib/console_ui.dart b/lib/console_ui.dart index 10fbbe2..3fc9510 100644 --- a/lib/console_ui.dart +++ b/lib/console_ui.dart @@ -653,7 +653,7 @@ Future channelMenuUI(Store node) async { break; case 2: - node.printChannelsOverview(node.channels, 1000, selectorShowAllRooms); + node.printChannelsOverview(node.channels, node.channels.length, selectorShowAllRooms); justShowedChannels = true; break; @@ -898,7 +898,7 @@ Future encryptedChannelMenuUI(Store node) async { break; case 2: - node.printChannelsOverview(node.encryptedChannels, 1000, selectorShowAllRooms); + node.printChannelsOverview(node.encryptedChannels, node.encryptedChannels.length, selectorShowAllRooms); justShowedChannels = true; break; diff --git a/lib/tree_ds.dart b/lib/tree_ds.dart index 34a3fa7..5ae16a6 100644 --- a/lib/tree_ds.dart +++ b/lib/tree_ds.dart @@ -1329,45 +1329,24 @@ class Store { /** * @printAllChennelsInfo Print one line information about all channels, which are type 40 events ( class ChatRoom) */ - int printChannelsOverview(List channelstoPrint, int numToPrint, fRoomSelector selector) { + int printChannelsOverview(List channelstoPrint, int numRoomsOverview, fRoomSelector selector) { - int numRoomsSelected = 0; - for( int j = 0; j < channelstoPrint.length; j++) { - //print(channelstoPrint[j].participants); - if( channelstoPrint[j].participants.length == 0 || (channelstoPrint[j].participants.length > 0 && channelstoPrint[j].participants.contains(userPublicKey))) { - if( selector(channelstoPrint[j]) ) { - numRoomsSelected++; - } - } - } - //print(numRoomsSelected); - - if( numRoomsSelected == 0) { - return 0; - } - - // if selected rooms is less, then print only that - //if( numRoomsSelected < numToPrint) numToPrint = numRoomsSelected; - - int numChannelsActuallyPrinted = 0; channelstoPrint.sort(scrollableCompareTo); - print(""); - if( numToPrint < channelstoPrint.length) { - print("Showing only $numToPrint/${channelstoPrint.length} total channels\n"); - } else { - print("Showing all ${channelstoPrint.length} channels\n"); - numToPrint = channelstoPrint.length; - } + int numChannelsActuallyPrinted = 0; printUnderlined(" Channel Name Num of Messages Latest Message "); - for(int j = 0; j < numToPrint; j++) { + for(int j = 0; j < numRoomsOverview; j++) { if( channelstoPrint[j].participants.length > 0 && !channelstoPrint[j].participants.contains(userPublicKey)) { //print(channelstoPrint[j].participants); continue; } + if( !selector(channelstoPrint[j]) ) { + continue; + } + String name = ""; if( channelstoPrint[j].chatRoomName == "") { //print("channel has no name"); @@ -1378,7 +1357,7 @@ class Store { int numMessages = channelstoPrint[j].getNumValidMessages(); stdout.write("${name} ${getNumSpaces(32-name.length)} $numMessages${getNumSpaces(12- numMessages.toString().length)}"); - numChannelsActuallyPrinted ++; + numChannelsActuallyPrinted++; List messageIds = channelstoPrint[j].messageIds; for( int i = messageIds.length - 1; i >= 0; i--) { if( allChildEventsMap.containsKey(messageIds[i])) { @@ -1393,6 +1372,10 @@ class Store { } print(""); } + + print(""); + print("Showing $numChannelsActuallyPrinted channels\n"); + return numChannelsActuallyPrinted; } diff --git a/pubspec.yaml b/pubspec.yaml index b09d94c..27bbeff 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,6 +8,7 @@ homepage: https://github.com/vishalxl/nostr_console # damus reactions # random seed # printed info +#improved environment: sdk: '>=2.17.3 <3.0.0'