Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement full canAddNotes capabilities, add notesInfo and canAddNotesWithErrorDetail API #60

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

drakargx
Copy link

Based on #46 this implements just the functionality of notesInfo and canAddNotesWithErrorDetail, at least as much for yomitan to work.

themoeway/yomitan#693 was recently pushed into yomitan's main release branch which prevents yomitan from displaying the add button when duplicate checking is enabled, as it relies on the canAddNotesWithErrorDetail API.

canAddNotesWithErrorDetail returns an array of JSON objects with a 'canAdd' field and an optional 'error' field. If canAdd is true then 'error' is not present. Yomitan is checking for the presence of the 'error' field so I also had to create another GSON instance that doesn't serialize nulls; if there's a better way let me know (this is the first time I've used Java in years).

canAddNotes is currently implemented by just checking if the card to add is a duplicate, so right now I pass the result of that over and if the result is false, I add the string Yomitan is checking for. If a future feature of Yomitan relies on the contents of the error message then this needs to be revisited.

I am also not sure how to credit @Aquafina-water-bottle for the work in implementing the notesInfo API, I simply added some performance improvements by caching model information.

This implementation is kinda hacky. canAddNotes in Ankiconnect-Android just checks for duplicate cards, so I pass the result of that check through and add the string yomitan is checking for so that it will mark the card as a duplicate.
@drakargx drakargx marked this pull request as ready for review April 23, 2024 23:17
@drakargx drakargx changed the title Add notesInfo and canAddNotesWithErrorDetail API Implement full canAddNotes capabilities, add notesInfo and canAddNotesWithErrorDetail API Apr 24, 2024
Copy link
Owner

@KamWithK KamWithK left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, it's mostly good apart from a few syntactical nitpicks and one function which I think should be broken down into a few smaller ones

@KamWithK KamWithK mentioned this pull request Apr 27, 2024
@drakargx drakargx requested a review from KamWithK April 27, 2024 17:57
Logic for checking if a card is duplicate if scope is set to "deck" or "deck root" wasn't correct after refactor
Copy link

@naiza-asaad naiza-asaad left a comment

Choose a reason for hiding this comment

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

Hi @drakargx, thanks for the work on this and for letting me comment here. This is just for an issue I noticed when I tested the changes with asbplayer. notesInfo isn't returning anything so asbplayer fails to update the last card.

Also this is unrelated to your PR but I think it might also just be a minor fix. When an unsupported API is called, default_version() returns a String ("AnkiConnect v.6") and a MalformedJsonException is thrown: killergerbah/asbplayer#408. Since asbplayer also calls addTags, the issue will continue to happen even after notesInfo is added. Is it okay if the response is wrapped like this:

    private String default_version() {
        return Parser.gson.toJson("AnkiConnect v.6");
    }

The tags won't be added but at the very least, it stops the exception from being thrown.

}

try (cursor) {
while (!cursor.moveToNext()) {

Choose a reason for hiding this comment

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

Was this supposed to be while(cursor.moveToNext())? It seems like it's ignoring the results of the query right now

Copy link
Author

@drakargx drakargx May 6, 2024

Choose a reason for hiding this comment

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

Was this supposed to be while(cursor.moveToNext())? It seems like it's ignoring the results of the query right now

Thanks for pointing that out, you are right.

Also this is unrelated to your PR but I think it might also just be a minor fix. When an unsupported API is called, default_version() returns a String ("AnkiConnect v.6") and a MalformedJsonException is thrown: killergerbah/asbplayer#408. Since asbplayer also calls addTags, the issue will continue to happen even after notesInfo is added. Is it okay if the response is wrapped like this:

I think for this it would be better if instead of calling default_version() here we just threw an Exception, that way we will respond like the desktop AnkiConnect with a json object of {"result": null, "error":"unsupported action"}.

Will test the change in asbplayer to make sure it works before updating PR

Copy link
Owner

Choose a reason for hiding this comment

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

@naiza-asaad after @drakargx finishes up if you're able to please test everything and double check it works

After that I'm happy to merge :)

Choose a reason for hiding this comment

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

Sure. Myself and others have been using this branch for some time now since it fixed the duplicate checking bug. Probably only the comment about fixing the result of notesInfo() should be changed before merging.

The other one about changing the result of default_version() should probably be in a different PR and not block this since it's technically unrelated.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, got distracted with work & other things...

I agree with @naiza-asaad on leaving to fix default_version() on a different PR. notesInfo logic is fixed in most recent commit.

A few people in TMW have been running the build with these changes for some time now and we haven't heard of any issues, so I think it should be good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants