gkeepapi icon indicating copy to clipboard operation
gkeepapi copied to clipboard

Added methods to convert `gkeepapi.node.Note` to `gkeepapi.node.List` and `gkeepapi.node.List` to `gkeepapi.node.Note`

Open kyrlon opened this issue 1 year ago • 4 comments

Fixes kiwiz/gkeepapi#122. Added methods roughly outlined in the issue

kyrlon avatar Apr 18 '24 03:04 kyrlon

Thanks for the PR. The (official) clients preserve the ID when converting between List/Note. IIRC, that was what made implementing this feature complicated.

The code needs to:

  • Convert the body ✅
  • Preserve the metadata
  • Replace the existing List/Note that the Keep instance knows about

The last item is tricky as individual Nodes don't contain a reference to the Keep instance. This is why ListItems aren't visible to the Keep until they've been synced.

Our options:

  • Use the implementation in the PR and add a note to "Known Issues".
  • Refactor the code to inject a reference to the Keep instance within every Node.

kiwiz avatar May 28 '24 14:05 kiwiz

Interesting. The latter option sounds like a challenge, but with your guidance I am up for it. Would this be some variant of dependency injection?

kyrlon avatar Jun 01 '24 14:06 kyrlon

Hmm, perhaps we can get around this by making it a method on the Keep object like so:

list_ = keep.to_list(note)
note = keep.to_note(list)

That looks kind of odd though. I think the crux of the issue is: Does a user expect a converted Note/List to retain all its metadata?

kiwiz avatar Jun 05 '24 00:06 kiwiz

Hmm that does look peculiar. Is it possible to make the reference to the keep instance optional?

kyrlon avatar Jun 11 '24 19:06 kyrlon