Clear up the room membership confusion around reading session members

This commit is contained in:
Robin
2025-09-24 21:39:36 -04:00
parent 6cf020763e
commit 530fbaf90a

View File

@@ -71,6 +71,7 @@ import {
MembershipManagerEvent, MembershipManagerEvent,
Status, Status,
} from "matrix-js-sdk/lib/matrixrtc"; } from "matrix-js-sdk/lib/matrixrtc";
import { type IWidgetApiRequest } from "matrix-widget-api";
import { ViewModel } from "./ViewModel"; import { ViewModel } from "./ViewModel";
import { import {
@@ -127,7 +128,6 @@ import { type MuteStates } from "./MuteStates";
import { getUrlParams } from "../UrlParams"; import { getUrlParams } from "../UrlParams";
import { type ProcessorState } from "../livekit/TrackProcessorContext"; import { type ProcessorState } from "../livekit/TrackProcessorContext";
import { ElementWidgetActions, widget } from "../widget"; import { ElementWidgetActions, widget } from "../widget";
import { IWidgetApiRequest } from "matrix-widget-api";
export interface CallViewModelOptions { export interface CallViewModelOptions {
encryptionSystem: EncryptionSystem; encryptionSystem: EncryptionSystem;
@@ -475,9 +475,11 @@ export class CallViewModel extends ViewModel {
), ),
); );
// TODO-MULTI-SFU make sure that we consider the room memberships here as well (so that here we only have valid memberships) /**
// this also makes it possible to use this memberships$ list in all observables based on it. * The MatrixRTC session participants.
// there should be no other call to: this.matrixRTCSession.memberships! */
// Note that MatrixRTCSession already filters the call memberships by users
// that are joined to the room; we don't need to perform extra filtering here.
public readonly memberships$ = this.scope.behavior( public readonly memberships$ = this.scope.behavior(
fromEvent( fromEvent(
this.matrixRTCSession, this.matrixRTCSession,
@@ -735,19 +737,17 @@ export class CallViewModel extends ViewModel {
// than on Chrome/Firefox). This means it is important that we multicast the result so that we // than on Chrome/Firefox). This means it is important that we multicast the result so that we
// don't do this work more times than we need to. This is achieved by converting to a behavior: // don't do this work more times than we need to. This is achieved by converting to a behavior:
public readonly memberDisplaynames$ = this.scope.behavior( public readonly memberDisplaynames$ = this.scope.behavior(
merge( combineLatest(
// Handle call membership changes. [
fromEvent( // Handle call membership changes
this.matrixRTCSession, this.memberships$,
MatrixRTCSessionEvent.MembershipsChanged, // Additionally handle display name changes (implicitly reacting to them)
), fromEvent(this.matrixRoom, RoomStateEvent.Members).pipe(
// Handle room membership changes (and displayname updates) startWith(null),
fromEvent(this.matrixRoom, RoomStateEvent.Members), ),
// TODO: do we need: pauseWhen(this.pretendToBeDisconnected$), // TODO: do we need: pauseWhen(this.pretendToBeDisconnected$),
).pipe( ],
startWith(null), (memberships, _displaynames) => {
map(() => {
const memberships = this.matrixRTCSession.memberships;
const displaynameMap = new Map<string, string>([ const displaynameMap = new Map<string, string>([
["local", this.matrixRoom.getMember(this.userId!)!.rawDisplayName], ["local", this.matrixRoom.getMember(this.userId!)!.rawDisplayName],
]); ]);
@@ -771,7 +771,7 @@ export class CallViewModel extends ViewModel {
); );
} }
return displaynameMap; return displaynameMap;
}), },
), ),
); );