AnkiHubSoftware / ankihub_addon

3 stars 0 forks source link

[BUILD-463] feat: Add method for getting note suspension states from Anki to the iframe #982

Closed RisingOrange closed 4 months ago

RisingOrange commented 5 months ago

In the AnkiHub AI chatbot, we want to know which notes are suspended and which aren't. This way we can e.g. have a button for each note that says "Unsuspend" or "Suspend" depending on if the note is currently suspended. We need a way to get this information.

The AnkiHub AI templates will be able to use java script like this to request the suspension states:

const message = {
  message: `ankihub_get_note_suspension_states {
    "noteIds": [
      "fe9cdeaa-7363-4135-8c00-98c723a3ed5d",
      "e3c1f90d-6dc8-41a8-8155-3bf05e6ea307",
      "00000000-0000-0000-0000-000000000002"
    ]
  }`,
  sendToPython: true
};
window.parent.postMessage(message, '*');

Then they will be able to receive the result using code like this:

window.addEventListener("message", function (event) {
  const message = event.data;
  console.log("received message", message);
});

Example result:

{
    // If a note is not found in Anki, it won't be in the returned mapping.
    "noteSuspensionStates": {
         "fe9cdeaa-7363-4135-8c00-98c723a3ed5d": true,
         "e3c1f90d-6dc8-41a8-8155-3bf05e6ea307": false,
    }
}

Related issues

https://ankihub.atlassian.net/jira/software/c/projects/BUILD/boards/1?selectedIssue=BUILD-463

Proposed changes

How to reproduce

codecov[bot] commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 87.83%. Comparing base (dece30f) to head (c8ae98e).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #982 +/- ## ========================================== + Coverage 87.79% 87.83% +0.03% ========================================== Files 67 67 Lines 6795 6812 +17 ========================================== + Hits 5966 5983 +17 Misses 829 829 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.