From b2068f6215fafd0b540f8566f6159035ff1053ad Mon Sep 17 00:00:00 2001 From: ethicnology <25751709+ethicnology@users.noreply.github.com> Date: Mon, 16 Oct 2023 09:41:05 +0200 Subject: [PATCH] feat: NIP 50 search (#37) * feat: NIP-50 search capability (#36) Co-authored-by: Jeffrey Sun * chore: bump version --------- Co-authored-by: Jeffrey Sun Co-authored-by: Jeffrey Sun --- CHANGELOG.md | 4 ++++ README.md | 1 + lib/src/filter.dart | 8 +++++++- pubspec.yaml | 2 +- test/filter_test.dart | 7 ++++++- test/request_test.dart | 11 ++++++++--- 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1607d58..8209e94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,3 +66,7 @@ - [new **a** filter](https://github.com/nostr-protocol/nips/commit/e50bf508d9014cfb19bfa8a5c4ec88dc4788d490) - Upgrade bip340 dependency + +## 1.4.2 + +- NIP50: search filter diff --git a/README.md b/README.md index 23cdd37..9676625 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ flutter pub add nostr - [x] [NIP 19 bech32-encoded entities](https://github.com/nostr-protocol/nips/blob/master/19.md) - [x] [NIP 20 Command Results](https://github.com/nostr-protocol/nips/blob/master/20.md) - [x] [NIP 28 Public Chat](https://github.com/nostr-protocol/nips/blob/master/28.md) +- [x] [NIP 50 Search Capability](https://github.com/nostr-protocol/nips/blob/master/50.md) - [x] [NIP 51 Lists](https://github.com/nostr-protocol/nips/blob/master/51.md) diff --git a/lib/src/filter.dart b/lib/src/filter.dart index 1e85b1c..dad9b3e 100644 --- a/lib/src/filter.dart +++ b/lib/src/filter.dart @@ -27,6 +27,9 @@ class Filter { /// maximum number of events to be returned in the initial query int? limit; + /// nip-50 search term + String? search; + /// Default constructor Filter( {this.ids, @@ -37,7 +40,8 @@ class Filter { this.p, this.since, this.until, - this.limit}); + this.limit, + this.search}); /// Deserialize a filter from a JSON Filter.fromJson(Map json) { @@ -51,6 +55,7 @@ class Filter { since = json['since']; until = json['until']; limit = json['limit']; + search = json['search']; } /// Serialize a filter in JSON @@ -65,6 +70,7 @@ class Filter { if (since != null) data['since'] = since; if (until != null) data['until'] = until; if (limit != null) data['limit'] = limit; + if (search != null) data['search'] = search; return data; } } diff --git a/pubspec.yaml b/pubspec.yaml index 284ecfd..7942b91 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: nostr description: A library for nostr protocol implemented in dart for flutter -version: 1.4.1 +version: 1.4.2 homepage: https://github.com/ethicnology/dart-nostr environment: diff --git a/test/filter_test.dart b/test/filter_test.dart index 37abf36..6550ce5 100644 --- a/test/filter_test.dart +++ b/test/filter_test.dart @@ -17,6 +17,7 @@ void main() { int since = 1672477960; int until = 1674063680; int limit = 450; + String search = "term"; Filter filter = Filter( ids: ids, @@ -28,6 +29,7 @@ void main() { since: since, until: until, limit: limit, + search: search, ); expect(filter.ids, ids); @@ -39,6 +41,7 @@ void main() { expect(filter.since, since); expect(filter.until, until); expect(filter.limit, limit); + expect(filter.search, search); }); test('Constructor.fromJson', () { @@ -55,7 +58,8 @@ void main() { "#p": [], "since": 1672477960, "until": 1674063680, - "limit": 450 + "limit": 450, + "search": "test", }; Filter filter = Filter.fromJson(json); @@ -68,6 +72,7 @@ void main() { expect(filter.since, json['since']); expect(filter.until, json['until']); expect(filter.limit, json['limit']); + expect(filter.search, json['search']); }); }); } diff --git a/test/request_test.dart b/test/request_test.dart index f9aea63..96da83d 100644 --- a/test/request_test.dart +++ b/test/request_test.dart @@ -19,6 +19,7 @@ void main() { since: 1672477960, until: 1674063680, limit: 450, + search: "term", ); Request req = Request("733209259899167", [myFilter]); @@ -34,11 +35,12 @@ void main() { expect(req.filters[0].since, myFilter.since); expect(req.filters[0].until, myFilter.until); expect(req.filters[0].limit, myFilter.limit); + expect(req.filters[0].search, myFilter.search); }); test('Request.serialize', () { String serialized = - '["REQ","733209259899167",{"ids":["047663d895d56aefa3f528935c7ce7dc8939eb721a0ec76ef2e558a8257955d2"],"authors":["0ba0206887bd61579bf65ec09d7806bea32c64be1cf2c978cf031a811cd238db"],"kinds":[0,1,2,7],"#e":[],"#a":[],"#p":[],"since":1672477960,"until":1674063680,"limit":450},{"kinds":[0,1,2,7],"since":1673980547,"limit":450}]'; + '["REQ","733209259899167",{"ids":["047663d895d56aefa3f528935c7ce7dc8939eb721a0ec76ef2e558a8257955d2"],"authors":["0ba0206887bd61579bf65ec09d7806bea32c64be1cf2c978cf031a811cd238db"],"kinds":[0,1,2,7],"#e":[],"#a":[],"#p":[],"since":1672477960,"until":1674063680,"limit":450,"search":"term"},{"kinds":[0,1,2,7],"since":1673980547,"limit":450}]'; var json = [ "REQ", "733209259899167", @@ -55,7 +57,8 @@ void main() { "#p": [], "since": 1672477960, "until": 1674063680, - "limit": 450 + "limit": 450, + "search": "term", }, { "kinds": [0, 1, 2, 7], @@ -84,7 +87,8 @@ void main() { "#p": [], "since": 1672477960, "until": 1674063680, - "limit": 450 + "limit": 450, + "search": "term", }, { "kinds": [0, 1, 2, 7], @@ -105,6 +109,7 @@ void main() { expect(req.filters[0].since, 1672477960); expect(req.filters[0].until, 1674063680); expect(req.filters[0].limit, 450); + expect(req.filters[0].search, "term"); expect(req.filters[1].kinds, [0, 1, 2, 7]); expect(req.filters[1].since, 1673980547); expect(req.filters[1].limit, 450);