mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-06-26 08:41:14 +02:00
handled received delete kind 5 event
so that the original message is not printed. If the original message was in file, its still not deleted.
This commit is contained in:
parent
ec83360ce6
commit
69223d407d
@ -182,6 +182,15 @@ String getShaId(String pubkey, int createdAt, String kind, String strTags, Strin
|
|||||||
return value.toString();
|
return value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get printable date from seconds since epoch
|
||||||
|
String getPrintableDate(int createdAt) {
|
||||||
|
final df1 = DateFormat('hh:mm a');
|
||||||
|
final df2 = DateFormat(DateFormat.ABBR_MONTH_DAY);
|
||||||
|
String strDate = df1.format(DateTime.fromMillisecondsSinceEpoch(createdAt*1000));
|
||||||
|
strDate += " ${df2.format(DateTime.fromMillisecondsSinceEpoch(createdAt*1000))}";
|
||||||
|
return strDate;
|
||||||
|
}
|
||||||
|
|
||||||
class EventData {
|
class EventData {
|
||||||
String id;
|
String id;
|
||||||
String pubkey;
|
String pubkey;
|
||||||
@ -195,9 +204,12 @@ class EventData {
|
|||||||
String evaluatedContent; // content which has mentions expanded, and which has been translated
|
String evaluatedContent; // content which has mentions expanded, and which has been translated
|
||||||
Set<String> newLikes; //
|
Set<String> newLikes; //
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
List<Contact> contactList = []; // used for kind:3 events, which is contact list event
|
List<Contact> contactList = []; // used for kind:3 events, which is contact list event
|
||||||
|
|
||||||
bool isHidden; // hidden by sending a reaction kind 7 event to this event, by the logged in user
|
bool isHidden; // hidden by sending a reaction kind 7 event to this event, by the logged in user
|
||||||
|
bool isDeleted; // deleted by kind 5 event
|
||||||
|
|
||||||
String getParent() {
|
String getParent() {
|
||||||
if( eTagsRest.isNotEmpty) {
|
if( eTagsRest.isNotEmpty) {
|
||||||
@ -207,7 +219,7 @@ class EventData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EventData(this.id, this.pubkey, this.createdAt, this.kind, this.content, this.eTagsRest, this.pTags,
|
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 = "", this.isHidden = false});
|
this.contactList, this.tags, this.newLikes, {this.isNotification = false, this.evaluatedContent = "", this.isHidden = false, this.isDeleted = false});
|
||||||
|
|
||||||
factory EventData.fromJson(dynamic json) {
|
factory EventData.fromJson(dynamic json) {
|
||||||
List<Contact> contactList = [];
|
List<Contact> contactList = [];
|
||||||
@ -242,7 +254,8 @@ class EventData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ( json['kind'] == 1 || json['kind'] == 7 || json['kind'] == 42 ) {
|
int eKind = json['kind'];
|
||||||
|
if ( eKind == 1 || eKind == 7 || eKind == 42 || eKind == 5) {
|
||||||
for( int i = 0; i < numTags; i++) {
|
for( int i = 0; i < numTags; i++) {
|
||||||
var tag = jsonTags[i];
|
var tag = jsonTags[i];
|
||||||
//stdout.write(tag);
|
//stdout.write(tag);
|
||||||
@ -359,11 +372,7 @@ class EventData {
|
|||||||
String maxN(String v) => v.length > n? v.substring(0,n) : v.substring(0, v.length);
|
String maxN(String v) => v.length > n? v.substring(0,n) : v.substring(0, v.length);
|
||||||
void printInColor(String s, String commentColor) => stdout.supportsAnsiEscapes ?stdout.write("$commentColor$s$gColorEndMarker"):stdout.write(s);
|
void printInColor(String s, String commentColor) => stdout.supportsAnsiEscapes ?stdout.write("$commentColor$s$gColorEndMarker"):stdout.write(s);
|
||||||
|
|
||||||
// TODO do it in one call
|
String strDate = getPrintableDate(createdAt);
|
||||||
final df1 = DateFormat('hh:mm a');
|
|
||||||
final df2 = DateFormat(DateFormat.ABBR_MONTH_DAY);
|
|
||||||
String strDate = df1.format(DateTime.fromMillisecondsSinceEpoch(createdAt*1000));
|
|
||||||
strDate += " ${df2.format(DateTime.fromMillisecondsSinceEpoch(createdAt*1000))}";
|
|
||||||
if( createdAt == 0) {
|
if( createdAt == 0) {
|
||||||
print("debug: createdAt == 0 for event $content");
|
print("debug: createdAt == 0 for event $content");
|
||||||
}
|
}
|
||||||
|
@ -115,6 +115,10 @@ int gDifficulty = 0;
|
|||||||
const int gNumChannelMessagesToShow = 15;
|
const int gNumChannelMessagesToShow = 15;
|
||||||
const int gMaxChannelPagesDisplayed = 50;
|
const int gMaxChannelPagesDisplayed = 50;
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// User interface messages
|
||||||
|
String gDeletedEventMessage = "This post was deleted by its original writer";
|
||||||
|
|
||||||
const String gUsage = """$exename version $version
|
const String gUsage = """$exename version $version
|
||||||
The nostr console client built using dart.
|
The nostr console client built using dart.
|
||||||
|
|
||||||
|
@ -275,7 +275,7 @@ class Store {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Set<int> typesInEventMap = {0, 1, 3, 7, 40, 42}; // 0 meta, 1 post, 3 follows list, 7 reactions
|
static const Set<int> typesInEventMap = {0, 1, 3, 5, 7, 40, 42}; // 0 meta, 1 post, 3 follows list, 7 reactions
|
||||||
|
|
||||||
static void handleChannelEvents( Map<String, ChatRoom> rooms, Map<String, Tree> tempChildEventsMap, Event ce) {
|
static void handleChannelEvents( Map<String, ChatRoom> rooms, Map<String, Tree> tempChildEventsMap, Event ce) {
|
||||||
String eId = ce.eventData.id;
|
String eId = ce.eventData.id;
|
||||||
@ -353,6 +353,8 @@ class Store {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
processDeleteEvents(tempChildEventsMap); // handle returned values perhaps later
|
||||||
|
|
||||||
// once tempChildEventsMap has been created, create connections between them so we get a tree structure from all these events.
|
// once tempChildEventsMap has been created, create connections between them so we get a tree structure from all these events.
|
||||||
List<Tree> topLevelTrees = [];// this will become the children of the main top node. These are events without parents, which are printed at top.
|
List<Tree> topLevelTrees = [];// this will become the children of the main top node. These are events without parents, which are printed at top.
|
||||||
List<String> tempWithoutParent = [];
|
List<String> tempWithoutParent = [];
|
||||||
@ -445,7 +447,7 @@ class Store {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// only kind 0, 1, 3, 7, 40, 42 events are added to map, return otherwise
|
// only kind 0, 1, 3, 5( delete), 7, 40, 42 events are added to map, return otherwise
|
||||||
if( !typesInEventMap.contains(newEvent.eventData.kind) ) {
|
if( !typesInEventMap.contains(newEvent.eventData.kind) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -863,18 +865,6 @@ class Store {
|
|||||||
return strTags;
|
return strTags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
void addChild(Event child) {
|
|
||||||
Store node;
|
|
||||||
node = Store(child, [], {}, [], false, {}, {});
|
|
||||||
children.add(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
void addChildNode(Store node) {
|
|
||||||
children.add(node);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
// for any tree node, returns its top most parent
|
// for any tree node, returns its top most parent
|
||||||
Tree getTopTree(Tree tree) {
|
Tree getTopTree(Tree tree) {
|
||||||
while( true) {
|
while( true) {
|
||||||
@ -965,6 +955,35 @@ class Store {
|
|||||||
return totalEvents;
|
return totalEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static List<String> processDeleteEvents(Map<String, Tree> tempChildEventsMap) {
|
||||||
|
List<String> deletedEventIds = [];
|
||||||
|
tempChildEventsMap.forEach((key, tree) {
|
||||||
|
EventData deleterEvent = tree.event.eventData;
|
||||||
|
if( deleterEvent.kind == 5) {
|
||||||
|
deleterEvent.tags.forEach((tag) {
|
||||||
|
if( tag.length < 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if( tag[0] == "e") {
|
||||||
|
String deletedEventId = tag[1];
|
||||||
|
// look up that event and ensure its kind 1 etc, and then mark it deleted.
|
||||||
|
Event? deletedEvent = tempChildEventsMap[deletedEventId]?.event;
|
||||||
|
if( deletedEvent != null) {
|
||||||
|
if( deletedEvent.eventData.kind == 1) {
|
||||||
|
deletedEvent.eventData.isDeleted = true;
|
||||||
|
deletedEvent.eventData.content = gDeletedEventMessage + " on ${getPrintableDate(deleterEvent.createdAt)}";
|
||||||
|
deletedEvent.eventData.evaluatedContent = "";
|
||||||
|
EventData ed = deletedEvent.eventData;
|
||||||
|
deletedEvent.originalJson = '["EVENT","none",{"id":${ed.id},"pubkey":${ed.pubkey},"createdAt":${ed.createdAt},"kind":1,"tags":[],"sig":"invalid","comment":"deleted"}]';
|
||||||
|
deletedEventIds.add(deletedEventId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return deletedEventIds;
|
||||||
|
} // end processDeleteEvents
|
||||||
} // end Store
|
} // end Store
|
||||||
|
|
||||||
void addMessageToChannel(String channelId, String messageId, Map<String, Tree> tempChildEventsMap, var chatRooms) {
|
void addMessageToChannel(String channelId, String messageId, Map<String, Tree> tempChildEventsMap, var chatRooms) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user