Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft : add volatile storage when moving to edit mode. #3132

Merged
merged 4 commits into from
Jul 3, 2024

Conversation

ganfra
Copy link
Member

@ganfra ganfra commented Jul 3, 2024

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

Add a volatile draft store when moving from NewMessage/Reply mode to Edit mode, so we don't loose our current composer text while moving to edit. It's then restored when :

  • Sending the edit
  • Closing the edit

If we manually switch to another Edit or another Reply from the timeline actions, then volatile draft is not restored.

Motivation and context

Screenshots / GIFs

Tests

  • Open a room
  • Start typing something
  • Start editing another event
  • Send the edit or close it
  • Get your previous text back to the composer

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

  • Changes have been tested on an Android device or Android emulator with API 23
  • UI change has been tested on both light and dark themes
  • Accessibility has been taken into account. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#accessibility
  • Pull request is based on the develop branch
  • Pull request title will be used in the release note, it clearly define what will change for the user
  • Pull request includes screenshots or videos if containing UI changes
  • Pull request includes a sign off
  • You've made a self review of your PR

@ganfra ganfra changed the title Feature/fga/draft in memory when editing Draft : add volatile storage when moving to edit mode. Jul 3, 2024
@ganfra ganfra marked this pull request as ready for review July 3, 2024 10:25
@ganfra ganfra requested a review from a team as a code owner July 3, 2024 10:25
@ganfra ganfra requested review from jmartinesp and removed request for a team July 3, 2024 10:25
@ganfra ganfra added the PR-Feature For a new feature label Jul 3, 2024
Copy link
Contributor

github-actions bot commented Jul 3, 2024

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/RyQZQZ

Copy link

codecov bot commented Jul 3, 2024

Codecov Report

Attention: Patch coverage is 67.74194% with 30 lines in your changes missing coverage. Please review.

Project coverage is 75.95%. Comparing base (bc13c24) to head (008ba4f).
Report is 28 commits behind head on develop.

Files Patch % Lines
...es/messages/impl/draft/MatrixComposerDraftStore.kt 0.00% 19 Missing ⚠️
...messages/impl/draft/DefaultComposerDraftService.kt 0.00% 7 Missing ⚠️
...s/impl/messagecomposer/MessageComposerPresenter.kt 93.33% 1 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3132      +/-   ##
===========================================
- Coverage    75.95%   75.95%   -0.01%     
===========================================
  Files         1638     1640       +2     
  Lines        38630    38663      +33     
  Branches      7464     7471       +7     
===========================================
+ Hits         29343    29366      +23     
- Misses        5399     5410      +11     
+ Partials      3888     3887       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@jmartinesp jmartinesp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a comment about docs. Thanks for the UX improvement!

import io.element.android.libraries.matrix.api.room.draft.ComposerDraft
import javax.inject.Inject

class VolatileComposerDraftStore @Inject constructor() : ComposerDraftStore {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add docs on the 2 draft stores?

if (isVolatile) {
volatileComposerDraftStore.updateDraft(roomId, draft)
} else {
matrixComposerDraftStore.updateDraft(roomId, draft)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe introduce a getStore fun to be able to write:

    override suspend fun loadDraft(roomId: RoomId, isVolatile: Boolean): ComposerDraft? {
        return getStore(isVolatile).loadDraft(roomId)
    }

    override suspend fun updateDraft(roomId: RoomId, draft: ComposerDraft?, isVolatile: Boolean) {
        getStore(isVolatile).updateDraft(roomId, draft)
    }

    private fun getStore(isVolatile: Boolean): ComposerDraftStore {
        return if (isVolatile) {
            volatileComposerDraftStore
        } else {
            matrixComposerDraftStore
        }
    }

@ganfra ganfra enabled auto-merge July 3, 2024 13:04
@ganfra ganfra added the Run-Maestro Starts a Maestro Cloud session to run integration tests label Jul 3, 2024
@github-actions github-actions bot removed the Run-Maestro Starts a Maestro Cloud session to run integration tests label Jul 3, 2024
Copy link

sonarqubecloud bot commented Jul 3, 2024

@ganfra ganfra merged commit c7dd2d5 into develop Jul 3, 2024
28 of 30 checks passed
@ganfra ganfra deleted the feature/fga/draft_in_memory_when_editing branch July 3, 2024 13:38
* Currently it's used to store draft message when moving to edit mode.
*/
class VolatileComposerDraftStore @Inject constructor() : ComposerDraftStore {
private val drafts: MutableMap<RoomId, ComposerDraft> = mutableMapOf()
Copy link
Member

@bmarty bmarty Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird to store the draft in a map since a new VolatileComposerDraftStore will be created for each room I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Feature For a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants