From 44cb1e27ca5597ccf9cb4bb5e1db2a70e4aa0741 Mon Sep 17 00:00:00 2001 From: ethicnology Date: Wed, 24 May 2023 16:01:00 +0200 Subject: [PATCH] refactor: PR #29 --- lib/src/nips/nip_028.dart | 74 +++++++++++++++++++------------------ lib/src/nips/nip_051.dart | 2 +- test/nips/nip_005_test.dart | 1 - test/nips/nip_028_test.dart | 1 - 4 files changed, 40 insertions(+), 38 deletions(-) diff --git a/lib/src/nips/nip_028.dart b/lib/src/nips/nip_028.dart index d93ebd3..ba85de3 100644 --- a/lib/src/nips/nip_028.dart +++ b/lib/src/nips/nip_028.dart @@ -116,10 +116,12 @@ class Nip28 { 'picture': picture, }; map.addAll(additional); - String content = jsonEncode(map); - Event event = - Event.from(kind: 40, tags: [], content: content, privkey: privkey); - return event; + return Event.from( + kind: 40, + tags: [], + content: jsonEncode(map), + privkey: privkey, + ); } static Event setChannelMetaData( @@ -133,52 +135,54 @@ class Nip28 { Map map = { 'name': name, 'about': about, - 'picture': picture, + 'picture': picture }; map.addAll(additional); - String content = jsonEncode(map); - List> tags = []; - tags.add(["e", channelId, relayURL]); - Event event = - Event.from(kind: 41, tags: tags, content: content, privkey: privkey); - return event; + return Event.from( + kind: 41, + tags: [ + ["e", channelId, relayURL] + ], + content: jsonEncode(map), + privkey: privkey, + ); } static Event sendChannelMessage( String channelId, String content, String privkey, {String? relay, List? etags, List? ptags}) { - List> tags = []; - Thread t = + Thread thread = Thread(Nip10.rootTag(channelId, relay ?? ''), etags ?? [], ptags ?? []); - tags = Nip10.toTags(t); - Event event = - Event.from(kind: 42, tags: tags, content: content, privkey: privkey); - return event; + return Event.from( + kind: 42, + tags: Nip10.toTags(thread), + content: content, + privkey: privkey, + ); } static Event hideChannelMessage( String messageId, String reason, String privkey) { - Map map = { - 'reason': reason, - }; - String content = jsonEncode(map); - List> tags = []; - tags.add(["e", messageId]); - Event event = - Event.from(kind: 43, tags: tags, content: content, privkey: privkey); - return event; + Map map = {'reason': reason}; + return Event.from( + kind: 43, + tags: [ + ["e", messageId] + ], + content: jsonEncode(map), + privkey: privkey, + ); } static Event muteUser(String pubkey, String reason, String privkey) { - Map map = { - 'reason': reason, - }; - String content = jsonEncode(map); - List> tags = []; - tags.add(["p", pubkey]); - Event event = - Event.from(kind: 44, tags: tags, content: content, privkey: privkey); - return event; + Map map = {'reason': reason}; + return Event.from( + kind: 44, + tags: [ + ["p", pubkey] + ], + content: jsonEncode(map), + privkey: privkey); } } diff --git a/lib/src/nips/nip_051.dart b/lib/src/nips/nip_051.dart index f0483a3..52990f1 100644 --- a/lib/src/nips/nip_051.dart +++ b/lib/src/nips/nip_051.dart @@ -59,7 +59,7 @@ class Nip51 { List bookmarks = []; int ivIndex = content.indexOf("?iv="); if (ivIndex <= 0) { - print("Invalid content, could not get ivIndex: $content"); + throw Exception("Invalid content, could not get ivIndex: $content"); } String iv = content.substring(ivIndex + "?iv=".length, content.length); String encString = content.substring(0, ivIndex); diff --git a/test/nips/nip_005_test.dart b/test/nips/nip_005_test.dart index 7fab14a..215e794 100644 --- a/test/nips/nip_005_test.dart +++ b/test/nips/nip_005_test.dart @@ -12,7 +12,6 @@ void main() { 'wss://relay2.example.com' ]; Event event = Nip5.encode('name', 'example.com', relays, user.private); - print(event.serialize()); expect(event.kind, 0); expect(() => Nip5.encode('name', 'example', relays, user.private), diff --git a/test/nips/nip_028_test.dart b/test/nips/nip_028_test.dart index 3ed9cea..c5eb1e8 100644 --- a/test/nips/nip_028_test.dart +++ b/test/nips/nip_028_test.dart @@ -16,7 +16,6 @@ void main() { }, privkey); Channel channel = Nip28.getChannelCreation(event); - print(event.serialize()); expect(channel.picture, 'http://image.jpg'); expect(channel.additional['badges'], '0f76c800a7ea76b83a3ae87de94c6046b98311bda8885cedd8420885b50de181');