improved channel name lookup and now initially network events are shown as notifications

This commit is contained in:
Vishal
2022-09-04 14:51:04 +05:30
parent 3e8a4e87d6
commit b0af54f353
3 changed files with 56 additions and 30 deletions

View File

@@ -484,7 +484,7 @@ Future<void> channelMenuUI(Store node) async {
readjustAlignment();
String fullChannelId = node.showChannel(channelId, pageNum);
if( fullChannelId == "") {
print("Could not find the given channel.");
//print("Could not find the given channel.");
showChannelOption = false;
break;
}
@@ -614,8 +614,8 @@ Future<void> PrivateMenuUI(Store node) async {
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 hasRepliesAndLikes (Tree t) => t.hasRepliesAndLikes(userPublicKey);
node.printTree(0, DateTime.now().subtract(Duration(days:gNumLastDays)), selectAll);
bool userContinue = true;
while(userContinue) {

View File

@@ -403,7 +403,10 @@ class Event {
e = json.length > 1? json[0]: "";
return Event(e,"",EventData("non","", 0, 0, "", [], [], [], [[]], {}), [relay], "[json]", fromFile);
}
return Event(json[0] as String, json[1] as String, EventData.fromJson(json[2]), [relay], d, fromFile );
EventData newEventData = EventData.fromJson(json[2]);
if( !fromFile)
newEventData.isNotification = true;
return Event(json[0] as String, json[1] as String, newEventData, [relay], d, fromFile );
} on Exception catch(e) {
if( gDebug> 0) {
print("Could not create event. returning dummy event. $e");
@@ -662,23 +665,27 @@ String getNumDashes(int num) {
String rightShiftContent(String s, int numSpaces) {
String newString = "";
int newlineCounter = 0;
int numCharsInCurLine = 0;
String spacesString = getNumSpaces(numSpaces + gNumLeftMarginSpaces);
for(int i = 0; i < s.length; i++) {
if( s[i] == '\n') {
newString += "\n";
newString += spacesString;
newlineCounter = 0;
numCharsInCurLine = 0;
} else {
if( newlineCounter >= (gTextWidth - numSpaces)) {
if( numCharsInCurLine >= (gTextWidth - numSpaces)) {
if( i > 1 && (!isWordSeparater(s[i-1]) && !isWordSeparater(s[i])) ) {
}
newString += "\n";
newString += spacesString;
newlineCounter = 0;
numCharsInCurLine = 0;
}
newString += s[i];
}
newlineCounter++;
numCharsInCurLine++;
}
return newString;
}
@@ -692,6 +699,15 @@ bool isNumeric(String s) {
return double.tryParse(s) != null;
}
bool isWordSeparater(String s) {
if( s.length != 1) {
return false;
}
return s[0] == ' ' || s[0] == '\n' || s[0] == '\r' || s[0] == '\t'
|| s[0] == ',' || s[0] == '.' || s[0] == '-' || s[0] == '('|| s[0] == ')';
}
bool isWhitespace(String s) {
if( s.length != 1) {
return false;

View File

@@ -922,35 +922,49 @@ class Store {
// shows the given channelId, where channelId is prefix-id or channel name as mentioned in room.name. returns full id of channel.
// looks for channelId in id first, then in names.
String showChannel(String channelId, [int page = 1]) {
if( channelId.length > 64 ) {
return "";
}
Set<String> fullChannelId = {};
for( String key in chatRooms.keys) {
if( key.substring(0, channelId.length) == channelId ) {
ChatRoom? room = chatRooms[key];
if( room != null) {
printChannel(room, page);
}
return key;
fullChannelId.add(key);
}
}
// since channelId was not found in channel id, search for it in channel name
for( String key in chatRooms.keys) {
ChatRoom? room = chatRooms[key];
if( room != null) {
if( room.chatRoomName.length < channelId.length) {
continue;
if(fullChannelId.length != 1) {
for( String key in chatRooms.keys) {
ChatRoom? room = chatRooms[key];
if( room != null) {
if( room.chatRoomName.length < channelId.length) {
continue;
}
if( gDebug > 0) print("room = ${room.chatRoomName} channelId = $channelId");
if( room.chatRoomName.substring(0, channelId.length) == channelId ) {
fullChannelId.add(key);
}
}
if( gDebug > 0) print("room = ${room.chatRoomName} channelId = $channelId");
if( room.chatRoomName.substring(0, channelId.length) == channelId ) {
printChannel(room);
return key;
}
}
} // end for
}
if( fullChannelId.length == 1) {
ChatRoom? room = chatRooms[fullChannelId.first];
if( room != null) {
printChannel(room, page);
}
return fullChannelId.first;
} else {
if( fullChannelId.length == 0) {
print("Could not find the channel.");
}
else {
print("Found more than 1 channel: $fullChannelId");
}
}
return "";
}
@@ -1216,7 +1230,6 @@ class Store {
if( gDebug > 0 && event.eventData.id == "e8a8a1f526af1023ba85ab3874d2310871e034eb8a0bcb3c289be671065ad03e")
print("in processReaction: 0 got reaction e8a8a1f526af1023ba85ab3874d2310871e034eb8a0bcb3c289be671065ad03e");
List<String> validReactionList = ["+", "!"]; // TODO support opposite reactions
List<String> opppositeReactions = ['-', "~"];
@@ -1362,7 +1375,6 @@ void addMessageToDirectRoom(String directRoomId, String messageId, Map<String, T
print("In addMessageToChannel: returning without inserting message");
}
int ascendingTimeTree(Tree a, Tree b) {
if(a.event.eventData.createdAt < b.event.eventData.createdAt) {
return -1;
@@ -1390,7 +1402,6 @@ int sortTreeNewestReply(Tree a, Tree b) {
}
}
/*
* @function getTree Creates a Tree out of these received List of events.
* Will remove duplicate events( which should not ideally exists because we have a set),
@@ -1454,7 +1465,6 @@ String getDirectRoomId(EventData eventData) {
String uniqueId = "";
participantIds.forEach((element) {uniqueId += element;}); // TODO ensure its only one thats added s
// send the other persons pubkey as identifier
if( eventData.pubkey == userPublicKey) {
return uniqueId;