File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -129,7 +129,7 @@ Object.keys(jsApiList).forEach(method => {
129129 return ;
130130 }
131131 if ( method === "ankiSetNoteTags" ) {
132- AnkiDroidJS . prototype [ method ] = async function ( noteId , tags ) {
132+ AnkiDroidJS . prototype [ method ] = async function ( tags ) {
133133 let hasSpaces = false ;
134134 for ( let i = 0 ; i < tags . length ; i ++ ) {
135135 tags [ i ] = tags [ i ] . trim ( ) ;
@@ -142,15 +142,7 @@ Object.keys(jsApiList).forEach(method => {
142142 console . warn ( "Spaces in tags have been converted to underscores" ) ;
143143 }
144144 const endpoint = jsApiList [ method ] ;
145- const data = JSON . stringify ( { noteId, tags } ) ;
146- return await this . handleRequest ( endpoint , data ) ;
147- } ;
148- return ;
149- }
150- if ( method === "ankiGetNoteTags" ) {
151- AnkiDroidJS . prototype [ method ] = async function ( noteId ) {
152- const endpoint = jsApiList [ method ] ;
153- const data = JSON . stringify ( { noteId } ) ;
145+ const data = JSON . stringify ( { tags } ) ;
154146 return await this . handleRequest ( endpoint , data ) ;
155147 } ;
156148 return ;
Original file line number Diff line number Diff line change @@ -380,7 +380,7 @@ open class AnkiDroidJsAPI(
380380
381381 " setNoteTags" -> {
382382 val jsonObject = JSONObject (apiParams)
383- val noteId = jsonObject.getLong( " noteId " )
383+ val noteId = currentCard.nid
384384 val tags = jsonObject.getJSONArray(" tags" )
385385 withCol {
386386 fun Note.setTagsFromList (tagList : List <String >) {
@@ -403,8 +403,7 @@ open class AnkiDroidJsAPI(
403403 }
404404
405405 " getNoteTags" -> {
406- val jsonObject = JSONObject (apiParams)
407- val noteId = jsonObject.getLong(" noteId" )
406+ val noteId = currentCard.nid
408407 val noteTags =
409408 withCol {
410409 getNote(noteId).tags
Original file line number Diff line number Diff line change @@ -428,7 +428,7 @@ class AnkiDroidJsAPITest : RobolectricTest() {
428428
429429 // test get tags for note
430430 val expectedTags = n.tags
431- val response = getDataFromRequest(" getNoteTags" , jsapi, jsonObjectOf( " noteId " to n.id) )
431+ val response = getDataFromRequest(" getNoteTags" , jsapi)
432432 val jsonResponse = JSONObject (response)
433433 val actualTags = JSONArray (jsonResponse.getString(" value" ))
434434
@@ -471,21 +471,5 @@ class AnkiDroidJsAPITest : RobolectricTest() {
471471 jsAPI
472472 .handleJsApiRequest(methodName, jsApiContract(apiData), false )
473473 .decodeToString()
474-
475- suspend fun getDataFromRequest (
476- methodName : String ,
477- jsAPI : AnkiDroidJsAPI ,
478- apiData : JSONObject ,
479- ): String =
480- jsAPI
481- .handleJsApiRequest(methodName, jsApiContract(apiData.toString()), false )
482- .decodeToString()
483474 }
484475}
485-
486- private fun jsonObjectOf (vararg pairs : Pair <String , Any >): JSONObject =
487- JSONObject ().apply {
488- for ((key, value) in pairs) {
489- put(key, value)
490- }
491- }
Original file line number Diff line number Diff line change @@ -71,3 +71,10 @@ class IsJsonHolderEqual(
7171}
7272
7373fun isJsonHolderEqual (expectedValue : String ) = IsJsonHolderEqual (JSONObject (expectedValue))
74+
75+ private fun jsonObjectOf (vararg pairs : Pair <String , Any >): JSONObject =
76+ JSONObject ().apply {
77+ for ((key, value) in pairs) {
78+ put(key, value)
79+ }
80+ }
You can’t perform that action at this time.
0 commit comments