mirror of
https://github.com/zulip/zulip.git
synced 2026-06-24 21:08:25 +08:00
We received a complaint about the generation of multiple duplicate drafts for a single message. It was discovered that the likely cause of this was how we were handling clients that were frequently suspending/unsuspending, we would initiate a reload when we discovered this, and expect the `beforeunload` handler to save the draft. This behaved correctly, however, we would also save the compose state and fill it in via `preserve_state` in reload.js. The important detail here is that `preserve_state` would not encode and preserve the `draft_id` for the current message, partly because it had no way of knowing the `draft_id` of the draft... since we have not saved it yet, the `beforeunload` event happens after `preserve_state`. As such, performing any action that would trigger a draft to be saved, eg pressing Esc to close the compose box, would save a duplicate draft of the same message. To resolve the above bug, we (1) ensure that we call `drafts.update_draft()` in `preserve_state`, this returns a draft_id to us, which we (2) ensure that we encode as part of the url and (3) set on the `#composebox-textarea` as a `draft-id` data attribute, which we check the next time we try to save the draft, post reload. Note that this causes us to save the draft twice, once from preserve_state and then again from the `beforeunload` handler, but we do not add two drafts since the second update_draft call just edits the timestamp because it finds the `draft-id` data attribute on the `#composebox-textarea` set by the first call. |
||
|---|---|---|
| .. | ||
| assets | ||
| audio | ||
| generated | ||
| html | ||
| images | ||
| js | ||
| shared | ||
| styles | ||
| templates | ||
| third | ||
| .gitignore | ||