Use if statement instead of ternary for readability in spotlight and pip logic

This commit is contained in:
Hugh Nimmo-Smith
2024-12-02 14:35:33 +00:00
parent 33f398ddcf
commit 7fdcbb3292
+41 -31
View File
@@ -632,49 +632,59 @@ export class CallViewModel extends ViewModel {
private readonly spotlight: Observable<MediaViewModel[]> = private readonly spotlight: Observable<MediaViewModel[]> =
this.screenShares.pipe( this.screenShares.pipe(
switchMap((screenShares) => switchMap((screenShares) => {
screenShares.length > 0 if (screenShares.length > 0) {
? of(screenShares.map((m) => m.vm)) return of(screenShares.map((m) => m.vm));
: this.spotlightSpeaker.pipe( }
return this.spotlightSpeaker.pipe(
map((speaker) => (speaker ? [speaker] : [])), map((speaker) => (speaker ? [speaker] : [])),
), );
), }),
this.scope.state(), this.scope.state(),
); );
private readonly pip: Observable<UserMediaViewModel | null> = private readonly pip: Observable<UserMediaViewModel | null> =
this.screenShares.pipe( this.screenShares.pipe(
switchMap((screenShares) => switchMap((screenShares) => {
screenShares.length > 0 if (screenShares.length > 0) {
? this.spotlightSpeaker return this.spotlightSpeaker;
: this.spotlightSpeaker.pipe( }
switchMap((speaker) =>
speaker return this.spotlightSpeaker.pipe(
? speaker.local switchMap((speaker) => {
? of(null) if (!speaker || speaker.local) {
: this.mediaItems.pipe( return of(null);
}
return this.mediaItems.pipe(
switchMap((mediaItems) => { switchMap((mediaItems) => {
const localUserMedia = mediaItems.find( const localUserMedia = mediaItems.find(
(m) => m.vm instanceof LocalUserMediaViewModel, (m) => m.vm instanceof LocalUserMediaViewModel,
) as UserMedia | undefined; ) as UserMedia | undefined;
return (
( const localUserMediaViewModel = localUserMedia?.vm as
localUserMedia?.vm as LocalUserMediaViewModel | LocalUserMediaViewModel
).alwaysShow.pipe( | undefined;
map(
(alwaysShow) => if (!localUserMediaViewModel) {
(alwaysShow return of(null);
? localUserMedia?.vm }
: undefined) ?? null,
), return localUserMediaViewModel.alwaysShow.pipe(
) ?? of(null) map((alwaysShow) => {
if (alwaysShow) {
return localUserMediaViewModel;
}
return null;
}),
);
}),
);
}),
); );
}), }),
)
: of(null),
),
),
),
this.scope.state(), this.scope.state(),
); );