Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 48224bb

Browse files
committed
Always show jitsi
(and other sticky widgets) in pip mode if they are not shown in any of the other widget containers.
1 parent 13028d3 commit 48224bb

File tree

2 files changed

+53
-12
lines changed

2 files changed

+53
-12
lines changed

src/components/views/elements/PersistentApp.tsx

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ import WidgetUtils from '../../../utils/WidgetUtils';
2525
import { MatrixClientPeg } from '../../../MatrixClientPeg';
2626
import { replaceableComponent } from "../../../utils/replaceableComponent";
2727
import AppTile from "./AppTile";
28+
import { Container, WidgetLayoutStore } from '../../../stores/widgets/WidgetLayoutStore';
29+
import RightPanelStore from '../../../stores/RightPanelStore';
30+
import { RightPanelPhases } from '../../../stores/RightPanelStorePhases';
31+
import dis from '../../../dispatcher/dispatcher';
32+
import { ActionPayload } from '../../../dispatcher/payloads';
33+
import { Action } from '../../../dispatcher/actions';
2834

2935
interface IProps {
3036
// none
@@ -33,22 +39,25 @@ interface IProps {
3339
interface IState {
3440
roomId: string;
3541
persistentWidgetId: string;
42+
rightPanelPhase?: RightPanelPhases;
3643
}
3744

3845
@replaceableComponent("views.elements.PersistentApp")
3946
export default class PersistentApp extends React.Component<IProps, IState> {
4047
private roomStoreToken: EventSubscription;
41-
48+
private dispatcherRef: string;
4249
constructor(props: IProps) {
4350
super(props);
4451

4552
this.state = {
4653
roomId: RoomViewStore.getRoomId(),
4754
persistentWidgetId: ActiveWidgetStore.instance.getPersistentWidgetId(),
55+
rightPanelPhase: RightPanelStore.getSharedInstance().roomPanelPhase,
4856
};
4957
}
5058

5159
public componentDidMount(): void {
60+
this.dispatcherRef = dis.register(this.onWidgetAction);
5261
this.roomStoreToken = RoomViewStore.addListener(this.onRoomViewStoreUpdate);
5362
ActiveWidgetStore.instance.on(ActiveWidgetStoreEvent.Update, this.onActiveWidgetStoreUpdate);
5463
MatrixClientPeg.get().on("Room.myMembership", this.onMyMembership);
@@ -58,6 +67,9 @@ export default class PersistentApp extends React.Component<IProps, IState> {
5867
if (this.roomStoreToken) {
5968
this.roomStoreToken.remove();
6069
}
70+
if (this.dispatcherRef) {
71+
dis.unregister(this.dispatcherRef);
72+
}
6173
ActiveWidgetStore.instance.removeListener(ActiveWidgetStoreEvent.Update, this.onActiveWidgetStoreUpdate);
6274
if (MatrixClientPeg.get()) {
6375
MatrixClientPeg.get().removeListener("Room.myMembership", this.onMyMembership);
@@ -71,6 +83,17 @@ export default class PersistentApp extends React.Component<IProps, IState> {
7183
});
7284
};
7385

86+
private onWidgetAction = (payload: ActionPayload): void => {
87+
switch (payload.action) {
88+
case Action.AfterRightPanelPhaseChange:
89+
this.setState({
90+
rightPanelPhase: RightPanelStore.getSharedInstance().roomPanelPhase,
91+
});
92+
break;
93+
default: break;
94+
}
95+
};
96+
7497
private onActiveWidgetStoreUpdate = (): void => {
7598
this.setState({
7699
persistentWidgetId: ActiveWidgetStore.instance.getPersistentWidgetId(),
@@ -88,17 +111,34 @@ export default class PersistentApp extends React.Component<IProps, IState> {
88111
};
89112

90113
public render(): JSX.Element {
91-
if (this.state.persistentWidgetId) {
92-
const persistentWidgetInRoomId = ActiveWidgetStore.instance.getRoomId(this.state.persistentWidgetId);
114+
const wId = this.state.persistentWidgetId;
115+
if (wId) {
116+
const persistentWidgetInRoomId = ActiveWidgetStore.instance.getRoomId(wId);
93117

94118
const persistentWidgetInRoom = MatrixClientPeg.get().getRoom(persistentWidgetInRoomId);
95119

96120
// Sanity check the room - the widget may have been destroyed between render cycles, and
97121
// thus no room is associated anymore.
98122
if (!persistentWidgetInRoom) return null;
99123

100-
const myMembership = persistentWidgetInRoom.getMyMembership();
101-
if (this.state.roomId !== persistentWidgetInRoomId && myMembership === "join") {
124+
const wls = WidgetLayoutStore.instance;
125+
126+
const userIsPartOfTheRoom = persistentWidgetInRoom.getMyMembership() == "join";
127+
const fromAnotherRoom = this.state.roomId !== persistentWidgetInRoomId;
128+
129+
const notInRightPanel =
130+
!(this.state.rightPanelPhase == RightPanelPhases.Widget &&
131+
wId == RightPanelStore.getSharedInstance().roomPanelPhaseParams?.widgetId);
132+
const notInCenterContainer =
133+
!wls.getContainerWidgets(persistentWidgetInRoom, Container.Center)
134+
.find((app)=>app.id == wId);
135+
const notInTopContainer =
136+
!wls.getContainerWidgets(persistentWidgetInRoom, Container.Top).find(app=>app.id == wId);
137+
if (
138+
//Show the persistent widget in two cases. The booleans have to be read like this: the widget is-`fromAnotherRoom`:
139+
(fromAnotherRoom && userIsPartOfTheRoom) ||
140+
(notInRightPanel && notInCenterContainer && notInTopContainer && userIsPartOfTheRoom)
141+
) {
102142
// get the widget data
103143
const appEvent = WidgetUtils.getRoomWidgets(persistentWidgetInRoom).find((ev) => {
104144
return ev.getStateKey() === ActiveWidgetStore.instance.getPersistentWidgetId();

src/components/views/voip/CallPreview.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,14 @@ export default class CallPreview extends React.Component<IProps, IState> {
197197
draggable={pipMode}
198198
onDoubleClick={this.onDoubleClick}
199199
>
200-
{ ({ onStartMoving, onResize }) => <CallView
201-
onMouseDownOnHeader={onStartMoving}
202-
call={this.state.primaryCall}
203-
secondaryCall={this.state.secondaryCall}
204-
pipMode={pipMode}
205-
onResize={onResize}
206-
/> }
200+
{ ({ onStartMoving, onResize }) =>
201+
<CallView
202+
onMouseDownOnHeader={onStartMoving}
203+
call={this.state.primaryCall}
204+
secondaryCall={this.state.secondaryCall}
205+
pipMode={pipMode}
206+
onResize={onResize}
207+
/> }
207208
</PictureInPictureDragger>
208209

209210
);

0 commit comments

Comments
 (0)