|
@@ -16,7 +16,7 @@ use tokio::sync::{mpsc::Sender, RwLock};
|
|
|
|
|
|
type SubIdx = (Key, ConnectionId, SubscriptionId);
|
|
|
|
|
|
-pub const MIN_PREFIX_MATCH_LEN: usize = 4;
|
|
|
+pub const MIN_PREFIX_MATCH_LEN: usize = 2;
|
|
|
|
|
|
/// Subscription for a connection
|
|
|
///
|
|
@@ -110,41 +110,33 @@ impl SubscriptionManager {
|
|
|
let author = event.author().as_ref().to_vec();
|
|
|
let id = event.id.as_ref().to_vec();
|
|
|
|
|
|
- let len = author.len();
|
|
|
- for i in min_prefix_match_len..len - min_prefix_match_len {
|
|
|
- subscriptions.push(Key::Author(author[..len - i].to_vec(), None));
|
|
|
- subscriptions.push(Key::Author(author[..len - i].to_vec(), Some(event.kind())));
|
|
|
+ for i in min_prefix_match_len..=author.len() {
|
|
|
+ subscriptions.push(Key::Author(author[..i].to_vec(), None));
|
|
|
+ subscriptions.push(Key::Author(author[..i].to_vec(), Some(event.kind())));
|
|
|
}
|
|
|
|
|
|
for t in event.tags() {
|
|
|
match t {
|
|
|
nostr_rs_types::types::Tag::Event(ref_event) => {
|
|
|
- let len = ref_event.id.len();
|
|
|
- for i in min_prefix_match_len..ref_event.id.len() - min_prefix_match_len {
|
|
|
- subscriptions.push(Key::RefId(ref_event.id[..len - i].to_vec(), None));
|
|
|
- subscriptions.push(Key::RefId(
|
|
|
- ref_event.id[..len - i].to_vec(),
|
|
|
- Some(event.kind()),
|
|
|
- ));
|
|
|
+ for i in min_prefix_match_len..=ref_event.id.len() {
|
|
|
+ subscriptions.push(Key::RefId(ref_event.id[..i].to_vec(), None));
|
|
|
+ subscriptions
|
|
|
+ .push(Key::RefId(ref_event.id[..i].to_vec(), Some(event.kind())));
|
|
|
}
|
|
|
}
|
|
|
nostr_rs_types::types::Tag::PubKey(ref_pub_key) => {
|
|
|
- let len = ref_pub_key.id.len();
|
|
|
- for i in min_prefix_match_len..len - min_prefix_match_len {
|
|
|
- subscriptions.push(Key::RefId(ref_pub_key.id[..len - i].to_vec(), None));
|
|
|
- subscriptions.push(Key::RefId(
|
|
|
- ref_pub_key.id[..len - i].to_vec(),
|
|
|
- Some(event.kind()),
|
|
|
- ));
|
|
|
+ for i in min_prefix_match_len..=ref_pub_key.id.len() {
|
|
|
+ subscriptions.push(Key::RefId(ref_pub_key.id[..i].to_vec(), None));
|
|
|
+ subscriptions
|
|
|
+ .push(Key::RefId(ref_pub_key.id[..i].to_vec(), Some(event.kind())));
|
|
|
}
|
|
|
}
|
|
|
_ => {}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- let len = id.len();
|
|
|
- for i in min_prefix_match_len..len - min_prefix_match_len {
|
|
|
- subscriptions.push(Key::Id(id[..len - i].to_vec()));
|
|
|
+ for i in min_prefix_match_len..=id.len() {
|
|
|
+ subscriptions.push(Key::Id(id[..i].to_vec()));
|
|
|
}
|
|
|
|
|
|
subscriptions.push(Key::Kind(event.kind()));
|