Skip to content

Deprecate noteId var from getNoteTags in Js-API#18624

Merged
mikehardy merged 1 commit intoankidroid:mainfrom
Haz3-jolt:Tags
Jun 25, 2025
Merged

Deprecate noteId var from getNoteTags in Js-API#18624
mikehardy merged 1 commit intoankidroid:mainfrom
Haz3-jolt:Tags

Conversation

@Haz3-jolt
Copy link
Copy Markdown
Member

Purpose / Description

  • get and set NoteTags does not need a noteId var anymore

Fixes

How Has This Been Tested?

Fixed UnitTests

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@david-allison david-allison added this to the 2.21 release milestone Jun 24, 2025
@david-allison david-allison added Needs Author Reply Waiting for a reply from the original author Queued for Cherry Pick to Stable Branch labels Jun 24, 2025
@Haz3-jolt Haz3-jolt removed the Needs Author Reply Waiting for a reply from the original author label Jun 24, 2025
@Haz3-jolt Haz3-jolt requested a review from david-allison June 24, 2025 18:42
@david-allison
Copy link
Copy Markdown
Member

david-allison commented Jun 24, 2025

It would be useful to know where the method went

And leave an extra line between the title and the first line of the message

@Haz3-jolt
Copy link
Copy Markdown
Member Author

Haz3-jolt commented Jun 24, 2025

It would be useful to know where the method went

And leave an extra line between the title and the first line of the message

would this work?
The test cases still pass, I think this would work similar to overloading the function

Index: AnkiDroid/src/main/assets/scripts/js-api.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/main/assets/scripts/js-api.js b/AnkiDroid/src/main/assets/scripts/js-api.js
--- a/AnkiDroid/src/main/assets/scripts/js-api.js	(revision 18d14c2dec2f3bb15d03ffd6ebe06c291fcd4c22)
+++ b/AnkiDroid/src/main/assets/scripts/js-api.js	(date 1750793826077)
@@ -130,6 +130,7 @@
     }
     if (method === "ankiSetNoteTags") {
         AnkiDroidJS.prototype[method] = async function (noteId, tags) {
+            console.warn("ankiSetNoteTags: The noteId parameter is deprecated and will be ignored. The method now uses the current card's note ID automatically.");
             let hasSpaces = false;
             for (let i = 0; i < tags.length; i++) {
                 tags[i] = tags[i].trim();
@@ -147,8 +148,28 @@
         };
         return;
     }
+    if (method === "ankiSetNoteTags") {
+            AnkiDroidJS.prototype[method] = async function (tags) {
+                let hasSpaces = false;
+                for (let i = 0; i < tags.length; i++) {
+                    tags[i] = tags[i].trim();
+                    if (tags[i].includes(" ") || tags[i].includes("\u3000")) {
+                        tags[i] = tags[i].replace(" ", "_").replace("\u3000", "_");
+                        hasSpaces = true;
+                    }
+                }
+                if (hasSpaces) {
+                    console.warn("Spaces in tags have been converted to underscores");
+                }
+                const endpoint = jsApiList[method];
+                const data = JSON.stringify({ tags });
+                return await this.handleRequest(endpoint, data);
+            };
+            return;
+        }
     if (method === "ankiGetNoteTags") {
         AnkiDroidJS.prototype[method] = async function (noteId) {
+            console.warn("ankiGetNoteTags: The noteId parameter is deprecated and will be ignored. The method now uses the current card's note ID automatically.");
             const endpoint = jsApiList[method];
             const data = JSON.stringify({ noteId });
             return await this.handleRequest(endpoint, data);

I think it might be better to do it this way, so as to not directly break anyone's decks, it follows the same console.warn pattern of ankiAddTagToNote which was also deprecated.

@david-allison
Copy link
Copy Markdown
Member

It's alpha functionality which we're removing. No need for complexity.

The only change should be in the commit message, making it immediately clear to a reader whether the method was removed, or just refactored to less code

Now consistent with other methods: the currently selected note is used

* Stop special-casing `ankiGetNoteTags` as no params are needed
* Adjust Object.keys usage accordingly
* Move jsonObjectOf to JsonUtils.kt

Issue 17716

Co-authored-by: David Allison <62114487+david-allison@users.noreply.github.com>
@david-allison david-allison added Needs Second Approval Has one approval, one more approval to merge and removed Needs Review labels Jun 25, 2025
Copy link
Copy Markdown
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed up the commit message to reduce the back/forth required.

As I force pushed, PR changes are on me to resolve

@Haz3-jolt
Copy link
Copy Markdown
Member Author

I fixed up the commit message to reduce the back/forth required.

As I force pushed, PR changes are on me to resolve

Didn't know commit messages can be that long.
Learned something new 😁

@david-allison
Copy link
Copy Markdown
Member

No length limit, have some 'long' ones:

Copy link
Copy Markdown
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks

@mikehardy mikehardy added this pull request to the merge queue Jun 25, 2025
@mikehardy mikehardy added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Second Approval Has one approval, one more approval to merge labels Jun 25, 2025
Merged via the queue into ankidroid:main with commit 49cdb8f Jun 25, 2025
9 checks passed
@github-actions github-actions bot removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FR: JS API function to remove a specific tag

3 participants