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

Record and send voice messages #1596

Merged
merged 12 commits into from
Oct 23, 2023
Merged

Conversation

jonnyandrew
Copy link
Contributor

@jonnyandrew jonnyandrew commented Oct 18, 2023

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

  • Add ability to record and send voice messages

Note that where commented the UI and text is still placeholder content which will be replaced in follow up PRs.

Motivation and context

Screenshots / GIFs

1000009088.mp4

Tests

  • Enable voice messages in developer settings
  • Go to a room
  • Tap and hold the voice message button

Tested devices

  • Physical
  • Emulator
  • OS version(s): Android 13

Checklist

@github-actions
Copy link
Contributor

github-actions bot commented Oct 18, 2023

📱 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/qx3eH9

@codecov
Copy link

codecov bot commented Oct 19, 2023

Codecov Report

Attention: 143 lines in your changes are missing coverage. Please review.

Comparison is base (503efbf) 59.12% compared to head (4c1d431) 59.21%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1596      +/-   ##
===========================================
+ Coverage    59.12%   59.21%   +0.09%     
===========================================
  Files         1229     1246      +17     
  Lines        31881    32268     +387     
  Branches      6562     6618      +56     
===========================================
+ Hits         18849    19109     +260     
- Misses       10177    10289     +112     
- Partials      2855     2870      +15     
Files Coverage Δ
...ndroid/features/messages/impl/MessagesPresenter.kt 83.06% <100.00%> (+0.18%) ⬆️
...nt/android/features/messages/impl/MessagesState.kt 100.00% <100.00%> (ø)
...id/features/messages/impl/MessagesStateProvider.kt 90.90% <100.00%> (+0.21%) ⬆️
...s/impl/voicemessages/VoiceMessageComposerEvents.kt 100.00% <100.00%> (ø)
...es/impl/voicemessages/VoiceMessageComposerState.kt 100.00% <100.00%> (ø)
...voicemessages/VoiceMessageComposerStateProvider.kt 87.50% <100.00%> (+1.78%) ⬆️
...ssages/impl/voicemessages/VoiceMessageException.kt 100.00% <100.00%> (ø)
...droid/libraries/mediaupload/api/MediaUploadInfo.kt 100.00% <100.00%> (+25.00%) ⬆️
...ibraries/mediaupload/test/FakeMediaPreProcessor.kt 100.00% <100.00%> (ø)
...raries/permissions/api/PermissionsStateProvider.kt 93.75% <100.00%> (+0.41%) ⬆️
... and 24 more

... and 4 files with indirect coverage changes

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

@jonnyandrew jonnyandrew force-pushed the jonny/voice-message-sending branch 2 times, most recently from 885e100 to be88988 Compare October 19, 2023 19:45
@ElementBot
Copy link
Collaborator

ElementBot commented Oct 19, 2023

Warnings
⚠️

gradle/libs.versions.toml#L24 - A newer version of androidx.compose:compose-bom than 2023.10.00 is available: 2023.10.01

⚠️

gradle/libs.versions.toml#L64 - A newer version of com.google.android.material:material than 1.9.0 is available: 1.10.0

⚠️

gradle/libs.versions.toml#L101 - A newer version of androidx.compose.material3:material3 than 1.2.0-alpha09 is available: 1.2.0-alpha10

⚠️

libraries/permissions/api/src/main/kotlin/io/element/android/libraries/permissions/api/PermissionsStateProvider.kt#L25 - Field requires API level 33 (current min is 23): android.Manifest.permission#POST_NOTIFICATIONS

⚠️

libraries/permissions/api/src/main/kotlin/io/element/android/libraries/permissions/api/PermissionsStateProvider.kt#L34 - Field requires API level 33 (current min is 23): android.Manifest.permission#POST_NOTIFICATIONS

Generated by 🚫 dangerJS against 4c1d431

@jonnyandrew jonnyandrew marked this pull request as ready for review October 20, 2023 08:45
@jonnyandrew jonnyandrew requested a review from a team as a code owner October 20, 2023 08:45
@jonnyandrew jonnyandrew requested review from julioromano and removed request for a team October 20, 2023 08:45
@julioromano
Copy link
Contributor

Do you think we can split this into logically independent smaller blocks?
It's gonna be tough to review it otherwise.
If we split it different reviewers can review different parts and a smaller PR usually gets also more attention from the reviewer itself.

@jonnyandrew
Copy link
Contributor Author

Yeah it has grown pretty large! No problem, I can split this down.

@jonnyandrew jonnyandrew marked this pull request as draft October 20, 2023 08:59
@jonnyandrew jonnyandrew marked this pull request as ready for review October 20, 2023 10:26
encoder = encoderProvider.get().apply {
init(file.absolutePath, sampleRate)
setBitrate(bitRate)
// TODO check encoder application: 2048 (voice, default is typically 2049 as audio)
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've checked on this and it's not currently possible with libopusencoder-android and needs changes to the underlying libopusencoder library. After we merge this, I'll create an issue in this repo and link to element-hq/libopusencoder-android#4.

Copy link
Contributor

@julioromano julioromano left a comment

Choose a reason for hiding this comment

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

Very well done! LGTM

Comments are mainly for simplifying some things but not really blocking.

@@ -71,10 +71,14 @@ internal fun MessageComposerView(
}
}

fun onVoiceRecordButtonEvent(press: PressEvent) {
val onVoiceRecordButtonEvent = { press: PressEvent ->
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering: why val instead of fun? What's the difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually here it shouldn't make a difference, but generally I'm starting to prefer val over fun so that changes in captured variables will trigger recomposition. With fun I've found that subtle bugs can sneak in easily.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -16,10 +16,15 @@

package io.element.android.features.messages.impl.voicemessages
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest moving all the contents of this package to io.element.android.features.messages.impl.voicemessages.record so it'll match best with io.element.android.features.messages.impl.voicemessages.play from #1503

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can I make this refactor in a follow-up PR as I've built some features on top of this branch?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ofc!

*
* @property level The current audio level of the recording as a fraction of 1.
*/
data class Recording(val level: Double) : VoiceRecorderState()
Copy link
Contributor

Choose a reason for hiding this comment

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

Not that big of a deal but perhaps a Float is more than enough here since we don't care about absolute precision as much as we care about performance and responsiveness of the UI.

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 couldn't find a source for this, but I think operations involving float and double have similar performance nowadays, since 64 bit processors became the norm? But happy to be corrected!

@sonarcloud
Copy link

sonarcloud bot commented Oct 23, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot E 2 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@jonnyandrew jonnyandrew merged commit b476654 into develop Oct 23, 2023
14 of 15 checks passed
@jonnyandrew jonnyandrew deleted the jonny/voice-message-sending branch October 23, 2023 17:28
@julioromano
Copy link
Contributor

Super! Thanks for all the changes!

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.

None yet

3 participants