Skip to content

Commit

Permalink
refactor: PR #29
Browse files Browse the repository at this point in the history
  • Loading branch information
ethicnology committed May 24, 2023
1 parent 5113922 commit 44cb1e2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 38 deletions.
74 changes: 39 additions & 35 deletions lib/src/nips/nip_028.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -133,52 +135,54 @@ class Nip28 {
Map<String, dynamic> map = {
'name': name,
'about': about,
'picture': picture,
'picture': picture
};
map.addAll(additional);
String content = jsonEncode(map);
List<List<String>> 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<ETag>? etags, List<PTag>? ptags}) {
List<List<String>> 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<String, dynamic> map = {
'reason': reason,
};
String content = jsonEncode(map);
List<List<String>> tags = [];
tags.add(["e", messageId]);
Event event =
Event.from(kind: 43, tags: tags, content: content, privkey: privkey);
return event;
Map<String, dynamic> 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<String, dynamic> map = {
'reason': reason,
};
String content = jsonEncode(map);
List<List<String>> tags = [];
tags.add(["p", pubkey]);
Event event =
Event.from(kind: 44, tags: tags, content: content, privkey: privkey);
return event;
Map<String, dynamic> map = {'reason': reason};
return Event.from(
kind: 44,
tags: [
["p", pubkey]
],
content: jsonEncode(map),
privkey: privkey);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/nips/nip_051.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Nip51 {
List<String> 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);
Expand Down
1 change: 0 additions & 1 deletion test/nips/nip_005_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 0 additions & 1 deletion test/nips/nip_028_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 44cb1e2

Please sign in to comment.