ubsicap / paratext_demo_plugins

Sample code to demonstrate how to create a Paratext plugin
2 stars 4 forks source link

Notes API - Note ID #29

Open GeoDirk opened 1 year ago

GeoDirk commented 1 year ago

We are pushing notes to the various corpora through our plugin successfully. Ideally it would very handy when sending a new note through the API for the ID of the new note to be returned back to us. We also need a way to later send an update to the same note through the API, identifying it by the ID, to flag the note as resolved. Is this possible? Not sure how you all keep track of note objects internally.

FoolRunning commented 1 year ago

The note object is returned when creating a new note. You can update that note by adding a new comment or resolving it. Is that sufficient?

GeoDirk commented 1 year ago

Hey Tim,

So I looked at the plugin demos and modified the AddNote code to be:

var noteObject = m_project.AddNote(writeLock, anchor, paragraphs, assignedUser: assignee);

Looking at the noteObject variable it looks like this:

noteObject
{Paratext.Base.Plugins.CommentThreadWrapper}
    Anchor: {NEH 1:3: Ɓe mo sat nwan nne nyem ɗi mo bar mpo ɗak laatong ni kɨ mo baaso nyil ni, mo mbut njeel ɗiinaat, kɨ naashwoop hakyeng. Kɨ nne moo shirip fwang kɨ̀ bɨrni nJerusalem ni, kɨ moo caan po shyeep kɨpang kɨ̀ ni mo. [0]}
    AssignedUser: {}
    Comments: Count = 1
    IsRead: false
    IsResolved: false
    ReplyToUser: null
    cachedComments: {PtxUtils.LazyInitHelper<System.Collections.Generic.IReadOnlyList<Paratext.PluginInterfaces.IComment>>}
    thread: {Paratext.Data.ProjectComments.CommentThread}

While we certainly could save this whole object into our database, I'm not sure how we can return back to this note later on without some sort of unique ID/GUID. If this note has been modified in Paratext, we no longer will be able to match them up easily with the one stored in our database.

FoolRunning commented 1 year ago

Ah, I see. Unfortunately, that's not currently possible. It would probably be best to send in a feature request through Help > Give feedback describing exactly what you need so it can get prioritized.

If this is holding you up and you are unable to wait, you can use reflection to get at the ID through the thread object contained in the wrapper object (noteObject.thread.Id - a string). This should be considered a temporary solution since there is no guarantee that the structure won't change. SIL.Core.Reflection.ReflectionHelper (GetField and GetProperty) can help if you can import LibPalaso.

GeoDirk commented 1 year ago

Thanks Tim - feature request was submitted (PTXS-40134)