mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-04-25 16:00:43 +02:00
now user can add a new contact even when they dont have a previous kind 3 event
also put checks about 64 byte lengths on keys supplied on command line
This commit is contained in:
parent
ff9b40d9aa
commit
a03916fea4
@ -59,11 +59,19 @@ Future<void> main(List<String> arguments) async {
|
||||
|
||||
if( argResults[pubkeyArg] != null) {
|
||||
userPublicKey = argResults[pubkeyArg];
|
||||
if( userPublicKey.length != 64){
|
||||
print("Length of provided public key should be 64. Exiting.");
|
||||
return;
|
||||
}
|
||||
userPrivateKey = "";
|
||||
print("Going to use public key $userPublicKey. You will not be able to send posts/replies.");
|
||||
}
|
||||
if( argResults[prikeyArg] != null) {
|
||||
userPrivateKey = argResults[prikeyArg];
|
||||
if( userPrivateKey.length != 64){
|
||||
print("Length of provided private key should be 64. Exiting.");
|
||||
return;
|
||||
}
|
||||
userPublicKey = getPublicKey(userPrivateKey);
|
||||
print("Going to use the provided private key");
|
||||
}
|
||||
|
@ -88,12 +88,13 @@ Future<void> sendChatMessage(Tree node, String channelId, String messageToSend)
|
||||
sendRequest( gListRelayUrls, toSendMessage);
|
||||
}
|
||||
|
||||
// send event e
|
||||
// sends event e
|
||||
Future<void> sendEvent(Tree node, Event e) async {
|
||||
String strTags = "";
|
||||
int createdAt = DateTime.now().millisecondsSinceEpoch ~/1000;
|
||||
String content = addEscapeChars( e.eventData.content);
|
||||
|
||||
// read the contacts and make them part of the tags, and then the sha
|
||||
if( e.eventData.kind == 3) {
|
||||
strTags = ""; // only new contacts will be sent
|
||||
for(int i = 0; i < e.eventData.contactList.length; i++) {
|
||||
@ -291,7 +292,21 @@ Future<void> otherMenuUi(Tree node, var contactList) async {
|
||||
print("The contact already exists in the contact list. Republishing the old contact list.");
|
||||
sendEvent(node, contactEvent);
|
||||
}
|
||||
} else {
|
||||
// TODO fix the send event functions by streamlining them
|
||||
print('Sending first contact event');
|
||||
|
||||
String newId = "", newPubkey = userPublicKey, newContent = "";
|
||||
int newKind = 3;
|
||||
List<String> newEtags = [], newPtags = [pk];
|
||||
List<List<String>> newTags = [[]];
|
||||
Set<String> newNewLikes = {};
|
||||
int newCreatedAt = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
List<Contact> newContactList = [ Contact(pk, defaultServerUrl) ];
|
||||
|
||||
EventData newEventData = EventData(newId, newPubkey, newCreatedAt, newKind, newContent, newEtags, newPtags, newContactList, newTags, newNewLikes,);
|
||||
Event newEvent = Event( "EVENT", newId, newEventData, [], "");
|
||||
sendEvent(node, newEvent);
|
||||
}
|
||||
|
||||
//print("TBD");
|
||||
|
@ -204,7 +204,7 @@ class EventData {
|
||||
|
||||
EventData(this.id, this.pubkey, this.createdAt, this.kind, this.content, this.eTagsRest, this.pTags,
|
||||
this.contactList, this.tags, this.newLikes, {this.isNotification = false, this.evaluatedContent = ""});
|
||||
|
||||
|
||||
factory EventData.fromJson(dynamic json) {
|
||||
List<Contact> contactList = [];
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user