-
Notifications
You must be signed in to change notification settings - Fork 756
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 Broadcast - Stop recording on app restart #7450
Changes from all commits
6eeb54a
53db04c
85bc78b
47047b2
ec80adc
2f14d19
5855fe1
443d573
23b4f6d
0cc2a47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[Voice Broadcast] Stop recording when opening the room after an app restart |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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.features.voicebroadcast.usecase | ||
|
||
import im.vector.app.core.di.ActiveSessionHolder | ||
import im.vector.app.features.voicebroadcast.VoiceBroadcastConstants | ||
import im.vector.app.features.voicebroadcast.model.VoiceBroadcastEvent | ||
import im.vector.app.features.voicebroadcast.model.VoiceBroadcastState | ||
import im.vector.app.features.voicebroadcast.model.asVoiceBroadcastEvent | ||
import org.matrix.android.sdk.api.query.QueryStringValue | ||
import org.matrix.android.sdk.api.session.getRoom | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
class GetOngoingVoiceBroadcastsUseCase @Inject constructor( | ||
private val activeSessionHolder: ActiveSessionHolder, | ||
) { | ||
|
||
fun execute(roomId: String): List<VoiceBroadcastEvent> { | ||
println("## GetOngoingVoiceBroadcastsUseCase") | ||
println("## GetOngoingVoiceBroadcastsUseCase activeSessionHolder $activeSessionHolder") | ||
val session = activeSessionHolder.getSafeActiveSession() | ||
println("## GetOngoingVoiceBroadcastsUseCase session $session") | ||
val room = session?.getRoom(roomId) ?: error("Unknown roomId: $roomId") | ||
println("## GetOngoingVoiceBroadcastsUseCase room $room") | ||
|
||
Timber.d("## GetLastVoiceBroadcastUseCase: get last voice broadcast in $roomId") | ||
|
||
return room.stateService().getStateEvents( | ||
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. I am wondering if we should use 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. @mnaturel Not sure, in Element, we cannot have more than one ongoing VB in a room. But "advanced users" or other clients are still allowed to send new state events with different state keys and we'll have several ongoing VB from several users... |
||
setOf(VoiceBroadcastConstants.STATE_ROOM_VOICE_BROADCAST_INFO), | ||
QueryStringValue.IsNotEmpty | ||
) | ||
.mapNotNull { it.asVoiceBroadcastEvent() } | ||
.filter { it.content?.voiceBroadcastState != null && it.content?.voiceBroadcastState != VoiceBroadcastState.STOPPED } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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.features.voicebroadcast.usecase | ||
|
||
import im.vector.app.core.di.ActiveSessionHolder | ||
import im.vector.app.features.voicebroadcast.VoiceBroadcastHelper | ||
import im.vector.app.features.voicebroadcast.model.asVoiceBroadcastEvent | ||
import org.matrix.android.sdk.api.query.QueryStringValue | ||
import org.matrix.android.sdk.api.session.getRoom | ||
import org.matrix.android.sdk.api.session.room.model.Membership | ||
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
/** | ||
* Stop ongoing voice broadcast if any. | ||
*/ | ||
class StopOngoingVoiceBroadcastUseCase @Inject constructor( | ||
private val activeSessionHolder: ActiveSessionHolder, | ||
private val getOngoingVoiceBroadcastsUseCase: GetOngoingVoiceBroadcastsUseCase, | ||
private val voiceBroadcastHelper: VoiceBroadcastHelper, | ||
) { | ||
|
||
suspend fun execute() { | ||
Timber.d("## StopOngoingVoiceBroadcastUseCase: Stop ongoing voice broadcast requested") | ||
|
||
val session = activeSessionHolder.getSafeActiveSession() ?: run { | ||
Timber.w("## StopOngoingVoiceBroadcastUseCase: no active session") | ||
return | ||
} | ||
// FIXME Iterate only on recent rooms for the moment, improve this | ||
val recentRooms = session.roomService() | ||
.getBreadcrumbs(roomSummaryQueryParams { | ||
displayName = QueryStringValue.NoCondition | ||
memberships = listOf(Membership.JOIN) | ||
}) | ||
.mapNotNull { session.getRoom(it.roomId) } | ||
|
||
recentRooms | ||
.forEach { room -> | ||
val ongoingVoiceBroadcasts = getOngoingVoiceBroadcastsUseCase.execute(room.roomId) | ||
val myOngoingVoiceBroadcastId = ongoingVoiceBroadcasts.find { it.root.stateKey == session.myUserId }?.reference?.eventId | ||
val initialEvent = myOngoingVoiceBroadcastId?.let { room.timelineService().getTimelineEvent(it)?.root?.asVoiceBroadcastEvent() } | ||
if (myOngoingVoiceBroadcastId != null && initialEvent?.content?.deviceId == session.sessionParams.deviceId) { | ||
voiceBroadcastHelper.stopVoiceBroadcast(room.roomId) | ||
return // No need to iterate more as we should not have more than one recording VB | ||
} | ||
} | ||
} | ||
} |
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.
Should we remove this
println
? If we want to keep some logs, we should useTimber
instead.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.
Good catch... will create a new PR
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.
#7458