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

Commit 68948d4

Browse files
authored
Merge pull request #4959 from matrix-org/t3chguy/room-list/14436
Fix room tile context menu for Historical rooms
2 parents ea15725 + 3060cdf commit 68948d4

File tree

4 files changed

+50
-16
lines changed

4 files changed

+50
-16
lines changed

src/components/structures/MatrixChat.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import PageTypes from '../../PageTypes';
5050
import { getHomePageUrl } from '../../utils/pages';
5151

5252
import createRoom from "../../createRoom";
53-
import { _t, getCurrentLanguage } from '../../languageHandler';
53+
import {_t, _td, getCurrentLanguage} from '../../languageHandler';
5454
import SettingsStore, { SettingLevel } from "../../settings/SettingsStore";
5555
import ThemeController from "../../settings/controllers/ThemeController";
5656
import { startAnyRegistrationFlow } from "../../Registration.js";
@@ -74,6 +74,7 @@ import {
7474
} from "../../toasts/AnalyticsToast";
7575
import {showToast as showNotificationsToast} from "../../toasts/DesktopNotificationsToast";
7676
import { OpenToTabPayload } from "../../dispatcher/payloads/OpenToTabPayload";
77+
import ErrorDialog from "../views/dialogs/ErrorDialog";
7778

7879
/** constants for MatrixChat.state.view */
7980
export enum Views {
@@ -460,7 +461,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
460461

461462
onAction = (payload) => {
462463
// console.log(`MatrixClientPeg.onAction: ${payload.action}`);
463-
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
464464
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
465465

466466
// Start the onboarding process for certain actions
@@ -554,6 +554,9 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
554554
case 'leave_room':
555555
this.leaveRoom(payload.room_id);
556556
break;
557+
case 'forget_room':
558+
this.forgetRoom(payload.room_id);
559+
break;
557560
case 'reject_invite':
558561
Modal.createTrackedDialog('Reject invitation', '', QuestionDialog, {
559562
title: _t('Reject invitation'),
@@ -1060,7 +1063,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
10601063

10611064
private leaveRoom(roomId: string) {
10621065
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
1063-
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
10641066
const roomToLeave = MatrixClientPeg.get().getRoom(roomId);
10651067
const warnings = this.leaveRoomWarnings(roomId);
10661068

@@ -1124,6 +1126,21 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
11241126
});
11251127
}
11261128

1129+
private forgetRoom(roomId: string) {
1130+
MatrixClientPeg.get().forget(roomId).then(() => {
1131+
// Switch to another room view if we're currently viewing the historical room
1132+
if (this.state.currentRoomId === roomId) {
1133+
dis.dispatch({ action: "view_next_room" });
1134+
}
1135+
}).catch((err) => {
1136+
const errCode = err.errcode || _td("unknown error code");
1137+
Modal.createTrackedDialog("Failed to forget room", '', ErrorDialog, {
1138+
title: _t("Failed to forget room %(errCode)s", {errCode}),
1139+
description: ((err && err.message) ? err.message : _t("Operation failed")),
1140+
});
1141+
});
1142+
}
1143+
11271144
/**
11281145
* Starts a chat with the welcome user, if the user doesn't already have one
11291146
* @returns {string} The room ID of the new room, or null if no room was created
@@ -1372,7 +1389,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
13721389
return;
13731390
}
13741391

1375-
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
13761392
Modal.createTrackedDialog('Signed out', '', ErrorDialog, {
13771393
title: _t('Signed Out'),
13781394
description: _t('For security, this session has been signed out. Please sign in again.'),
@@ -1442,7 +1458,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
14421458
}
14431459
});
14441460
cli.on("crypto.warning", (type) => {
1445-
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
14461461
switch (type) {
14471462
case 'CRYPTO_WARNING_OLD_VERSION_DETECTED':
14481463
Modal.createTrackedDialog('Crypto migrated', '', ErrorDialog, {

src/components/structures/RoomView.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,15 +1380,9 @@ export default createReactClass({
13801380
},
13811381

13821382
onForgetClick: function() {
1383-
this.context.forget(this.state.room.roomId).then(function() {
1384-
dis.dispatch({ action: 'view_next_room' });
1385-
}, function(err) {
1386-
const errCode = err.errcode || _t("unknown error code");
1387-
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
1388-
Modal.createTrackedDialog('Failed to forget room', '', ErrorDialog, {
1389-
title: _t("Error"),
1390-
description: _t("Failed to forget room %(errCode)s", { errCode: errCode }),
1391-
});
1383+
dis.dispatch({
1384+
action: 'forget_room',
1385+
room_id: this.state.room.roomId,
13921386
});
13931387
},
13941388

src/components/views/rooms/RoomTile2.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,17 @@ export default class RoomTile2 extends React.Component<IProps, IState> {
276276
this.setState({generalMenuPosition: null}); // hide the menu
277277
};
278278

279+
private onForgetRoomClick = (ev: ButtonEvent) => {
280+
ev.preventDefault();
281+
ev.stopPropagation();
282+
283+
dis.dispatch({
284+
action: 'forget_room',
285+
room_id: this.props.room.roomId,
286+
});
287+
this.setState({generalMenuPosition: null}); // hide the menu
288+
};
289+
279290
private onOpenRoomSettings = (ev: ButtonEvent) => {
280291
ev.preventDefault();
281292
ev.stopPropagation();
@@ -315,7 +326,7 @@ export default class RoomTile2 extends React.Component<IProps, IState> {
315326
private onClickMute = ev => this.saveNotifState(ev, MUTE);
316327

317328
private renderNotificationsMenu(isActive: boolean): React.ReactElement {
318-
if (MatrixClientPeg.get().isGuest() || !this.showContextMenu) {
329+
if (MatrixClientPeg.get().isGuest() || this.props.tag === DefaultTagID.Archived || !this.showContextMenu) {
319330
// the menu makes no sense in these cases so do not show one
320331
return null;
321332
}
@@ -397,7 +408,20 @@ export default class RoomTile2 extends React.Component<IProps, IState> {
397408
const favouriteLabel = isFavorite ? _t("Favourited") : _t("Favourite");
398409

399410
let contextMenu = null;
400-
if (this.state.generalMenuPosition) {
411+
if (this.state.generalMenuPosition && this.props.tag === DefaultTagID.Archived) {
412+
contextMenu = (
413+
<ContextMenu {...contextMenuBelow(this.state.generalMenuPosition)} onFinished={this.onCloseGeneralMenu}>
414+
<div className="mx_IconizedContextMenu mx_IconizedContextMenu_compact mx_RoomTile2_contextMenu">
415+
<div className="mx_IconizedContextMenu_optionList mx_RoomTile2_contextMenu_redRow">
416+
<MenuItem onClick={this.onForgetRoomClick} label={_t("Leave Room")}>
417+
<span className="mx_IconizedContextMenu_icon mx_RoomTile2_iconSignOut" />
418+
<span className="mx_IconizedContextMenu_label">{_t("Forget Room")}</span>
419+
</MenuItem>
420+
</div>
421+
</div>
422+
</ContextMenu>
423+
);
424+
} else if (this.state.generalMenuPosition) {
401425
contextMenu = (
402426
<ContextMenu {...contextMenuBelow(this.state.generalMenuPosition)} onFinished={this.onCloseGeneralMenu}>
403427
<div className="mx_IconizedContextMenu mx_IconizedContextMenu_compact mx_RoomTile2_contextMenu">

src/i18n/strings/en_EN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,7 @@
12331233
"Favourited": "Favourited",
12341234
"Favourite": "Favourite",
12351235
"Leave Room": "Leave Room",
1236+
"Forget Room": "Forget Room",
12361237
"Room options": "Room options",
12371238
"Add a topic": "Add a topic",
12381239
"Upgrading this room will shut down the current instance of the room and create an upgraded room with the same name.": "Upgrading this room will shut down the current instance of the room and create an upgraded room with the same name.",

0 commit comments

Comments
 (0)