How can we listen comment added, updated and deleted events in custom view?

I want to refresh my custom view once Comment got added or edited or deleted.

Parents
  • Hi ,

    Created new thread and copy/paste your response below.

    ================

    • Hi Harshad,

      You can't subscribe to an event through the Integration API; but you can potentially listen for changes and intuitively deduct when comments are added/removed.

      Start by subscribing to the ActiveDocumentChanged event on the EditorController.

      Then subscribe to the ActiveSegmentChanged, ContentChanged events when active document changes.

      Manage a collection on the document to identify the list of comments associated with each of the segmentPairs (read when the document is loaded).  Call this CollectionA

      Note: when you add a comment to the segment, the content changed event is fired. Understanding this, you would only need to get the current list of comments for the active segment pair and then compare it against a comments for the segment mentioned in CollectionA that you are managing on the document.

      private void ActiveDocument_ContentChanged(object sender, DocumentContentEventArgs e)
      {

      [...]

           var segmentSourceComments = segmentPair.Source.GetComments();
           var segmentTargetComments = segmentPair.Target.GetComments();
           var segmentParagraphComments = segmentPair.GetParagraphUnitProperties().Comments;

          // Compare list of comments listed here against what was initially read in CollectionA
          // Identify what was added or removed
          // if different, do something!
          // update CollectionA with the new list of comments for the SegmentPair (if different)

      [...]

      }

      similarly, perform same check in the ActiveSegmentChanged; to cover cases where the content structure of the segment didn't change; I'd need to check but might be that if the scope of the comment is at the paragraph level, then the ContentChanged is not fired!

      ===================

  • Hi ,

    Thanks for your input.

    Please find point wise reply for given input below.

    #1) ActiveDocument_ContentChanged:-

    • this event only called when we Add  & Delete comment
    • If comment added first time say version 1 then its called, If we add new comment say version 2 then not called. 
    • If we Edit comment then also not called
    • Its also called when we write/remove content to/from Active Segment so its not feasible to have comment logic here

    #2) var segmentSourceComments = segmentPair.Source.GetComments(); AND var segmentTargetComments = segmentPair.Target.GetComments();: 

    • Was not able to find GetComments() method in API
    • In APi we have GetCommentsFromSegment(ISegmentPair segmentPair) but its return comments having Scope as Segment, Its not return comments having Scope as Range.

    #3) var segmentParagraphComments = segmentPair.GetParagraphUnitProperties().Comments;:

    • Always return NULL. I have comments for given segment but its return NULL

    I have managed to get all comments (Scope comment and Range comment). Here ActiveDocument_ContentChanged is called only in few scenarios (i.e. First time Add & Delete) so only half usable ;-)

    Thanks,

    -harshad

Reply
  • Hi ,

    Thanks for your input.

    Please find point wise reply for given input below.

    #1) ActiveDocument_ContentChanged:-

    • this event only called when we Add  & Delete comment
    • If comment added first time say version 1 then its called, If we add new comment say version 2 then not called. 
    • If we Edit comment then also not called
    • Its also called when we write/remove content to/from Active Segment so its not feasible to have comment logic here

    #2) var segmentSourceComments = segmentPair.Source.GetComments(); AND var segmentTargetComments = segmentPair.Target.GetComments();: 

    • Was not able to find GetComments() method in API
    • In APi we have GetCommentsFromSegment(ISegmentPair segmentPair) but its return comments having Scope as Segment, Its not return comments having Scope as Range.

    #3) var segmentParagraphComments = segmentPair.GetParagraphUnitProperties().Comments;:

    • Always return NULL. I have comments for given segment but its return NULL

    I have managed to get all comments (Scope comment and Range comment). Here ActiveDocument_ContentChanged is called only in few scenarios (i.e. First time Add & Delete) so only half usable ;-)

    Thanks,

    -harshad

Children