mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-04-24 23:40:25 +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();
|
||||
}
|
||||
|
||||
// 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 {
|
||||
String id;
|
||||
String pubkey;
|
||||
@ -195,9 +204,12 @@ class EventData {
|
||||
String evaluatedContent; // content which has mentions expanded, and which has been translated
|
||||
Set<String> newLikes; //
|
||||
|
||||
|
||||
|
||||
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 isDeleted; // deleted by kind 5 event
|
||||
|
||||
String getParent() {
|
||||
if( eTagsRest.isNotEmpty) {
|
||||
@ -207,7 +219,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 = "", 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) {
|
||||
List<Contact> contactList = [];
|
||||
@ -242,7 +254,8 @@ class EventData {
|
||||
}
|
||||
}
|
||||
} 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++) {
|
||||
var tag = jsonTags[i];
|
||||
//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);
|
||||
void printInColor(String s, String commentColor) => stdout.supportsAnsiEscapes ?stdout.write("$commentColor$s$gColorEndMarker"):stdout.write(s);
|
||||
|
||||
// TODO do it in one call
|
||||
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))}";
|
||||
String strDate = getPrintableDate(createdAt);
|
||||
if( createdAt == 0) {
|
||||
print("debug: createdAt == 0 for event $content");
|
||||
}
|
||||
|
@ -115,6 +115,10 @@ int gDifficulty = 0;
|
||||
const int gNumChannelMessagesToShow = 15;
|
||||
const int gMaxChannelPagesDisplayed = 50;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// User interface messages
|
||||
String gDeletedEventMessage = "This post was deleted by its original writer";
|
||||
|
||||
const String gUsage = """$exename version $version
|
||||
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) {
|
||||
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.
|
||||
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 = [];
|
||||
@ -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) ) {
|
||||
return;
|
||||
}
|
||||
@ -863,18 +865,6 @@ class Store {
|
||||
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
|
||||
Tree getTopTree(Tree tree) {
|
||||
while( true) {
|
||||
@ -965,6 +955,35 @@ class Store {
|
||||
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
|
||||
|
||||
void addMessageToChannel(String channelId, String messageId, Map<String, Tree> tempChildEventsMap, var chatRooms) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user