Skip to content

Commit

Permalink
feat: filter new 'a' tag (#35)
Browse files Browse the repository at this point in the history
* feat: "a" tag filter since NIP01 update (#33)

* Add a tag to filter

* Oops. wrong letter

* Add a tag to these test cases

---------

Co-authored-by: cm <c@m.com>

* fix: unit test filter

* refactor: filter toJson

* chore: upgrade dependencies & bump version

---------

Co-authored-by: CM <caleb.a.mccarthy@protonmail.com>
Co-authored-by: cm <c@m.com>
  • Loading branch information
3 people authored Sep 1, 2023
1 parent 8aa5a47 commit 8a66698
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 27 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,8 @@
- NIP 20 Command Results
- NIP 28 Public Chat
- NIP 51 Lists

## 1.4.1

- [new **a** filter](https://github.com/nostr-protocol/nips/commit/e50bf508d9014cfb19bfa8a5c4ec88dc4788d490)
- Upgrade bip340 dependency
38 changes: 14 additions & 24 deletions lib/src/filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class Filter {
/// a list of event ids that are referenced in an "e" tag
List<String>? e;

/// a list of event ids that are referenced in an "a" tag
List<String>? a;

/// a list of pubkeys that are referenced in a "p" tag
List<String>? p;

Expand All @@ -30,6 +33,7 @@ class Filter {
this.authors,
this.kinds,
this.e,
this.a,
this.p,
this.since,
this.until,
Expand All @@ -42,6 +46,7 @@ class Filter {
json['authors'] == null ? null : List<String>.from(json['authors']);
kinds = json['kinds'] == null ? null : List<int>.from(json['kinds']);
e = json['#e'] == null ? null : List<String>.from(json['#e']);
a = json['#a'] == null ? null : List<String>.from(json['#a']);
p = json['#p'] == null ? null : List<String>.from(json['#p']);
since = json['since'];
until = json['until'];
Expand All @@ -51,30 +56,15 @@ class Filter {
/// Serialize a filter in JSON
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
if (ids != null) {
data['ids'] = ids;
}
if (authors != null) {
data['authors'] = authors;
}
if (kinds != null) {
data['kinds'] = kinds;
}
if (e != null) {
data['#e'] = e;
}
if (p != null) {
data['#p'] = p;
}
if (since != null) {
data['since'] = since;
}
if (until != null) {
data['until'] = until;
}
if (limit != null) {
data['limit'] = limit;
}
if (ids != null) data['ids'] = ids;
if (authors != null) data['authors'] = authors;
if (kinds != null) data['kinds'] = kinds;
if (e != null) data['#e'] = e;
if (a != null) data['#a'] = a;
if (p != null) data['#p'] = p;
if (since != null) data['since'] = since;
if (until != null) data['until'] = until;
if (limit != null) data['limit'] = limit;
return data;
}
}
4 changes: 2 additions & 2 deletions 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.0
version: 1.4.1
homepage: https://github.com/ethicnology/dart-nostr

environment:
Expand All @@ -10,7 +10,7 @@ dev_dependencies:
lints: ^2.0.0
test: ^1.16.0
dependencies:
bip340: ^0.1.0
bip340: ^0.2.0
convert: ^3.1.1
pointycastle: ^3.7.3
bech32: ^0.2.2
Expand Down
5 changes: 5 additions & 0 deletions test/filter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void main() {
];
List<int> kinds = [0, 1, 2, 7];
List<String> e = [];
List<String> a = [];
List<String> p = [];
int since = 1672477960;
int until = 1674063680;
Expand All @@ -22,6 +23,7 @@ void main() {
authors: authors,
kinds: kinds,
e: e,
a: a,
p: p,
since: since,
until: until,
Expand All @@ -32,6 +34,7 @@ void main() {
expect(filter.authors, authors);
expect(filter.kinds, kinds);
expect(filter.e, e);
expect(filter.a, a);
expect(filter.p, p);
expect(filter.since, since);
expect(filter.until, until);
Expand All @@ -48,6 +51,7 @@ void main() {
],
"kinds": [0, 1, 2, 7],
"#e": [],
"#a": [],
"#p": [],
"since": 1672477960,
"until": 1674063680,
Expand All @@ -59,6 +63,7 @@ void main() {
expect(filter.authors, json['authors']);
expect(filter.kinds, json['kinds']);
expect(filter.e, json['#e']);
expect(filter.a, json['#a']);
expect(filter.p, json['#p']);
expect(filter.since, json['since']);
expect(filter.until, json['until']);
Expand Down
7 changes: 6 additions & 1 deletion test/request_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void main() {
],
kinds: [0, 1, 2, 7],
e: [],
a: [],
p: [],
since: 1672477960,
until: 1674063680,
Expand All @@ -27,6 +28,7 @@ void main() {
expect(req.filters[0].authors, myFilter.authors);
expect(req.filters[0].kinds, myFilter.kinds);
expect(req.filters[0].e, myFilter.e);
expect(req.filters[0].a, myFilter.a);
expect(req.filters[0].p, myFilter.p);
expect(req.filters[0].kinds, myFilter.kinds);
expect(req.filters[0].since, myFilter.since);
Expand All @@ -36,7 +38,7 @@ void main() {

test('Request.serialize', () {
String serialized =
'["REQ","733209259899167",{"ids":["047663d895d56aefa3f528935c7ce7dc8939eb721a0ec76ef2e558a8257955d2"],"authors":["0ba0206887bd61579bf65ec09d7806bea32c64be1cf2c978cf031a811cd238db"],"kinds":[0,1,2,7],"#e":[],"#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},{"kinds":[0,1,2,7],"since":1673980547,"limit":450}]';
var json = [
"REQ",
"733209259899167",
Expand All @@ -49,6 +51,7 @@ void main() {
],
"kinds": [0, 1, 2, 7],
"#e": [],
"#a": [],
"#p": [],
"since": 1672477960,
"until": 1674063680,
Expand Down Expand Up @@ -77,6 +80,7 @@ void main() {
],
"kinds": [0, 1, 2, 7],
"#e": [],
"#a": [],
"#p": [],
"since": 1672477960,
"until": 1674063680,
Expand All @@ -95,6 +99,7 @@ void main() {
expect(req.filters[0].authors,
["0ba0206887bd61579bf65ec09d7806bea32c64be1cf2c978cf031a811cd238db"]);
expect(req.filters[0].e, []);
expect(req.filters[0].a, []);
expect(req.filters[0].p, []);
expect(req.filters[0].kinds, [0, 1, 2, 7]);
expect(req.filters[0].since, 1672477960);
Expand Down

0 comments on commit 8a66698

Please sign in to comment.