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

Convert DraftService to suspend functions #2405

Merged
merged 2 commits into from
Nov 18, 2020

Conversation

Dominaezzz
Copy link
Contributor

Signed-off-by: Dominic Fischer [email protected]

Pull Request Checklist

  • Changes has been tested on an Android device or Android emulator with API 21
  • UI change has been tested on both light and dark themes
  • Pull request is based on the develop branch
  • Pull request updates CHANGES.md
  • Pull request includes screenshots or videos if containing UI changes
  • Pull request includes a sign off

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

Thanks for the new PR. I have one question though.

it.sendMode is SendMode.EDIT -> {
setState { copy(sendMode = it.sendMode.copy(text = action.draft)) }
room.saveDraft(UserDraft.EDIT(it.sendMode.timelineEvent.root.eventId!!, action.draft), NoOpMatrixCallback())
viewModelScope.launch {
Copy link
Member

Choose a reason for hiding this comment

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

We call this action when the Fragment is paused, so there is maybe a risk that the action is cancelled, because the vieWModelScope will be cancelled (I think). Have you tested that change on a device?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

viewModelScope is cancelled when the ViewModel is cleared, which happens when the owning Activity/Fragment is destroyed (so it will survive rotations and other config changes too).
Does this need to outlive the fragment's destruction?

To inspire confidence, I've linked docs that outline the behaviour.

I have not tested this on a device.

Copy link
Member

Choose a reason for hiding this comment

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

Does this need to outlive the fragment's destruction?

Yes, I think so, because we save the draft when the user leaves, and the RoomDetailActivity will be destroyed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh okay. I'll probably just use withContext(NonCancellable) for it but I'll give it some thought first.

Copy link
Member

Choose a reason for hiding this comment

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

Yes NonCancellable is the way to go I think 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ended up putting it in the launch directly, to ensure it doesn't get cancelled between launch and withContext.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, LGTM now :)

@bmarty
Copy link
Member

bmarty commented Nov 18, 2020

Thanks for the update @Dominaezzz . I have a doubt about using NonCancellable because in the (rare) case when the user will signout, we cancel every tasks and it won't be the case for this one. But as the draft is saved locally (no network delay...), the time for the user to signout, the draft will be saved.

@bmarty bmarty merged commit ca0da2c into element-hq:develop Nov 18, 2020
@Dominaezzz Dominaezzz deleted the suspend_functions_1 branch March 27, 2021 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants