From 063e2ff2653bb07a80183369fd72a74658b61450 Mon Sep 17 00:00:00 2001 From: noumantahir Date: Wed, 18 Sep 2024 18:25:55 +0500 Subject: [PATCH 1/5] added support for extracting hash tags --- android/app/src/main/assets/index.html | 17 ++++++++++++++++- ios/Runner/public/index.html | 23 ++++++++++++++++++----- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/android/app/src/main/assets/index.html b/android/app/src/main/assets/index.html index 4e479b6..d23498f 100644 --- a/android/app/src/main/assets/index.html +++ b/android/app/src/main/assets/index.html @@ -223,6 +223,20 @@ // .toLowerCase(); // permlink2 = `re-${username}-${permlink2}`; // console.log(permlink2); + + + + // Regex pattern for hashtags + const pattern = /#(\w+)/g; + // Find all hashtags and discard the # character + const hashtags = []; + let match; + + while ((match = pattern.exec(comment)) !== null) { + hashtags.push(match[1]); // match[1] contains the hashtag without the # + } + + let op = [ "comment", { @@ -238,7 +252,8 @@ "waves", "ecency", "mobile", - "thread" + "thread", + ...hashtags ], app: "ecency-waves", format: "markdown+html", diff --git a/ios/Runner/public/index.html b/ios/Runner/public/index.html index 89fccf0..4b424e0 100644 --- a/ios/Runner/public/index.html +++ b/ios/Runner/public/index.html @@ -202,6 +202,18 @@ // .toLowerCase(); // permlink2 = `re-${username}-${permlink2}`; // console.log(permlink2); + + // Regex pattern for hashtags + const pattern = /#(\w+)/g; + // Find all hashtags and discard the # character + const hashtags = []; + let match; + + while ((match = pattern.exec(comment)) !== null) { + hashtags.push(match[1]); // match[1] contains the hashtag without the # + } + + let op = [ "comment", { @@ -213,11 +225,12 @@ body: description, json_metadata: JSON.stringify({ tags: [ - "hive-125125", - "waves", - "ecency", - "mobile", - "thread" + "hive-125125", + "waves", + "ecency", + "mobile", + "thread", + ...hashTags ], app: "ecency-waves", format: "markdown+html", From c346079d00b644b7ed405447ecd13aa8325ee3f0 Mon Sep 17 00:00:00 2001 From: noumantahir Date: Wed, 18 Sep 2024 18:26:12 +0500 Subject: [PATCH 2/5] syntax update --- .../thread_json_meta_data/thread_json_meta_data.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/features/threads/models/thread_feeds/thread_json_meta_data/thread_json_meta_data.dart b/lib/features/threads/models/thread_feeds/thread_json_meta_data/thread_json_meta_data.dart index f51b8d7..ea4aa97 100644 --- a/lib/features/threads/models/thread_feeds/thread_json_meta_data/thread_json_meta_data.dart +++ b/lib/features/threads/models/thread_feeds/thread_json_meta_data/thread_json_meta_data.dart @@ -131,7 +131,7 @@ class ThreadJsonMetadata { 'vote_change':voteChange, 'hide_votes':hideVotes, 'ui_hide_res_until_voted':uiHideResUntilVoted, - 'preferred_interpretation':preferredInterpretation!.value + 'preferred_interpretation':preferredInterpretation?.value }; } From cc0f4464d4b5f705f5561e5ecb1208261188ae66 Mon Sep 17 00:00:00 2001 From: noumantahir Date: Wed, 18 Sep 2024 19:35:34 +0500 Subject: [PATCH 3/5] using extracted comment string to read hash tags --- android/app/src/main/assets/index.html | 2 +- ios/Runner/public/index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/assets/index.html b/android/app/src/main/assets/index.html index d23498f..e218c3a 100644 --- a/android/app/src/main/assets/index.html +++ b/android/app/src/main/assets/index.html @@ -232,7 +232,7 @@ const hashtags = []; let match; - while ((match = pattern.exec(comment)) !== null) { + while ((match = pattern.exec(description)) !== null) { hashtags.push(match[1]); // match[1] contains the hashtag without the # } diff --git a/ios/Runner/public/index.html b/ios/Runner/public/index.html index 4b424e0..01979ea 100644 --- a/ios/Runner/public/index.html +++ b/ios/Runner/public/index.html @@ -209,7 +209,7 @@ const hashtags = []; let match; - while ((match = pattern.exec(comment)) !== null) { + while ((match = pattern.exec(description)) !== null) { hashtags.push(match[1]); // match[1] contains the hashtag without the # } From 8c49d45c30a52d7d978cd53d4234f645cfcef168 Mon Sep 17 00:00:00 2001 From: noumantahir Date: Wed, 18 Sep 2024 19:36:02 +0500 Subject: [PATCH 4/5] version bump --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 2401c2f..a70108f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.0+23 +version: 1.0.0+24 environment: sdk: '>=3.3.2 <4.0.0' From 4c1080798b87cece6f50541b48e2419ba5119926 Mon Sep 17 00:00:00 2001 From: noumantahir Date: Wed, 18 Sep 2024 20:44:49 +0500 Subject: [PATCH 5/5] passing extracted tags array from dart code --- android/app/src/main/assets/index.html | 26 +++++++------------ .../kotlin/com/ecency/waves/MainActivity.kt | 3 ++- ios/Runner/AppBridge.swift | 4 ++- ios/Runner/public/index.html | 23 +++------------- .../services/data_service/api_service.dart | 3 ++- .../services/data_service/mobile_service.dart | 2 ++ lib/core/services/data_service/service.dart | 1 + .../services/data_service/web_service.dart | 1 + lib/core/utilities/act.dart | 23 ++++++++++++++++ .../sign_transaction_hive_controller.dart | 2 ++ ...gn_transaction_posting_key_controller.dart | 2 ++ .../threads/repository/thread_repository.dart | 3 ++- 12 files changed, 53 insertions(+), 40 deletions(-) diff --git a/android/app/src/main/assets/index.html b/android/app/src/main/assets/index.html index e218c3a..e8dd4a3 100644 --- a/android/app/src/main/assets/index.html +++ b/android/app/src/main/assets/index.html @@ -209,6 +209,7 @@ parentPermlink, permlink, comment, + tags, postingKey, token, authKey @@ -226,15 +227,15 @@ - // Regex pattern for hashtags - const pattern = /#(\w+)/g; - // Find all hashtags and discard the # character - const hashtags = []; - let match; + // // Regex pattern for hashtags + // const pattern = /#(\w+)/g; + // // Find all hashtags and discard the # character + // const hashtags = []; + // let match; - while ((match = pattern.exec(description)) !== null) { - hashtags.push(match[1]); // match[1] contains the hashtag without the # - } + // while ((match = pattern.exec(description)) !== null) { + // hashtags.push(match[1]); // match[1] contains the hashtag without the # + // } let op = [ @@ -247,14 +248,7 @@ title: "", body: description, json_metadata: JSON.stringify({ - tags: [ - "hive-125125", - "waves", - "ecency", - "mobile", - "thread", - ...hashtags - ], + tags:JSON.parse(tags), app: "ecency-waves", format: "markdown+html", }), diff --git a/android/app/src/main/kotlin/com/ecency/waves/MainActivity.kt b/android/app/src/main/kotlin/com/ecency/waves/MainActivity.kt index e52d844..fd33eea 100644 --- a/android/app/src/main/kotlin/com/ecency/waves/MainActivity.kt +++ b/android/app/src/main/kotlin/com/ecency/waves/MainActivity.kt @@ -46,6 +46,7 @@ class MainActivity: FlutterActivity() { val weight = call.argument("weight") val pollId = call.argument("pollId") val choices = call.argument("choices") + val tags = call.argument("tags") if (id == null) { result.error( @@ -91,7 +92,7 @@ class MainActivity: FlutterActivity() { && parentPermlink != null && permlink != null && comment != null && postingKey != null && token != null && authKey != null ) { webView?.evaluateJavascript( - "commentOnContent('$id','$username', '$author', '$parentPermlink', '$permlink', '$comment', '$postingKey', '$token', '$authKey');", + "commentOnContent('$id','$username', '$author', '$parentPermlink', '$permlink', '$comment', '$tags', '$postingKey', '$token', '$authKey');", null ) } else if (call.method == "voteContent" && username != null && author != null diff --git a/ios/Runner/AppBridge.swift b/ios/Runner/AppBridge.swift index 00df358..4129203 100644 --- a/ios/Runner/AppBridge.swift +++ b/ios/Runner/AppBridge.swift @@ -119,16 +119,18 @@ class AppBridge: NSObject { let parentPermlink = arguments ["parentPermlink"] as? String, let permlink = arguments ["permlink"] as? String, let comment = arguments ["comment"] as? String, + let tags = arguments ["tags"] as? [String], let postingKey = arguments ["postingKey"] as? String, let token = arguments ["token"] as? String, let authKey = arguments ["authKey"] as? String + else { debugPrint("username, author, parentPermlink, permlink, comment, postingKey, token, authKey - are note set") return result(FlutterMethodNotImplemented) } webVC.runThisJS( id: id, - jsCode: "commentOnContent('\(id)','\(username)', '\(author)', '\(parentPermlink)', '\(permlink)', '\(comment)', '\(postingKey)', '\(token)', '\(authKey)');" + jsCode: "commentOnContent('\(id)','\(username)', '\(author)', '\(parentPermlink)', '\(permlink)', '\(comment)', '\(tags)', '\(postingKey)', '\(token)', '\(authKey)');" ) { text in result(text) } case "voteContent": guard diff --git a/ios/Runner/public/index.html b/ios/Runner/public/index.html index 01979ea..699a40e 100644 --- a/ios/Runner/public/index.html +++ b/ios/Runner/public/index.html @@ -188,6 +188,7 @@ parentPermlink, permlink, comment, + tags, postingKey, token, authKey @@ -201,18 +202,7 @@ // .replace(/[^a-zA-Z0-9]+/g, "") // .toLowerCase(); // permlink2 = `re-${username}-${permlink2}`; - // console.log(permlink2); - - // Regex pattern for hashtags - const pattern = /#(\w+)/g; - // Find all hashtags and discard the # character - const hashtags = []; - let match; - - while ((match = pattern.exec(description)) !== null) { - hashtags.push(match[1]); // match[1] contains the hashtag without the # - } - + // console.log(permlink2) let op = [ "comment", @@ -224,14 +214,7 @@ title: "", body: description, json_metadata: JSON.stringify({ - tags: [ - "hive-125125", - "waves", - "ecency", - "mobile", - "thread", - ...hashTags - ], + tags: JSON.parase(tags), app: "ecency-waves", format: "markdown+html", }), diff --git a/lib/core/services/data_service/api_service.dart b/lib/core/services/data_service/api_service.dart index 419e09e..21f892b 100644 --- a/lib/core/services/data_service/api_service.dart +++ b/lib/core/services/data_service/api_service.dart @@ -167,13 +167,14 @@ class ApiService { String parentPermlink, String permlink, String comment, + List tags, String? postingKey, String? authKey, String? token, ) async { try { String jsonString = await commentOnContentFromPlatform(username, author, - parentPermlink, permlink, comment, postingKey, authKey, token); + parentPermlink, permlink, comment, tags, postingKey, authKey, token); ActionSingleDataResponse response = ActionSingleDataResponse.fromJsonString(jsonString, null, ignoreFromJson: true); diff --git a/lib/core/services/data_service/mobile_service.dart b/lib/core/services/data_service/mobile_service.dart index d6640da..80b7ec9 100644 --- a/lib/core/services/data_service/mobile_service.dart +++ b/lib/core/services/data_service/mobile_service.dart @@ -54,6 +54,7 @@ Future commentOnContentFromPlatform( String parentPermlink, String permlink, String comment, + List tags, String? postingKey, String? authKey, String? token, @@ -66,6 +67,7 @@ Future commentOnContentFromPlatform( 'parentPermlink': parentPermlink, 'permlink': permlink, 'comment': base64.encode(utf8.encode(comment)), + 'tags': tags, 'postingKey': postingKey ?? '', 'token': token ?? '', 'authKey': authKey ?? '', diff --git a/lib/core/services/data_service/service.dart b/lib/core/services/data_service/service.dart index 3ac2612..5d05c2b 100644 --- a/lib/core/services/data_service/service.dart +++ b/lib/core/services/data_service/service.dart @@ -24,6 +24,7 @@ Future commentOnContentFromPlatform( String parentPermlink, String permlink, String comment, + List tags, String? postingKey, String? authKey, String? token, diff --git a/lib/core/services/data_service/web_service.dart b/lib/core/services/data_service/web_service.dart index 4c0ae52..1faa0d2 100644 --- a/lib/core/services/data_service/web_service.dart +++ b/lib/core/services/data_service/web_service.dart @@ -60,6 +60,7 @@ Future commentOnContentFromPlatform( String parentPermlink, String permlink, String comment, + List tags, String? postingKey, String? authKey, String? token, diff --git a/lib/core/utilities/act.dart b/lib/core/utilities/act.dart index c673b21..97a7fe6 100644 --- a/lib/core/utilities/act.dart +++ b/lib/core/utilities/act.dart @@ -35,6 +35,29 @@ class Act { return data?.text; } + static List compileTags(String comment) { + // Regex pattern for hashtags + RegExp pattern = RegExp(r'#(\w+)'); + + // Find all hashtags and discard the # character + List hashtags = []; + Iterable matches = pattern.allMatches(comment); + + for (var match in matches) { + hashtags + .add(match.group(1)!); // group(1) contains the hashtag without the # + } + + return [ + "hive-125125", + "waves", + "ecency", + "mobile", + "thread", + ...hashtags + ]; + } + static String generatePermlink(String username) { final t = DateTime.now(); final timeFormat = '${t.year}' diff --git a/lib/features/threads/presentation/comments/add_comment/controller/sign_transaction_hive_controller.dart b/lib/features/threads/presentation/comments/add_comment/controller/sign_transaction_hive_controller.dart index 9e5cafa..7069f50 100644 --- a/lib/features/threads/presentation/comments/add_comment/controller/sign_transaction_hive_controller.dart +++ b/lib/features/threads/presentation/comments/add_comment/controller/sign_transaction_hive_controller.dart @@ -125,12 +125,14 @@ class SignTransactionHiveController extends HiveTransactionController { switch (transactionType) { case SignTransactionType.comment: _generatedPermlink = Act.generatePermlink(authData.accountName); + List tags = Act.compileTags(comment!); return _threadRepository.commentOnContent( authData.accountName, author, permlink!, //parentPermlink _generatedPermlink!, Act.commentWithImages(comment!, imageLinks!), + tags, null, authData.auth.authKey, authData.auth.token); diff --git a/lib/features/threads/presentation/comments/add_comment/controller/sign_transaction_posting_key_controller.dart b/lib/features/threads/presentation/comments/add_comment/controller/sign_transaction_posting_key_controller.dart index f335d0d..ec4f738 100644 --- a/lib/features/threads/presentation/comments/add_comment/controller/sign_transaction_posting_key_controller.dart +++ b/lib/features/threads/presentation/comments/add_comment/controller/sign_transaction_posting_key_controller.dart @@ -22,6 +22,7 @@ class SignTransactionPostingKeyController { }) async { String generatedPermlink = Act.generatePermlink(authData.accountName); String commentWithImages = Act.commentWithImages(comment, imageLinks); + List tags = Act.compileTags(comment); ActionSingleDataResponse commentResponse = await _threadRepository.commentOnContent( authData.accountName, @@ -29,6 +30,7 @@ class SignTransactionPostingKeyController { parentPermlink, generatedPermlink, commentWithImages, + tags, authData.auth.postingKey, null, null); diff --git a/lib/features/threads/repository/thread_repository.dart b/lib/features/threads/repository/thread_repository.dart index 1ed2114..9b5073b 100644 --- a/lib/features/threads/repository/thread_repository.dart +++ b/lib/features/threads/repository/thread_repository.dart @@ -40,12 +40,13 @@ class ThreadRepository { String parentPermlink, String permlink, String comment, + List tags, String? postingKey, String? authKey, String? token, ) async { return await _apiService.commentOnContent(username, author, parentPermlink, - permlink, comment, postingKey, authKey, token); + permlink, comment, tags, postingKey, authKey, token); } Future> votecontent(