From 0e0b5bc0484cd9358d3dc065bf3224fa1091fea6 Mon Sep 17 00:00:00 2001 From: Vishal <64505169+vishalxl@users.noreply.github.com> Date: Fri, 9 Sep 2022 19:26:40 +0530 Subject: [PATCH] printed notifications for channels too at start so all three notifications get printed now at start --- lib/console_ui.dart | 14 ++++++++++---- lib/event_ds.dart | 7 +++++++ lib/tree_ds.dart | 25 ++++++++++++++++++++----- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/lib/console_ui.dart b/lib/console_ui.dart index 3ef320b..d641d3b 100644 --- a/lib/console_ui.dart +++ b/lib/console_ui.dart @@ -501,7 +501,7 @@ Future channelMenuUI(Store node) async { //await processNotifications(node); // this takes 300 ms if( !justShowedChannels) { - node.printAllChannelsInfo(20); + node.printAllChannelsInfo(20, selectorShowAllRooms); justShowedChannels = true; } @@ -512,7 +512,7 @@ Future channelMenuUI(Store node) async { print('You picked: $option'); switch(option) { case 1: - node.printAllChannelsInfo(1000); + node.printAllChannelsInfo(1000, selectorShowAllRooms); justShowedChannels = true; break; case 2: @@ -587,12 +587,13 @@ Future PrivateMenuUI(Store node) async { // bool fromClient (Tree t) => t.fromClientSelector(clientName); // node.printTree(0, DateTime.now().subtract(Duration(days:gNumLastDays)), fromClient); // search for last gNumLastDays only - bool showAllRooms (DirectMessageRoom room) => selectorShowAllDirectRooms(room); + bool showAllRooms (ScrollableMessages room) => selectorShowAllRooms(room); node.printDirectRoomInfo(showAllRooms); int option = showMenu([ 'Reply or Send a direct message', + 'Create hub group chat', 'Go back to main menu'], // 3 "Private Message Menu"); // name of menu print('You picked: $option'); @@ -654,6 +655,9 @@ Future PrivateMenuUI(Store node) async { break; case 2: + + + case 3: continueChatMenu = false; break; @@ -672,9 +676,11 @@ Future mainMenuUi(Store node) async { bool hasRepliesAndLikes (Tree t) => t.hasRepliesAndLikes(userPublicKey); node.printTree(0, DateTime.now().subtract(Duration(days:gNumLastDays)), hasRepliesAndLikes); - bool showNotifications (DirectMessageRoom room) => room.selectorNotifications(); + bool showNotifications (ScrollableMessages room) => room.selectorNotifications(); node.printDirectRoomInfo(showNotifications); + node.printAllChannelsInfo(20, showNotifications); + bool userContinue = true; while(userContinue) { diff --git a/lib/event_ds.dart b/lib/event_ds.dart index a25f2f8..5702a9d 100644 --- a/lib/event_ds.dart +++ b/lib/event_ds.dart @@ -214,6 +214,13 @@ class EventData { String? decrypted = decryptContent(); if( decrypted != null) { evaluatedContent = decrypted; + + // hubgroup can have two types of messages + // 1. sent by self, declaring the pub/pri keys of the new group chat and its N members (not including user themselve). Its len is (64) * (2 + N) and spaces + // hub grp pubkey, hub grp prikey, participant1, participant2, .. participantN + // 2. Messages from users that are to be broadcast to others + // hub grp pubkey, + // } break; } // end switch diff --git a/lib/tree_ds.dart b/lib/tree_ds.dart index 28963ef..199a61f 100644 --- a/lib/tree_ds.dart +++ b/lib/tree_ds.dart @@ -5,7 +5,7 @@ import 'package:nostr_console/event_ds.dart'; import 'package:nostr_console/settings.dart'; typedef fTreeSelector = bool Function(Tree a); -typedef fDirectRoomSelector = bool Function(DirectMessageRoom room); +typedef fRoomSelector = bool Function(ScrollableMessages room); Store? gStore = null; @@ -13,7 +13,7 @@ bool selectorShowAllTrees(Tree t) { return true; } -bool selectorShowAllDirectRooms(DirectMessageRoom room) { +bool selectorShowAllRooms(ScrollableMessages room) { return true; } @@ -772,7 +772,7 @@ class Store { allChildEventsMap[parentId]?.children.add(newTree); } else { // create top unknown parent and then add it - Event dummy = Event("","", EventData(parentId, gDummyAccountPubkey, newTree.event.eventData.createdAt, 1, "Unknown parent event", [], [], [], [[]], {}), [""], "[json]"); + Event dummy = Event("","", EventData(parentId, gDummyAccountPubkey, newTree.event.eventData.createdAt, 1, "Event not loaded", [], [], [], [[]], {}), [""], "[json]"); Tree dummyTopNode = Tree.withoutStore(dummy, []); dummyTopNode.children.add(newTree); topPosts.add(dummyTopNode); @@ -970,7 +970,22 @@ class Store { /** * @printAllChennelsInfo Print one line information about all channels, which are type 40 events ( class ChatRoom) */ - void printAllChannelsInfo(int numToPrint) { + void printAllChannelsInfo(int numToPrint, fRoomSelector selector) { + + int numRoomsSelected = 0; + for( int j = 0; j < channels.length; j++) { + if( selector(channels[j])) + numRoomsSelected++; + } + + if( numRoomsSelected == 0) { + return; + } + + // if selected rooms is less, then print only that + if( numRoomsSelected < numToPrint) + numToPrint = numRoomsSelected; + channels.sort(scrollableCompareTo); print(""); if( numToPrint < channels.length) { @@ -1066,7 +1081,7 @@ class Store { /** * @printDirectRoomInfo Print one line information about chat rooms */ - void printDirectRoomInfo(fDirectRoomSelector roomSelector) { + void printDirectRoomInfo(fRoomSelector roomSelector) { directRooms.sort(scrollableCompareTo); int numNotificationRooms = 0;