Skip to content

Commit

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

* Oops. wrong letter

* Add a tag to these test cases

---------

Co-authored-by: cm <c@m.com>
  • Loading branch information
bigOconstant and cm committed Sep 1, 2023
1 parent 8aa5a47 commit a532b33
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/src/filter.dart
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 @@ -63,6 +68,9 @@ class Filter {
if (e != null) {
data['#e'] = e;
}
if (a != null) {
data['#a'] = a;
}
if (p != null) {
data['#p'] = p;
}
Expand Down
4 changes: 4 additions & 0 deletions test/filter_test.dart
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.e, e);
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 Down
7 changes: 6 additions & 1 deletion test/request_test.dart
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 a532b33

Please sign in to comment.