added t tag to messages with #tags

This commit is contained in:
Vishal
2022-12-05 11:57:34 +05:30
parent 4f8a138fd0
commit 6d5cbde5f4
6 changed files with 44 additions and 45 deletions

View File

@@ -49,14 +49,13 @@ String mySign(String privateKey, String msg) {
return sign(privateKey, msg, randomSeed); return sign(privateKey, msg, randomSeed);
} }
/* @function sendReplyPostLike Used to send Reply, Post and Like ( event 1 for reply and post, and event 7 for like/reaction) /* @function sendReplyPostLike Used to send Reply, Post and Like ( event 1 for reply and post, and event 7 for like/reaction)
* If replyToId is blank, then it does not reference any e/p tags, and thus becomes a top post * If replyToId is blank, then it does not reference any e/p tags, and thus becomes a top post
* otherwise e and p tags are found for the given event being replied to, if that event data is available * otherwise e and p tags are found for the given event being replied to, if that event data is available
*/ */
Future<void> sendReplyPostLike(Store node, String replyToId, String replyKind, String content) async { Future<void> sendReplyPostLike(Store node, String replyToId, String replyKind, String content) async {
content = addEscapeChars(content); content = addEscapeChars(content);
String strTags = node.getTagStr(replyToId, exename, true); String strTags = node.getTagStr(replyToId, exename, true, getTagsFromContent(content));
if( replyToId.isNotEmpty && strTags == "") { // this returns empty only when the given replyto ID is non-empty, but its not found ( nor is it 64 bytes) if( replyToId.isNotEmpty && strTags == "") { // this returns empty only when the given replyto ID is non-empty, but its not found ( nor is it 64 bytes)
print("${gWarningColor}The given target id was not found and/or is not a valid id. Not sending the event.$gColorEndMarker"); print("${gWarningColor}The given target id was not found and/or is not a valid id. Not sending the event.$gColorEndMarker");
return; return;

View File

@@ -3,7 +3,7 @@ import 'package:logging/logging.dart';
// name of executable // name of executable
const String exename = "nostr_console"; const String exename = "nostr_console";
const String version = "0.2.3-beta"; const String version = "0.2.4-beta";
int gDebug = 0; int gDebug = 0;
int gSpecificDebug = 0; int gSpecificDebug = 0;

View File

@@ -1931,21 +1931,6 @@ class Store {
} }
} }
/*
// only write if its not too old ( except in case of user logged in)
if( gDontWriteOldEvents) {
if( tree.event.eventData.createdAt < getSecondsDaysAgo(gDontSaveBeforeDays) ) {
if( tree.event.eventData.pubkey != userPublicKey ) {
if( !(tree.event.eventData.kind == 4 && isValidDirectMessage(tree.event.eventData)))
if( !tree.event.eventData.pTags.contains(userPublicKey))
if( ![0, 3, 40, 41, 140, 141].contains(tree.event.eventData.kind))
continue;
}
}
}
*/
if( gDummyAccountPubkey == tree.event.eventData.pubkey) { if( gDummyAccountPubkey == tree.event.eventData.pubkey) {
print("not writing dummy event pubkey"); print("not writing dummy event pubkey");
continue; // dont write dummy events continue; // dont write dummy events
@@ -1984,12 +1969,24 @@ class Store {
* Also adds 'client' tag with application name. * Also adds 'client' tag with application name.
* @parameter replyToId First few letters of an event id for which reply is being made * @parameter replyToId First few letters of an event id for which reply is being made
*/ */
String getTagStr(String replyToId, String clientName, [bool addAllP = false]) { String getTagStr(String replyToId, String clientName, [bool addAllP = false, Set<String>? extraTags = null]) {
clientName = (clientName == "")? "nostr_console": clientName; // in case its empty clientName = (clientName == "")? "nostr_console": clientName; // in case its empty
print("extraTags = $extraTags");
String otherTags = ""; String otherTags = "";
if( gWhetherToSendClientTag)
otherTags = '["client","$clientName"]'; if( extraTags != null)
for( String extraTag in extraTags) {
if( otherTags.length > 0)
otherTags += ",";
otherTags += '["t","$extraTag"]';
}
if( gWhetherToSendClientTag) {
if( otherTags.length > 0)
otherTags += ",";
otherTags += '["client","$clientName"]';
}
if( gUserLocation != "") { if( gUserLocation != "") {
if( otherTags.length > 0) if( otherTags.length > 0)
@@ -1997,13 +1994,13 @@ class Store {
otherTags += '["location","$gUserLocation"]'; otherTags += '["location","$gUserLocation"]';
} }
print("otherTags = $otherTags");
if( replyToId.isEmpty) { if( replyToId.isEmpty) {
return otherTags.length >0 ? otherTags: '[]'; return otherTags.length >0 ? otherTags: '[]';
} }
String strTags = otherTags ; String strTags = otherTags ;
// find the latest event with the given id; needs to be done because we allow user to refer to events with as few as 3 or so first letters // find the latest event with the given id; needs to be done because we allow user to refer to events with as few as 3 or so first letters
// and only the event that's latest is considered as the intended recipient ( this is not perfect, but easy UI) // and only the event that's latest is considered as the intended recipient ( this is not perfect, but easy UI)
int latestEventTime = 0; int latestEventTime = 0;

View File

@@ -19,6 +19,22 @@ String getPostKindFrom(enumRoomType eType) {
} }
Set<String>? getTagsFromContent(String content) {
Set<String>? tags = null;
String regexp1 = '(#[a-zA-Z0-9_\-]+ )|(#[a-zA-Z0-9_\-]+)\$';
RegExp httpRegExp = RegExp(regexp1);
for( var match in httpRegExp.allMatches(content) ) {
if( tags == null)
tags = {};
tags.add( content.substring(match.start + 1, match.end) );
}
return tags;
}
class HistogramEntry { class HistogramEntry {
String str; String str;
int count; int count;

View File

@@ -5,6 +5,7 @@ homepage: https://github.com/vishalxl/nostr_console
# Release 0.2.3-beta # Release 0.2.3-beta
# crated location and t rooms # crated location and t rooms
# t tags added for all tags
environment: environment:
sdk: '>=2.17.3 <3.0.0' sdk: '>=2.17.3 <3.0.0'

View File

@@ -161,13 +161,6 @@ String expectedResult =
a"""; a""";
String res = makeParagraphAtDepth(paragraph, 30); String res = makeParagraphAtDepth(paragraph, 30);
/* stdout.write(getNumSpaces(30));
stdout.write("\n");
stdout.write(getNumDashes(30));
//stdout.write(getNumSpaces(30)); */
//stdout.write(res);
//return res == expectedResult;;
expect( res, expectedResult); expect( res, expectedResult);
}); });
@@ -195,19 +188,6 @@ String expectedResult =
words"""; words""";
String res = makeParagraphAtDepth(paragraph, 30); String res = makeParagraphAtDepth(paragraph, 30);
/*stdout.write(getNumSpaces(30));
stdout.write("\n");
stdout.write(getNumDashes(30));
stdout.write(getNumSpaces(30));
stdout.write(res); */
/*
print("paragraph length = ${paragraph.length} res length = ${res.length}");
print("paragraph last: ${paragraph.substring(paragraph.length - 4, paragraph.length)}");
print( res.substring(res.length - 100, res.length).codeUnits);
//res = res.trim();
print("res trimmed len = ${res.length}");
*/
expect( res, expectedResult); expect( res, expectedResult);
}); });
@@ -262,12 +242,10 @@ String expectedResult =
//print("read $numFilePosts posts from file $gEventsFilename"); //print("read $numFilePosts posts from file $gEventsFilename");
expect(numFilePosts, 3486, reason:'Verify right number of kind 1 posts'); expect(numFilePosts, 3486, reason:'Verify right number of kind 1 posts');
Store node = await getTree(initialEvents); Store node = await getTree(initialEvents);
expect(0, node.getNumDirectRooms(), reason:'verify correct number of direct chat rooms created'); expect(0, node.getNumDirectRooms(), reason:'verify correct number of direct chat rooms created');
int numKind4xChannels = 0; int numKind4xChannels = 0;
node.channels.forEach((channel) => channel.roomType == enumRoomType.kind40? numKind4xChannels++:1); node.channels.forEach((channel) => channel.roomType == enumRoomType.kind40? numKind4xChannels++:1);
@@ -277,7 +255,6 @@ String expectedResult =
int numLocationTagChannels = 0; int numLocationTagChannels = 0;
node.channels.forEach((channel) => channel.roomType == enumRoomType.RoomLocationTag? numLocationTagChannels++:1); node.channels.forEach((channel) => channel.roomType == enumRoomType.RoomLocationTag? numLocationTagChannels++:1);
expect(78, numKind4xChannels, reason: 'verify correct number of public channels created of kind 4x'); expect(78, numKind4xChannels, reason: 'verify correct number of public channels created of kind 4x');
expect(41, numTTagChannels, reason: 'verify correct number of public channels created of T tag type'); expect(41, numTTagChannels, reason: 'verify correct number of public channels created of T tag type');
expect(2, numLocationTagChannels, reason: 'verify correct number of public channels created of Location tag'); expect(2, numLocationTagChannels, reason: 'verify correct number of public channels created of Location tag');
@@ -308,7 +285,16 @@ String expectedResult =
expect (qrCodeResult1, getQrCodeAsString(profilePubkey1), reason: "testing qr code function"); expect (qrCodeResult1, getQrCodeAsString(profilePubkey1), reason: "testing qr code function");
}); });
test('utils_fns', () async {
String content1 = '#bitcoin #chatgpt #u-s-a #u_s_a #1947 #1800';
Set<String>? tags = getTagsFromContent(content1);
//print(tags);
expect(tags?.length, 6);
});
return ; return ;
} // end main } // end main