contently / videojs-annotation-comments

A plugin for video.js to add support for timeline moment/range comments and annotations
https://contently.github.io/videojs-annotation-comments/
Other
171 stars 50 forks source link

Cannot delete comments that were created programmatically #56

Closed drichar closed 4 years ago

drichar commented 4 years ago

Expected Behavior

Any comment can be deleted programmatically via API with the destroyComment event

Actual Behavior

Comments created by the UI or defined in annotationsObjects on initialization can be deleted with destroyComment, but comments created programmatically with the newComment event result in this error:

Uncaught (in promise) TypeError: Cannot read property 'destroyComment' of undefined

https://github.com/contently/videojs-annotation-comments/blob/ee905aa65a30d56f62edf2f5857f366c2bdaada9/src/js/lib/event_dispatcher.js#L39 It seems that comments created programmatically are set inside plugin.annotationState with the commentList property undefined: image

Steps to Reproduce the Problem

  1. Initialize plugin with an annotation in annotationsObjects with id: 1
  2. Add a new comment to annotation via API: plugin.fire('newComment', { annotationId: 1, body: "My comment string" })
  3. Call plugin.fire('destroyComment', { id: newCommentId })

I confirmed this is happening by calling destroyComment in this test: https://github.com/contently/videojs-annotation-comments/blob/a5c7d899d6498352e155da9f6450fe553c598dca/test/mocha/features/api_test.js#L125

Specifications

jackpope commented 4 years ago

Thanks for reporting this. I was able to reproduce it with your information. Looks like the comment's commentList wasn't being set when initializing a comment through the API. This PR should fix and updates the integration tests as well: https://github.com/contently/videojs-annotation-comments/pull/58

jackpope commented 4 years ago

@drichar this should be fixed with the latest release 2.0.1. Closing this issue for now but please let me know here if you still have trouble.

drichar commented 4 years ago

Thank you @jackpope it now works as expected!