Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: NIP 50 search #37

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@

- [new **a** filter](https://github.com/nostr-protocol/nips/commit/e50bf508d9014cfb19bfa8a5c4ec88dc4788d490)
- Upgrade bip340 dependency

## 1.4.2

- NIP50: search filter
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
8 changes: 7 additions & 1 deletion lib/src/filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<String, dynamic> json) {
Expand All @@ -51,6 +55,7 @@ class Filter {
since = json['since'];
until = json['until'];
limit = json['limit'];
search = json['search'];
}

/// Serialize a filter in JSON
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
7 changes: 6 additions & 1 deletion test/filter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void main() {
int since = 1672477960;
int until = 1674063680;
int limit = 450;
String search = "term";

Filter filter = Filter(
ids: ids,
Expand All @@ -28,6 +29,7 @@ void main() {
since: since,
until: until,
limit: limit,
search: search,
);

expect(filter.ids, ids);
Expand All @@ -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', () {
Expand All @@ -55,7 +58,8 @@ void main() {
"#p": [],
"since": 1672477960,
"until": 1674063680,
"limit": 450
"limit": 450,
"search": "test",
};

Filter filter = Filter.fromJson(json);
Expand All @@ -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']);
});
});
}
11 changes: 8 additions & 3 deletions test/request_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void main() {
since: 1672477960,
until: 1674063680,
limit: 450,
search: "term",
);

Request req = Request("733209259899167", [myFilter]);
Expand All @@ -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",
Expand All @@ -55,7 +57,8 @@ void main() {
"#p": [],
"since": 1672477960,
"until": 1674063680,
"limit": 450
"limit": 450,
"search": "term",
},
{
"kinds": [0, 1, 2, 7],
Expand Down Expand Up @@ -84,7 +87,8 @@ void main() {
"#p": [],
"since": 1672477960,
"until": 1674063680,
"limit": 450
"limit": 450,
"search": "term",
},
{
"kinds": [0, 1, 2, 7],
Expand All @@ -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);
Expand Down