Skip to content

Commit

Permalink
improved channel lookup further
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalxl committed Dec 5, 2022
1 parent 9014304 commit 777de50
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
66 changes: 39 additions & 27 deletions lib/tree_ds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1703,6 +1703,25 @@ class Store {

}

Set<String> getExactMatches(List<Channel> listChannels, channelId) {
Set<String> matches = {};

for(int i = 0; i < listChannels.length; i++) {
Channel room = listChannels[i];

// exact match name
if( room.chatRoomName.toLowerCase() == channelId.toLowerCase()) {
matches.add(room.channelId);
}

// exact match channel id
if( room.channelId.toLowerCase() == channelId.toLowerCase()) {
matches.add(room.channelId);
}
}
return matches;
}

// works for both 4x and 14x channels
// 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.
Expand All @@ -1711,36 +1730,29 @@ class Store {
return "";
}

//print("looking for $channelId");

// first check channelsId's, in case user has sent a channelId itself
Set<String> fullChannelId = {};
for(int i = 0; i < listChannels.length; i++) {
if( listChannels[i].channelId.length >= channelId.length && listChannels[i].channelId.substring(0, channelId.length) == channelId ) {
fullChannelId.add(listChannels[i].channelId.toLowerCase());
}
}

// lookup in channel room name
for(int i = 0; i < listChannels.length; i++) {
Channel room = listChannels[i];
if( room.chatRoomName.length < channelId.length) {
continue;
}
Set<String> fullChannelId = getExactMatches(listChannels, channelId);

if( fullChannelId.length != 1) {
for(int i = 0; i < listChannels.length; i++) {
// do partial match in channel room name
Channel room = listChannels[i];
if( room.chatRoomName.length >= channelId.length) {
if( room.chatRoomName.substring(0, channelId.length).toLowerCase() == channelId.toLowerCase() ) {
// otherwise add it to list
fullChannelId.add(room.channelId.toLowerCase());
}
}

if( room.chatRoomName.substring(0, channelId.length).toLowerCase() == channelId.toLowerCase() ) {

if( room.chatRoomName.toLowerCase() == channelId.toLowerCase()) {
//if there is an exact match in name, then use that
fullChannelId = {};
fullChannelId.add(room.channelId.toLowerCase());
break;
} else {
// otherwise add it to list
fullChannelId.add(room.channelId.toLowerCase());
// do partial match in ids
if( room.chatRoomName.length >= channelId.length) {
if( listChannels[i].channelId.length >= channelId.length && listChannels[i].channelId.substring(0, channelId.length).toLowerCase() == channelId.toLowerCase() ) {
// otherwise add it to list
fullChannelId.add(room.channelId.toLowerCase());
}
}
}
} // end for
} // end for
}

if( fullChannelId.length == 1) {
Channel? room = getChannel( listChannels, fullChannelId.first);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ homepage: https://github.com/vishalxl/nostr_console

# crated location and t rooms
# t tags added for all tags

environment:
sdk: '>=2.17.3 <3.0.0'

Expand Down

0 comments on commit 777de50

Please sign in to comment.