Skip to content

Commit 2088be8

Browse files
committed
nostr: fix Filter::match_event NIP-50 search
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 1eed4fb commit 2088be8

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

crates/nostr/src/types/filter.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -748,10 +748,8 @@ impl Filter {
748748
#[inline]
749749
fn search_match(&self, event: &Event) -> bool {
750750
match &self.search {
751-
Some(query) => event
752-
.content
753-
.split_whitespace()
754-
.any(|word| word.eq_ignore_ascii_case(query)),
751+
// TODO: best ways?
752+
Some(query) => event.content.to_lowercase().contains(&query.to_lowercase()),
755753
None => true,
756754
}
757755
}
@@ -1124,6 +1122,34 @@ mod tests {
11241122
let filter: Filter = Filter::new().search("test").into();
11251123
assert!(filter.match_event(&event));
11261124
}
1125+
1126+
#[test]
1127+
fn test_filter_search_match_event() {
1128+
let json: &str = r#"{
1129+
"id": "3d1e30c357eba92568ba67138f9a508d29b306e5254952ee4d7c8039bd4a48fa",
1130+
"pubkey": "68d81165918100b7da43fc28f7d1fc12554466e1115886b9e7bb326f65ec4272",
1131+
"created_at": 1711027680,
1132+
"kind": 0,
1133+
"tags": [
1134+
[
1135+
"alt",
1136+
"User profile for Yuki Kishimoto"
1137+
],
1138+
[
1139+
"i",
1140+
"github:yukibtc",
1141+
"69d9980b6e6b5d77a3e1e369ccaca9ba"
1142+
]
1143+
],
1144+
"content": "{\"banner\":\"https://i.imgur.com/f1h1GgJ.jpg\",\"website\":\"https://yukikishimoto.com\",\"nip05\":\"[email protected]\",\"picture\":\"https://yukikishimoto.com/images/avatar.jpg\",\"lud16\":\"[email protected]\",\"display_name\":\"Yuki Kishimoto\",\"about\":\"GitHub: https://github.com/yukibtc\\nPGP: 86F3 105A DFA8 AB58 7268 DCD7 8D3D CD04 2496 19D1\",\"name\":\"Yuki Kishimoto\",\"displayName\":\"Yuki Kishimoto\"}",
1145+
"sig": "27dddf90036cb7ea893eb13827342c49cbb72c442b3ac7b1f09081868b752d4c6e85882a881599e02a1374d4825e492e81703d44bce9728adccf66bb49f14220"
1146+
}
1147+
"#;
1148+
let event = Event::from_json(json).unwrap();
1149+
1150+
let filter = Filter::new().search("Yuki kishi");
1151+
assert!(filter.match_event(&event));
1152+
}
11271153
}
11281154

11291155
#[cfg(bench)]

0 commit comments

Comments
 (0)