Skip to content

Commit

Permalink
added t tag to messages with #tags
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalxl committed Dec 5, 2022
1 parent 4f8a138 commit 6d5cbde
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 45 deletions.
3 changes: 1 addition & 2 deletions lib/console_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,13 @@ String mySign(String privateKey, String msg) {
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)
* 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
*/
Future<void> sendReplyPostLike(Store node, String replyToId, String replyKind, String content) async {
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)
print("${gWarningColor}The given target id was not found and/or is not a valid id. Not sending the event.$gColorEndMarker");
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:logging/logging.dart';

// name of executable
const String exename = "nostr_console";
const String version = "0.2.3-beta";
const String version = "0.2.4-beta";

int gDebug = 0;
int gSpecificDebug = 0;
Expand Down
35 changes: 16 additions & 19 deletions lib/tree_ds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
print("not writing dummy event pubkey");
continue; // dont write dummy events
Expand Down Expand Up @@ -1984,25 +1969,37 @@ class Store {
* Also adds 'client' tag with application name.
* @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

print("extraTags = $extraTags");
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( otherTags.length > 0)
otherTags += ",";
otherTags += '["location","$gUserLocation"]';
}

print("otherTags = $otherTags");
if( replyToId.isEmpty) {
return otherTags.length >0 ? 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
// and only the event that's latest is considered as the intended recipient ( this is not perfect, but easy UI)
Expand Down
16 changes: 16 additions & 0 deletions lib/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
String str;
int count;
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ homepage: https://github.com/vishalxl/nostr_console

# Release 0.2.3-beta
# crated location and t rooms
# t tags added for all tags

environment:
sdk: '>=2.17.3 <3.0.0'
Expand Down
32 changes: 9 additions & 23 deletions test/nostr_console_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,6 @@ String expectedResult =
a""";

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);
});

Expand Down Expand Up @@ -195,19 +188,6 @@ String expectedResult =
words""";

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);
});

Expand Down Expand Up @@ -261,13 +241,11 @@ String expectedResult =
initialEvents.forEach((element) { element.eventData.kind == 1? numFilePosts++: numFilePosts;});
//print("read $numFilePosts posts from file $gEventsFilename");
expect(numFilePosts, 3486, reason:'Verify right number of kind 1 posts');


Store node = await getTree(initialEvents);

expect(0, node.getNumDirectRooms(), reason:'verify correct number of direct chat rooms created');


int numKind4xChannels = 0;
node.channels.forEach((channel) => channel.roomType == enumRoomType.kind40? numKind4xChannels++:1);

Expand All @@ -277,7 +255,6 @@ String expectedResult =
int numLocationTagChannels = 0;
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(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');
Expand Down Expand Up @@ -308,7 +285,16 @@ String expectedResult =
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 ;
} // end main



0 comments on commit 6d5cbde

Please sign in to comment.