Fix saving changes to statuses when editing (#3103)

* Fix saving changes to statuses when editing

With the previous code backing out of a status editing operation where changes
had been made  (whether it was editing an existing status, a scheduled status,
or a draft) would prompt the user to save the changes as a new draft.

See https://github.com/tuskyapp/Tusky/issues/2704 and
https://github.com/tuskyapp/Tusky/issues/2705 for more detail.

The fix:

- Create an enum to represent the four different kinds of edits that can
  happen
  - Editing a new status (i.e., composing it for the first time)
  - Editing a posted status
  - Editing a draft
  - Editing a scheduled status

- Store this in ComposeOptions, and set it appropriately everywhere
  ComposeOptions is created.

- Check the edit kind when backing out of ComposeActivity, and use this to
  show one of three different dialogs as appropriate so the user can:
  - Save as new draft or discard changes
  - Continue editing or discard changes
  - Update existing draft or discard changes

Also fix ComposeViewModel.didChange(), which erroneously reported false if the
old text started with the new text (e.g., if the old text was "hello, world"
and it was edited to "hello", didChange() would not consider that to be a
change).

Fixes https://github.com/tuskyapp/Tusky/issues/2704,
https://github.com/tuskyapp/Tusky/issues/2705

* Use orEmpty extension function
This commit is contained in:
Nik Clayton 2022-12-31 13:04:49 +01:00 committed by GitHub
commit a5f479d79c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 112 additions and 30 deletions

View file

@ -109,6 +109,8 @@
<string name="action_delete">Delete</string>
<string name="action_delete_conversation">Delete conversation</string>
<string name="action_delete_and_redraft">Delete and re-draft</string>
<string name="action_discard">Discard changes</string>
<string name="action_continue_edit">Continue editing</string>
<string name="action_send">TOOT</string>
<string name="action_send_public">TOOT!</string>
<string name="action_retry">Retry</string>
@ -443,6 +445,7 @@
<string name="lock_account_label_description">Requires you to manually approve followers</string>
<string name="compose_save_draft">Save draft?</string>
<string name="compose_save_draft_loses_media">Save draft? (Attachments will be uploaded again when you restore the draft.)</string>
<string name="compose_unsaved_changes">You have unsaved changes.</string>
<string name="send_post_notification_title">Sending post…</string>
<string name="send_post_notification_error_title">Error sending post</string>
<string name="send_post_notification_channel_name">Sending Posts</string>