-
Notifications
You must be signed in to change notification settings - Fork 868
Voice Broadcast - Start record #7363
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a88a172
Trigger play/pause/resume/stop actions on VoiceRecorder
dbc6197
Reduce duplicated code
33a021c
Add sdk entry to attach reference to the outgoing events
e775404
Improve VoiceRecorder abstraction
ad2bf8d
Add VoiceBroadcastRecorder
3ad245d
Trigger VoiceBroadcast recording actions
aecb660
Move Voice Broadcast constants into dedicated object
ad730d5
Fix tests
c492fda
Change VoiceBroadcastRecorder as Interface
06bceef
Add changelog
fb9c747
Reformat and add trailing commas
64e6a2b
Compute file size from chunk length
9d35e81
Compute max file size from chunk length
62596b3
Pause recording when the composer is not visible anymore
3a951f2
Add punctuation to kdoc
1db3d69
Change chunk_length type in unit test
400118e
Remove useless Android API checks
def9fc0
Revert AudioMessageHelper.pauseRecording
92bd8cd
Voice Broadcast - Remove check on voice message minimum duration
b9335c6
Rename const DEFAULT_CHUNK_LENGTH_IN_SECONDS
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| [Voice Broadcast] Record and send not aggregated voice messages to the room |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,7 +127,7 @@ internal class LocalEchoEventFactory @Inject constructor( | |
| newBodyFormattedText: CharSequence?, | ||
| newBodyAutoMarkdown: Boolean, | ||
| msgType: String, | ||
| compatibilityText: String | ||
| compatibilityText: String, | ||
| ): Event { | ||
| val content = if (newBodyFormattedText != null) { | ||
| TextContent(newBodyText.toString(), newBodyFormattedText.toString()).toMessageTextContent(msgType) | ||
|
|
@@ -148,7 +148,7 @@ internal class LocalEchoEventFactory @Inject constructor( | |
| private fun createPollContent( | ||
| question: String, | ||
| options: List<String>, | ||
| pollType: PollType | ||
| pollType: PollType, | ||
| ): MessagePollContent { | ||
| return MessagePollContent( | ||
| unstablePollCreationInfo = PollCreationInfo( | ||
|
|
@@ -166,7 +166,7 @@ internal class LocalEchoEventFactory @Inject constructor( | |
| pollType: PollType, | ||
| targetEventId: String, | ||
| question: String, | ||
| options: List<String> | ||
| options: List<String>, | ||
| ): Event { | ||
| val newContent = MessagePollContent( | ||
| relatesTo = RelationDefaultContent(RelationType.REPLACE, targetEventId), | ||
|
|
@@ -186,7 +186,7 @@ internal class LocalEchoEventFactory @Inject constructor( | |
| fun createPollReplyEvent( | ||
| roomId: String, | ||
| pollEventId: String, | ||
| answerId: String | ||
| answerId: String, | ||
| ): Event { | ||
| val content = MessagePollResponseContent( | ||
| body = answerId, | ||
|
|
@@ -212,7 +212,7 @@ internal class LocalEchoEventFactory @Inject constructor( | |
| roomId: String, | ||
| pollType: PollType, | ||
| question: String, | ||
| options: List<String> | ||
| options: List<String>, | ||
| ): Event { | ||
| val content = createPollContent(question, options, pollType) | ||
| val localId = LocalEcho.createLocalEchoId() | ||
|
|
@@ -229,7 +229,7 @@ internal class LocalEchoEventFactory @Inject constructor( | |
|
|
||
| fun createEndPollEvent( | ||
| roomId: String, | ||
| eventId: String | ||
| eventId: String, | ||
| ): Event { | ||
| val content = MessageEndPollContent( | ||
| relatesTo = RelationDefaultContent( | ||
|
|
@@ -254,7 +254,7 @@ internal class LocalEchoEventFactory @Inject constructor( | |
| latitude: Double, | ||
| longitude: Double, | ||
| uncertainty: Double?, | ||
| isUserLocation: Boolean | ||
| isUserLocation: Boolean, | ||
| ): Event { | ||
| val geoUri = buildGeoUri(latitude, longitude, uncertainty) | ||
| val assetType = if (isUserLocation) LocationAssetType.SELF else LocationAssetType.PIN | ||
|
|
@@ -274,7 +274,7 @@ internal class LocalEchoEventFactory @Inject constructor( | |
| roomId: String, | ||
| latitude: Double, | ||
| longitude: Double, | ||
| uncertainty: Double? | ||
| uncertainty: Double?, | ||
| ): Event { | ||
| val geoUri = buildGeoUri(latitude, longitude, uncertainty) | ||
| val content = MessageBeaconLocationDataContent( | ||
|
|
@@ -305,7 +305,7 @@ internal class LocalEchoEventFactory @Inject constructor( | |
| newBodyText: String, | ||
| autoMarkdown: Boolean, | ||
| msgType: String, | ||
| compatibilityText: String | ||
| compatibilityText: String, | ||
| ): Event { | ||
| val permalink = permalinkFactory.createPermalink(roomId, originalEvent.root.eventId ?: "", false) | ||
| val userLink = originalEvent.root.senderId?.let { permalinkFactory.createPermalink(it, false) } ?: "" | ||
|
|
@@ -347,14 +347,21 @@ internal class LocalEchoEventFactory @Inject constructor( | |
| fun createMediaEvent( | ||
| roomId: String, | ||
| attachment: ContentAttachmentData, | ||
| rootThreadEventId: String? | ||
| rootThreadEventId: String?, | ||
| relatesTo: RelationDefaultContent?, | ||
| ): Event { | ||
| return when (attachment.type) { | ||
| ContentAttachmentData.Type.IMAGE -> createImageEvent(roomId, attachment, rootThreadEventId) | ||
| ContentAttachmentData.Type.VIDEO -> createVideoEvent(roomId, attachment, rootThreadEventId) | ||
| ContentAttachmentData.Type.AUDIO -> createAudioEvent(roomId, attachment, isVoiceMessage = false, rootThreadEventId = rootThreadEventId) | ||
| ContentAttachmentData.Type.VOICE_MESSAGE -> createAudioEvent(roomId, attachment, isVoiceMessage = true, rootThreadEventId = rootThreadEventId) | ||
| ContentAttachmentData.Type.FILE -> createFileEvent(roomId, attachment, rootThreadEventId) | ||
| ContentAttachmentData.Type.IMAGE -> createImageEvent(roomId, attachment, rootThreadEventId, relatesTo) | ||
| ContentAttachmentData.Type.VIDEO -> createVideoEvent(roomId, attachment, rootThreadEventId, relatesTo) | ||
| ContentAttachmentData.Type.AUDIO -> createAudioEvent(roomId, attachment, isVoiceMessage = false, rootThreadEventId = rootThreadEventId, relatesTo) | ||
| ContentAttachmentData.Type.VOICE_MESSAGE -> createAudioEvent( | ||
| roomId, | ||
| attachment, | ||
| isVoiceMessage = true, | ||
| rootThreadEventId = rootThreadEventId, | ||
| relatesTo, | ||
| ) | ||
| ContentAttachmentData.Type.FILE -> createFileEvent(roomId, attachment, rootThreadEventId, relatesTo) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -378,7 +385,12 @@ internal class LocalEchoEventFactory @Inject constructor( | |
| ) | ||
| } | ||
|
|
||
| private fun createImageEvent(roomId: String, attachment: ContentAttachmentData, rootThreadEventId: String?): Event { | ||
| private fun createImageEvent( | ||
| roomId: String, | ||
| attachment: ContentAttachmentData, | ||
| rootThreadEventId: String?, | ||
| relatesTo: RelationDefaultContent?, | ||
| ): Event { | ||
| var width = attachment.width | ||
| var height = attachment.height | ||
|
|
||
|
|
@@ -403,19 +415,17 @@ internal class LocalEchoEventFactory @Inject constructor( | |
| size = attachment.size | ||
| ), | ||
| url = attachment.queryUri.toString(), | ||
| relatesTo = rootThreadEventId?.let { | ||
| RelationDefaultContent( | ||
| type = RelationType.THREAD, | ||
| eventId = it, | ||
| isFallingBack = true, | ||
| inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(it)) | ||
| ) | ||
| } | ||
| relatesTo = relatesTo ?: rootThreadEventId?.let { generateThreadRelationContent(it) } | ||
| ) | ||
| return createMessageEvent(roomId, content) | ||
| } | ||
|
|
||
| private fun createVideoEvent(roomId: String, attachment: ContentAttachmentData, rootThreadEventId: String?): Event { | ||
| private fun createVideoEvent( | ||
| roomId: String, | ||
| attachment: ContentAttachmentData, | ||
| rootThreadEventId: String?, | ||
| relatesTo: RelationDefaultContent?, | ||
| ): Event { | ||
| val mediaDataRetriever = MediaMetadataRetriever() | ||
| mediaDataRetriever.setDataSource(context, attachment.queryUri) | ||
|
|
||
|
|
@@ -447,14 +457,7 @@ internal class LocalEchoEventFactory @Inject constructor( | |
| thumbnailInfo = thumbnailInfo | ||
| ), | ||
| url = attachment.queryUri.toString(), | ||
| relatesTo = rootThreadEventId?.let { | ||
| RelationDefaultContent( | ||
| type = RelationType.THREAD, | ||
| eventId = it, | ||
| isFallingBack = true, | ||
| inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(it)) | ||
| ) | ||
| } | ||
| relatesTo = relatesTo ?: rootThreadEventId?.let { generateThreadRelationContent(it) } | ||
| ) | ||
| return createMessageEvent(roomId, content) | ||
| } | ||
|
|
@@ -463,7 +466,8 @@ internal class LocalEchoEventFactory @Inject constructor( | |
| roomId: String, | ||
| attachment: ContentAttachmentData, | ||
| isVoiceMessage: Boolean, | ||
| rootThreadEventId: String? | ||
| rootThreadEventId: String?, | ||
| relatesTo: RelationDefaultContent?, | ||
| ): Event { | ||
| val content = MessageAudioContent( | ||
| msgType = MessageType.MSGTYPE_AUDIO, | ||
|
|
@@ -479,19 +483,17 @@ internal class LocalEchoEventFactory @Inject constructor( | |
| waveform = waveformSanitizer.sanitize(attachment.waveform) | ||
| ), | ||
| voiceMessageIndicator = if (!isVoiceMessage) null else emptyMap(), | ||
| relatesTo = rootThreadEventId?.let { | ||
| RelationDefaultContent( | ||
| type = RelationType.THREAD, | ||
| eventId = it, | ||
| isFallingBack = true, | ||
| inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(it)) | ||
| ) | ||
| } | ||
| relatesTo = relatesTo ?: rootThreadEventId?.let { generateThreadRelationContent(it) } | ||
| ) | ||
| return createMessageEvent(roomId, content) | ||
| } | ||
|
|
||
| private fun createFileEvent(roomId: String, attachment: ContentAttachmentData, rootThreadEventId: String?): Event { | ||
| private fun createFileEvent( | ||
| roomId: String, | ||
| attachment: ContentAttachmentData, | ||
| rootThreadEventId: String?, | ||
| relatesTo: RelationDefaultContent?, | ||
| ): Event { | ||
| val content = MessageFileContent( | ||
| msgType = MessageType.MSGTYPE_FILE, | ||
| body = attachment.name ?: "file", | ||
|
|
@@ -500,14 +502,7 @@ internal class LocalEchoEventFactory @Inject constructor( | |
| size = attachment.size | ||
| ), | ||
| url = attachment.queryUri.toString(), | ||
| relatesTo = rootThreadEventId?.let { | ||
| RelationDefaultContent( | ||
| type = RelationType.THREAD, | ||
| eventId = it, | ||
| isFallingBack = true, | ||
| inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(it)) | ||
| ) | ||
| } | ||
| relatesTo = relatesTo ?: rootThreadEventId?.let { generateThreadRelationContent(it) } | ||
| ) | ||
| return createMessageEvent(roomId, content) | ||
| } | ||
|
|
@@ -559,7 +554,7 @@ internal class LocalEchoEventFactory @Inject constructor( | |
| text: CharSequence, | ||
| msgType: String, | ||
| autoMarkdown: Boolean, | ||
| formattedText: String? | ||
| formattedText: String?, | ||
| ): Event { | ||
| val content = formattedText?.let { TextContent(text.toString(), it) } ?: createTextContent(text, autoMarkdown) | ||
| return createEvent( | ||
|
|
@@ -588,7 +583,7 @@ internal class LocalEchoEventFactory @Inject constructor( | |
| replyTextFormatted: CharSequence?, | ||
| autoMarkdown: Boolean, | ||
| rootThreadEventId: String? = null, | ||
| showInThread: Boolean | ||
| showInThread: Boolean, | ||
| ): Event? { | ||
| // Fallbacks and event representation | ||
| // TODO Add error/warning logs when any of this is null | ||
|
|
@@ -629,6 +624,14 @@ internal class LocalEchoEventFactory @Inject constructor( | |
| return createMessageEvent(roomId, content) | ||
| } | ||
|
|
||
| private fun generateThreadRelationContent(rootThreadEventId: String) = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for mutualizing this code! |
||
| RelationDefaultContent( | ||
| type = RelationType.THREAD, | ||
| eventId = rootThreadEventId, | ||
| isFallingBack = true, | ||
| inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(rootThreadEventId)), | ||
| ) | ||
|
|
||
| /** | ||
| * Generates the appropriate relatesTo object for a reply event. | ||
| * It can either be a regular reply or a reply within a thread | ||
|
|
@@ -772,7 +775,7 @@ internal class LocalEchoEventFactory @Inject constructor( | |
| text: String, | ||
| formattedText: String?, | ||
| autoMarkdown: Boolean, | ||
| rootThreadEventId: String? | ||
| rootThreadEventId: String?, | ||
| ): Event { | ||
| val messageContent = quotedEvent.getLastMessageContent() | ||
| val textMsg = if (messageContent is MessageContentWithFormattedBody) { messageContent.formattedBody } else { messageContent?.body } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * Copyright (c) 2022 New Vector Ltd | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package im.vector.app.core.di | ||
|
|
||
| import android.content.Context | ||
| import android.os.Build | ||
| import dagger.Module | ||
| import dagger.Provides | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.components.SingletonComponent | ||
| import im.vector.app.features.voicebroadcast.VoiceBroadcastRecorder | ||
| import im.vector.app.features.voicebroadcast.VoiceBroadcastRecorderQ | ||
| import javax.inject.Singleton | ||
|
|
||
| @Module | ||
| @InstallIn(SingletonComponent::class) | ||
| object VoiceModule { | ||
| @Provides | ||
| @Singleton | ||
| fun providesVoiceBroadcastRecorder(context: Context): VoiceBroadcastRecorder? { | ||
| return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { | ||
| VoiceBroadcastRecorderQ(context) | ||
| } else { | ||
| null | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not blocking but I am wondering if we should remove the
rootThreadEventIdparam and build therelatesToparam in case of threads at an upper level?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started considering this point but I am not sure it would make sense to build the
relatesTorelated to a thread in an upper level, IMO it makes sense to do it in the factory 😕