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

Voice Message - Draft support #4237

Closed
wants to merge 8 commits into from
Closed

Conversation

onurays
Copy link
Contributor

@onurays onurays commented Oct 13, 2021

If a user leaves the room detail screen without sending or deleting the ongoing voice message record then we need to save this record as a draft message and render it again in playback mode when the user enters the room detail screen again.

  • Extend the draft service to support multiple message types
  • Listen onPause of the RoomDetailFragment and save the VM draft if the recording is active
  • Show voice message in playback mode
  • Initialize voice message view with the saved draft
  • Delete the cache file if the user decides to delete or send the recording

EDIT
Fixes #3922

@github-actions
Copy link

github-actions bot commented Oct 13, 2021

Unit Test Results

  62 files  ±0    62 suites  ±0   58s ⏱️ +7s
118 tests ±0  118 ✔️ ±0  0 💤 ±0  0 ±0 
350 runs  ±0  350 ✔️ ±0  0 💤 ±0  0 ±0 

Results for commit 5cb49ea. ± Comparison against base commit 0d6e8bd.

♻️ This comment has been updated with latest results.

@bmarty
Copy link
Member

bmarty commented Oct 14, 2021

LGTM so far

@onurays onurays requested a review from bmarty October 21, 2021 10:59
@onurays onurays marked this pull request as ready for review October 21, 2021 11:16
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 your work.
Some first small remarks, will test it later.

views.composerLayout.collapse()
views.composerLayout.setTextIfDifferent(text)
views.composerLayout.views.sendButton.contentDescription = getString(R.string.send)
private fun renderRegularMode(content: String, messageType: String) {
Copy link
Member

Choose a reason for hiding this comment

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

The body content does not match the name of this fun anymore.
Is it possible to not change this fun and create a new one like renderVoiceMessageMode()?
And test the value of messageType at the call site.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// We should improve the UX to support going into playback mode when paused and delete the media when the view is destroyed.
roomDetailViewModel.handle(RoomDetailAction.EndAllVoiceActions(deleteRecord = false))
views.voiceMessageRecorderView.initVoiceRecordingViews()
roomDetailViewModel.handle(
Copy link
Member

Choose a reason for hiding this comment

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

We do not talk to the textComposerViewModel anymore here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

roomDetailViewModel will decide it and communicate with textComposerViewModel later with SaveDraft event.

Copy link
Member

Choose a reason for hiding this comment

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

OK

views.voiceMessageRecorderView.initVoiceRecordingViews()
roomDetailViewModel.handle(
RoomDetailAction.OnRoomDetailEntersBackground(
isVoiceMessageActive = views.voiceMessageRecorderView.isActive()
Copy link
Member

Choose a reason for hiding this comment

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

It is strange to ask the view about the state. The ViewModel should be aware of the current state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found it complex to determine the state here, especially if there is already a draft in the room.

override fun startRecord() {
init()
outputFile = File(outputDirectory, "Voice message.$filenameExt")
val fileName = """${UUID.randomUUID()}.$filenameExt"""
Copy link
Member

Choose a reason for hiding this comment

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

The filename can be visible to the user, it will be a bit weird.
Is it possible to create a folder per room?
Also saving voice message draft could be handled by the Matrix SDK, using the DraftService

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I proposed a way to keep drafts in a roomId based directory structure.

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.

LGTM, thanks!

@bmarty
Copy link
Member

bmarty commented Oct 25, 2021

CI is not happy, can you handle that please? Thanks

?.transform {
it.setString(DraftEntityFields.MESSAGE_TYPE, MessageType.MSGTYPE_TEXT)
}

Copy link
Member

Choose a reason for hiding this comment

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

This will be a problem for those who are already on version 19. In this case you should create a version 20.

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.

I'm sorry I think this has to be modified.
I would like the voice messages to be saved as draft by the SDK, using DraftService.
It will simplify the code I think and make it more robust, by following our current architecture.
What do you think about it?

@ouchadam ouchadam self-assigned this Nov 9, 2021
@ouchadam
Copy link
Contributor

ouchadam commented Nov 9, 2021

@bmarty from my understanding we are storing the draft via the DraftService https://github.com/vector-im/element-android/pull/4237/files#diff-40c47fd843620c38e4415e5731d825aaacf4d74d6e400cc9b573409fa550392dR604

I'm unfamiliar with the area, do you have more insight into the type of change you're expecting?

val audioJsonString = audioType?.toContentAttachmentData()?.toJsonString()
_viewEvents.post(RoomDetailViewEvents.SaveDraft(audioJsonString, MessageType.MSGTYPE_AUDIO))
} else {
_viewEvents.post(RoomDetailViewEvents.SaveDraft(null, MessageType.MSGTYPE_TEXT))
Copy link
Member

Choose a reason for hiding this comment

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

weird arch

@ouchadam
Copy link
Contributor

going to close this PR whilst working on it

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.

Voice messages: Persist drafts of voice messages when navigating between rooms
3 participants