Added support for diaplay_name and website in kind 0

This commit is contained in:
Vishal 2022-12-29 21:22:23 +05:30
parent 9dbd97b44b
commit 01590b6670
3 changed files with 32 additions and 17 deletions

View File

@ -318,6 +318,8 @@ void printProfile(Store node, String profilePubkey) {
String picture = gKindONames[profilePubkey]?.picture??"";
String lud06 = gKindONames[profilePubkey]?.lud06??"";
String lud16 = gKindONames[profilePubkey]?.lud16??"";
String display_name= gKindONames[profilePubkey]?.display_name??"";
String website = gKindONames[profilePubkey]?.website??"";
int dateLastUpdated = gKindONames[profilePubkey]?.createdAt??0;
bool verified = gKindONames[profilePubkey]?.nip05Verified??false;
String nip05Id = gKindONames[profilePubkey]?.nip05Id??"";
@ -359,6 +361,8 @@ void printProfile(Store node, String profilePubkey) {
print("\nName : $authorName ( ${profilePubkey} ).");
print("About : $about");
print("Picture : $picture");
print("display_name: $display_name");
print("Website : $website");
print("Lud06 : $lud06");
print("Lud16 : $lud16");
print("Nip 05 : ${verified?"yes. ${nip05Id}":"no"}");
@ -564,23 +568,29 @@ Future<void> otherOptionsMenuUi(Store node) async {
print("Your current name: ${getAuthorName(userPublicKey)}");
print("Your 'about me': ${gKindONames[userPublicKey]?.about}");
print("Your current profile picture: ${gKindONames[userPublicKey]?.picture}");
print("Your current display name: ${gKindONames[userPublicKey]?.display_name}");
print("Your current website: ${gKindONames[userPublicKey]?.website}");
print("Your current NIP 05 id: ${gKindONames[userPublicKey]?.nip05Id}");
print("Your current lud06: ${gKindONames[userPublicKey]?.lud06}");
print("Your current lud16: ${gKindONames[userPublicKey]?.lud16}");
print("\n\nEnter new data. Leave blank to use the old value:\n");
String userName = getStringFromUser("Enter your new display name: ", getAuthorName(userPublicKey));
String userAbout = getStringFromUser("Enter new 'about me' for yourself: ", gKindONames[userPublicKey]?.about??"");
String userPic = getStringFromUser("Enter url to your new display picture: ", gKindONames[userPublicKey]?.picture??"https://placekitten.com/200/200");
String nip05id = getStringFromUser("Enter your nip 05 id. Leave blank if unknown/none: ", gKindONames[userPublicKey]?.nip05Id??"");
String lud06 = getStringFromUser("Enter your lud06 or lnurl. Leave blank if unknown/none: ", gKindONames[userPublicKey]?.lud06??"");
String lud16 = getStringFromUser("Enter your lud16 address. Leave blank if unknown/none: ", gKindONames[userPublicKey]?.lud16??"");
print("\n\nEnter new data. Leave blank to use the old value. Some clients use name, others use display name; you can enter same value for both:\n");
String userName = getStringFromUser("Enter your new name : ", getAuthorName(userPublicKey));
String userAbout = getStringFromUser("Enter new 'about me' for yourself : ", gKindONames[userPublicKey]?.about??"");
String userPic = getStringFromUser("Enter url to your new display picture: ", gKindONames[userPublicKey]?.picture??"https://placekitten.com/200/200");
String display_name = getStringFromUser("Enter your new display name : ", gKindONames[userPublicKey]?.display_name??"");
String website = getStringFromUser("Enter your new website : ", gKindONames[userPublicKey]?.website??"");
String nip05id = getStringFromUser("Enter your nip 05 id. Leave blank if unknown/none: ", gKindONames[userPublicKey]?.nip05Id??"");
String lud06 = getStringFromUser("Enter your lud06 or lnurl. Leave blank if unknown/none: ", gKindONames[userPublicKey]?.lud06??"");
String lud16 = getStringFromUser("Enter your lud16 address. Leave blank if unknown/none: ", gKindONames[userPublicKey]?.lud16??"");
String strLud06 = lud06.length > 0? '"lud06":"$lud06",': '';
String strLud16 = lud16.length > 0? '"lud16":"$lud16",': '';
String strDispName = display_name.length > 0? '"display_name":"$display_name",': '';
String strWebsite = website.length > 0? '"website":"$website",': '';
String content = "{\"name\": \"$userName\", \"about\": \"$userAbout\", \"picture\": \"$userPic\"${ nip05id.length >0 ? ", $strLud06 $strLud16 \"nip05\": \"$nip05id\"":""}}";
String content = "{\"name\": \"$userName\", \"about\": \"$userAbout\", \"picture\": \"$userPic\"${ nip05id.length >0 ? ", $strDispName $strWebsite $strLud06 $strLud16 \"nip05\": \"$nip05id\"":""}}";
int createdAt = DateTime.now().millisecondsSinceEpoch ~/1000;
EventData eventData = EventData('id', userPublicKey, createdAt, 0, content, [], [], [], [], {}, );

View File

