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 Broadcast - Handle event deletion when listening or recording #7629

Merged
merged 12 commits into from
Nov 29, 2022

Conversation

Florian14
Copy link
Contributor

@Florian14 Florian14 commented Nov 23, 2022

Type of change

  • WIP Feature
  • Bugfix
  • Technical
  • Other :

Content

Handle the deletion of a voice broadcast state event on the recorder and the listener sides.

  • Improve the voice broadcast state observation by handling the event redaction.
  • Stop listening to this VB as soon as the started event is redacted
  • Stop recording this VB as soon as the started event is redacted
  • The recorder now reacts to the state event changes (previously, we sent the state event and did the action on the recorder at the same time)

Motivation and context

Continue #7127

Screenshots / GIFs

Tests

  • Show hidden events in the timeline (advanced settings -> developer mode)
  • Record a VB with several state events (started/paused/resumed/stopped) and verify that the tile in the timeline is correctly updated on listener and recorder sides
  • Redact some state events and verify that the tile is always displayed according to the most recent not redacted state event
  • When redacting the started state event (behind the tile), the tile should be removed

Test again during recording and listening to the VB, delete the started event should stop the action.

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

@Florian14 Florian14 requested review from a team and mnaturel and removed request for a team November 23, 2022 16:56
@Florian14 Florian14 marked this pull request as ready for review November 23, 2022 16:56
) : AbstractVoiceRecorderQ(context), VoiceBroadcastRecorder {

private val session get() = sessionHolder.getActiveSession()
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you considered it may throw an exception when getting the session variable?

@@ -31,8 +30,7 @@ import timber.log.Timber
import javax.inject.Inject

class ResumeVoiceBroadcastUseCase @Inject constructor(
private val session: Session,
private val voiceBroadcastRecorder: VoiceBroadcastRecorder?,
private val session: Session
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we keep the trailing comma?

@@ -31,7 +32,7 @@ interface VoiceBroadcastRecorder : VoiceRecorder {
/** Current remaining time of recording, in seconds, if any. */
val currentRemainingTime: Long?

fun startRecord(roomId: String, chunkLength: Int, maxLength: Int)
fun startRecordVoiceBroadcast(voiceBroadcast: VoiceBroadcast, chunkLength: Int, maxLength: Int)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we need to add VoiceBroadcast in the name of the method? I personnally think this is enough with startRecord since first parameter is a VoiceBroadcast.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My problem is that I want to distinguish this method from the startRecord which is inherited from VoiceRecorder to avoid confusion. Ideally, I would like to only expose this one to the outside and change the visibility of the other method to "protected", but afaik I can do it programmatically but this is a bit ugly imo. Wdyt @mnaturel?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. I didn't see the method in the VoiceRecorder Interface. Let's keep it like this then.

@@ -79,13 +84,15 @@ class StartVoiceBroadcastUseCase @Inject constructor(
).toContent()
)

startRecording(room, eventId, chunkLength, maxLength)
val voiceBroadcast = VoiceBroadcast(roomId = room.roomId, voiceBroadcastId = eventId)
room.flow().liveTimelineEvent(eventId).unwrap().first() // wait for the event come back from the sync
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to update the related unit tests to take this change into account.

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 tried but I was stuck with an infinite loading on the Flow, I added a todo to not forget to update the related test

import timber.log.Timber
import javax.inject.Inject

class GetMostRecentVoiceBroadcastStateEventUseCase @Inject constructor(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this use case needs some unit tests.

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 suggest doing it in a dedicated PR to unblock this one, I created an issue with the missing tests to track this one

flowOf(Optional.empty())
} else {
// otherwise, observe most recent event changes
getMostRecentRelatedEventFlow(room, voiceBroadcast)
Copy link
Contributor

@mnaturel mnaturel Nov 24, 2022

Choose a reason for hiding this comment

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

Have you thought about this way of writing this logic?

getMostRecentRelatedEventFlow(room, voiceBroadcast)
                                .transformWhile { mostRecentEvent ->
                                    val hasValue = mostRecentEvent.hasValue()
                                    if(hasValue) {
                                        // keep the most recent event
                                        emit(mostRecentEvent)
                                    } else {
                                        // no most recent event, fallback to started event
                                        emit(startedEvent)
                                    }
                                    hasValue
                                }

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 definitely prefer this format, updated aa53105

event.hasValue() && event.get().root.isRedacted().not()
}
.flatMapLatest { event ->
if (event.getOrNull()?.root?.isRedacted().orFalse()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What was your intention when event is null? The comment says it should be in this if branch but using orFalse means it will go through the else branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you're right, I fixed and rewrote the condition for better clarity

Copy link
Contributor

@mnaturel mnaturel left a comment

Choose a reason for hiding this comment

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

I have added some small comments.
Just a general thought about redaction of voice broadcast events. For the default user, when pressing the "Remove" button on a voice broadcast, it seems it only redacts the started event. It is intended? I expected it redacts every associated events of the given voice broadcast (message events + state events).

@Florian14 Florian14 force-pushed the feature/fre/voice_broadcast_deletion branch 3 times, most recently from f59be73 to a8f3bb1 Compare November 25, 2022 13:45
@Florian14 Florian14 force-pushed the feature/fre/voice_broadcast_handle_event_deletion branch from 0e74402 to 81a2a10 Compare November 25, 2022 14:38
Base automatically changed from feature/fre/voice_broadcast_deletion to develop November 28, 2022 12:57
@Florian14 Florian14 force-pushed the feature/fre/voice_broadcast_handle_event_deletion branch from 81a2a10 to f85f4cf Compare November 28, 2022 15:03
@Florian14 Florian14 force-pushed the feature/fre/voice_broadcast_handle_event_deletion branch from f85f4cf to 620bebc Compare November 28, 2022 15:08
@Florian14 Florian14 requested a review from mnaturel November 28, 2022 15:54
@sonarcloud
Copy link

sonarcloud bot commented Nov 28, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

6.9% 6.9% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@mnaturel mnaturel 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 for the updates!
I have just a general question: I have seen when removing from the tile of a voice broadcast, it actually doesn't remove all the related events like messages or related state events to the original event. As a user, I would expect it redacts every related events to the selected voice broadcast. Can you confirm it will be implemented this way in the future?

@Florian14
Copy link
Contributor Author

LGTM. Thanks for the updates! I have just a general question: I have seen when removing from the tile of a voice broadcast, it actually doesn't remove all the related events like messages or related state events to the original event. As a user, I would expect it redacts every related events to the selected voice broadcast. Can you confirm it will be implemented this way in the future?

Sorry, I forgot to answer this question, indeed it is not done for the moment but we'll implement the proper redaction of all the related events in a dedicated PR by using this MSC

@Florian14 Florian14 merged commit d6fd32b into develop Nov 29, 2022
@Florian14 Florian14 deleted the feature/fre/voice_broadcast_handle_event_deletion branch November 29, 2022 08:51
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.

2 participants