Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions AnkiDroid/src/main/assets/scripts/js-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Object.keys(jsApiList).forEach(method => {
return;
}
if (method === "ankiSetNoteTags") {
AnkiDroidJS.prototype[method] = async function (noteId, tags) {
AnkiDroidJS.prototype[method] = async function (tags) {
let hasSpaces = false;
for (let i = 0; i < tags.length; i++) {
tags[i] = tags[i].trim();
Expand All @@ -142,15 +142,7 @@ Object.keys(jsApiList).forEach(method => {
console.warn("Spaces in tags have been converted to underscores");
}
const endpoint = jsApiList[method];
const data = JSON.stringify({ noteId, tags });
return await this.handleRequest(endpoint, data);
};
return;
}
if (method === "ankiGetNoteTags") {
Comment thread
Haz3-jolt marked this conversation as resolved.
AnkiDroidJS.prototype[method] = async function (noteId) {
const endpoint = jsApiList[method];
const data = JSON.stringify({ noteId });
const data = JSON.stringify({ tags });
return await this.handleRequest(endpoint, data);
};
return;
Expand Down
5 changes: 2 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidJsAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ open class AnkiDroidJsAPI(

"setNoteTags" -> {
val jsonObject = JSONObject(apiParams)
val noteId = jsonObject.getLong("noteId")
val noteId = currentCard.nid
val tags = jsonObject.getJSONArray("tags")
withCol {
fun Note.setTagsFromList(tagList: List<String>) {
Expand All @@ -403,8 +403,7 @@ open class AnkiDroidJsAPI(
}

"getNoteTags" -> {
val jsonObject = JSONObject(apiParams)
val noteId = jsonObject.getLong("noteId")
val noteId = currentCard.nid
val noteTags =
withCol {
getNote(noteId).tags
Expand Down
18 changes: 1 addition & 17 deletions AnkiDroid/src/test/java/com/ichi2/anki/AnkiDroidJsAPITest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ class AnkiDroidJsAPITest : RobolectricTest() {

// test get tags for note
val expectedTags = n.tags
val response = getDataFromRequest("getNoteTags", jsapi, jsonObjectOf("noteId" to n.id))
val response = getDataFromRequest("getNoteTags", jsapi)
val jsonResponse = JSONObject(response)
val actualTags = JSONArray(jsonResponse.getString("value"))

Expand Down Expand Up @@ -471,21 +471,5 @@ class AnkiDroidJsAPITest : RobolectricTest() {
jsAPI
.handleJsApiRequest(methodName, jsApiContract(apiData), false)
.decodeToString()

suspend fun getDataFromRequest(
methodName: String,
jsAPI: AnkiDroidJsAPI,
apiData: JSONObject,
): String =
jsAPI
.handleJsApiRequest(methodName, jsApiContract(apiData.toString()), false)
.decodeToString()
}
}

private fun jsonObjectOf(vararg pairs: Pair<String, Any>): JSONObject =
JSONObject().apply {
for ((key, value) in pairs) {
put(key, value)
}
}
7 changes: 7 additions & 0 deletions AnkiDroid/src/test/java/com/ichi2/testutils/JsonUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,10 @@ class IsJsonHolderEqual(
}

fun isJsonHolderEqual(expectedValue: String) = IsJsonHolderEqual(JSONObject(expectedValue))

private fun jsonObjectOf(vararg pairs: Pair<String, Any>): JSONObject =
JSONObject().apply {
for ((key, value) in pairs) {
put(key, value)
}
}