@ -33,12 +33,12 @@ List<String> nip08PlaceHolders = ["#[0]", "#[1]", "#[2]", "#[3]", "#[4]", "#[5]"
// kind 0 event and/or kind 3 event, both with their own time stamps.
class UserNameInfo {
int? createdAt;
String? name, about, picture, lud06, lud16;
String? name, about, picture, lud06, lud16, display_name, website;
int? createdAtKind3;
Event ?latestContactEvent;
bool nip05Verified;
String? nip05Id;
UserNameInfo(this.createdAt, this.name, this.about, this.picture, this.lud06, this.lud16, this.nip05Id , this.latestContactEvent, [this.createdAtKind3 = null, this.nip05Verified = false]);
UserNameInfo(this.createdAt, this.name, this.about, this.picture, this.lud06, this.lud16, this.display_name, this.website, this.nip05Id , this.latestContactEvent, [this.createdAtKind3 = null, this.nip05Verified = false]);
}
/*
@ -1116,6 +1116,8 @@ bool processKind0Event(Event e) {
String picture = "";
String lud06 = "";
String lud16 = "";
String display_name = "";
String website = "";
String nip05 = "";
try {
@ -1125,6 +1127,8 @@ bool processKind0Event(Event e) {
picture = json["picture"]??"";
lud06 = json["lud06"]??"";
lud16 = json["lud16"]??"";
display_name = json["display_name"]??"";
website = json["website"]??"";
nip05 = json['nip05']??"";
//String twitterId = json['twitter']??"";
//String githubId = json['github']??"";
@ -1134,12 +1138,12 @@ bool processKind0Event(Event e) {
bool newEntry = false, entryModified = false;
if( !gKindONames.containsKey(e.eventData.pubkey)) {
gKindONames[e.eventData.pubkey] = UserNameInfo(e.eventData.createdAt, name, about, picture, lud06, lud16, nip05, null);
gKindONames[e.eventData.pubkey] = UserNameInfo(e.eventData.createdAt, name, about, picture, lud06, lud16, display_name, website, nip05, null);
newEntry = true;;
} else {
int oldTime = gKindONames[e.eventData.pubkey]?.createdAt??0;
if( oldTime < e.eventData.createdAt) {
gKindONames[e.eventData.pubkey] = UserNameInfo(e.eventData.createdAt, name, about, picture, lud06, lud16, nip05, null);
gKindONames[e.eventData.pubkey] = UserNameInfo(e.eventData.createdAt, name, about, picture, lud06, lud16, display_name, website, nip05, null);
entryModified = true;
}
}
@ -1175,7 +1179,7 @@ bool processKind0Event(Event e) {
int oldTime = 0;
if( !gKindONames.containsKey(e.eventData.pubkey)) {
//printWarning("in response handing. creating user info");
gKindONames[e.eventData.pubkey] = UserNameInfo(e.eventData.createdAt, name, about, picture, lud06, lud16, null, null);
gKindONames[e.eventData.pubkey] = UserNameInfo(e.eventData.createdAt, name, about, picture, lud06, lud16, display_name, website,null, null);
} else {
oldTime = gKindONames[e.eventData.pubkey]?.createdAt??0;
//print("in response handing. user info exists with old time = $oldTime and this event time = ${e.eventData.createdAt}");
@ -1211,7 +1215,7 @@ bool processKind3Event(Event newContactEvent) {
bool newEntry = false, entryModified = false;
if( !gKindONames.containsKey(newContactEvent.eventData.pubkey)) {
gKindONames[newContactEvent.eventData.pubkey] = UserNameInfo(null, null, null, null, null, null, null, newContactEvent, newContactEvent.eventData.createdAt);
gKindONames[newContactEvent.eventData.pubkey] = UserNameInfo(null, null, null, null, null, null, null, null, null, newContactEvent, newContactEvent.eventData.createdAt);
newEntry = true;;
} else {
// if entry already exists, then check its old time and update only if we have a newer entry now
@ -1223,9 +1227,11 @@ bool processKind3Event(Event newContactEvent) {
picture = gKindONames[newContactEvent.eventData.pubkey]?.picture,
lud06 = gKindONames[newContactEvent.eventData.pubkey]?.lud06,
lud16 = gKindONames[newContactEvent.eventData.pubkey]?.lud16,
display_name = gKindONames[newContactEvent.eventData.pubkey]?.display_name,
website = gKindONames[newContactEvent.eventData.pubkey]?.website,
nip05id = gKindONames[newContactEvent.eventData.pubkey]?.nip05Id??"";
gKindONames[newContactEvent.eventData.pubkey] = UserNameInfo(createdAt, name, about, picture, lud06, lud16, nip05id, newContactEvent, newContactEvent.eventData.createdAt );
gKindONames[newContactEvent.eventData.pubkey] = UserNameInfo(createdAt, name, about, picture, lud06, lud16, display_name, website, nip05id, newContactEvent, newContactEvent.eventData.createdAt );
entryModified = true;;
}
}

View File

@ -1340,7 +1340,7 @@ class Store {
// for pubkeys that don't have any kind 0 events ( but have other events), add then to global kind0 store so they can still be accessed
tempChildEventsMap.forEach((key, value) {
if( !gKindONames.containsKey(value.event.eventData.pubkey)) {
gKindONames[value.event.eventData.pubkey] = UserNameInfo(null, null, null, null, null, null, null, null );
gKindONames[value.event.eventData.pubkey] = UserNameInfo(null, null, null, null, null, null, null, null, null, null );
}
});
@ -1399,7 +1399,6 @@ class Store {
// add the event to the main event store thats allChildEventsMap
newEventsToProcess.forEach((newEvent) {
if( newEvent.eventData.kind == 1 && newEvent.eventData.content.compareTo("Hello Nostr! :)") == 0 && newEvent.eventData.id.substring(0,2).compareTo("00") == 0) {
return; // spam prevention
}