pubnub / javascript

PubNub JavaScript SDK docs https://www.pubnub.com/docs/sdks/javascript
Other
553 stars 401 forks source link

Editing Messages 409 Conflict #414

Open tance77 opened 1 month ago

tance77 commented 1 month ago

When editing a message I’ve noticed an issue: going from the message text A to B and then back to A causes a 409 conflict error. However, if I edit from A to B, then to C, and finally back to A, there’s no conflict. This behavior is confusing—why does the system only check the previous action?

Function that we're having issues with:

https://github.com/pubnub/js-chat/blob/master/lib/src/entities/message.ts#L202

What would be the best way to work around this behavior when editing a message?

Idea 1:

We could delete all actions following the conflict, but the time token would not update.

Idea 2:

Delete all the edit actions, but then changes in the UI flash from A to EMPTY to B to EMPTY to A

parfeon commented 1 month ago

@tance77 thank you for reaching out.

I tried to reproduce the ABCA flow and the last step gave me a conflict error (tried with regular REST API).

As for a potential workaround (will suggest it to the Chat team because the Core SDK developed by another team) could be:

  1. edit text
  2. do nothing on success
  3. on error:
    1. fetch reactions for message
    2. find edit action with value which has been used with failed edit
    3. delete reaction with previous edit
    4. re-send edit, which should be successful this time.

Because of complexity and potential errors (if any, structure will change in published reactions) it probably would be better to do as part of editText function call inside of Chat JS SDK.

tance77 commented 1 month ago

@parfeon Thanks for the solution—it works!

I'm still a bit confused, though, about why a conflict occurs when the time tokens differ, but the content is the same. Shouldn't that be valid? Or, better yet, what's the reasoning behind it being considered a conflict?

parfeon commented 1 month ago

@tance77 the Chat SDK team is going to try to assess this improvement suggestion and add it to their backlog (maybe they will implement it differently or our endpoints will evolve to that time).