From fd71bca7c0af97ab496a3d320900498256af0dc4 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 26 Aug 2020 10:33:05 -0600 Subject: [PATCH 1/4] Change menu label if in a community --- src/components/views/rooms/RoomList.tsx | 5 ++++- src/i18n/strings/en_EN.json | 1 + src/stores/TagOrderStore.js | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/views/rooms/RoomList.tsx b/src/components/views/rooms/RoomList.tsx index 3274e0e49f..92c5982276 100644 --- a/src/components/views/rooms/RoomList.tsx +++ b/src/components/views/rooms/RoomList.tsx @@ -45,6 +45,7 @@ import { arrayFastClone, arrayHasDiff } from "../../../utils/arrays"; import { objectShallowClone, objectWithOnly } from "../../../utils/objects"; import { IconizedContextMenuOption, IconizedContextMenuOptionList } from "../context_menus/IconizedContextMenu"; import AccessibleButton from "../elements/AccessibleButton"; +import TagOrderStore from "../../../stores/TagOrderStore"; interface IProps { onKeyDown: (ev: React.KeyboardEvent) => void; @@ -129,7 +130,9 @@ const TAG_AESTHETICS: { }} /> { e.preventDefault(); diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index d6ba736a76..da4e298f0f 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1121,6 +1121,7 @@ "Rooms": "Rooms", "Add room": "Add room", "Create new room": "Create new room", + "Explore community rooms": "Explore community rooms", "Explore public rooms": "Explore public rooms", "Low priority": "Low priority", "System Alerts": "System Alerts", diff --git a/src/stores/TagOrderStore.js b/src/stores/TagOrderStore.js index f02fce0769..2eb35e6dc2 100644 --- a/src/stores/TagOrderStore.js +++ b/src/stores/TagOrderStore.js @@ -285,6 +285,13 @@ class TagOrderStore extends Store { getSelectedTags() { return this._state.selectedTags; } + + getSelectedPrototypeTag() { + if (SettingsStore.getValue("feature_communities_v2_prototypes")) { + return this.getSelectedTags()[0]; + } + return null; // no selection as far as this function is concerned + } } if (global.singletonTagOrderStore === undefined) { From c28134eb11bb3f1fab540c83cf9a512d1209f3e0 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 26 Aug 2020 10:53:06 -0600 Subject: [PATCH 2/4] Associate created rooms with the selected community --- src/components/views/dialogs/CreateRoomDialog.js | 13 ++++++++++++- src/createRoom.ts | 6 ++++++ src/i18n/strings/en_EN.json | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/components/views/dialogs/CreateRoomDialog.js b/src/components/views/dialogs/CreateRoomDialog.js index ce7ac6e59c..9726c44fac 100644 --- a/src/components/views/dialogs/CreateRoomDialog.js +++ b/src/components/views/dialogs/CreateRoomDialog.js @@ -25,6 +25,8 @@ import { _t } from '../../../languageHandler'; import {MatrixClientPeg} from '../../../MatrixClientPeg'; import {Key} from "../../../Keyboard"; import {privateShouldBeEncrypted} from "../../../createRoom"; +import TagOrderStore from "../../../stores/TagOrderStore"; +import GroupStore from "../../../stores/GroupStore"; export default createReactClass({ displayName: 'CreateRoomDialog', @@ -70,6 +72,10 @@ export default createReactClass({ opts.encryption = this.state.isEncrypted; } + if (TagOrderStore.getSelectedPrototypeTag()) { + opts.associatedWithCommunity = TagOrderStore.getSelectedPrototypeTag(); + } + return opts; }, @@ -212,7 +218,12 @@ export default createReactClass({ ; } - const title = this.state.isPublic ? _t('Create a public room') : _t('Create a private room'); + let title = this.state.isPublic ? _t('Create a public room') : _t('Create a private room'); + if (TagOrderStore.getSelectedPrototypeTag()) { + const summary = GroupStore.getSummary(TagOrderStore.getSelectedPrototypeTag()); + const name = summary?.profile?.name || TagOrderStore.getSelectedPrototypeTag(); + title = _t("Create a room in %(communityName)s", {communityName: name}); + } return ( { } else { return Promise.resolve(); } + }).then(() => { + if (opts.associatedWithCommunity) { + return GroupStore.addRoomToGroup(opts.associatedWithCommunity, roomId, false); + } }).then(function() { // NB createRoom doesn't block on the client seeing the echo that the // room has been created, so we race here with the client knowing that diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index da4e298f0f..0ec12a4d6a 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1643,6 +1643,7 @@ "Enable end-to-end encryption": "Enable end-to-end encryption", "Create a public room": "Create a public room", "Create a private room": "Create a private room", + "Create a room in %(communityName)s": "Create a room in %(communityName)s", "Name": "Name", "Topic (optional)": "Topic (optional)", "Make this room public": "Make this room public", From 027f263589a767830120b18b83829d8ca8c42bab Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 26 Aug 2020 11:01:58 -0600 Subject: [PATCH 3/4] Remove prototype code from CreateGroupDialog The prototype code paths prevent users from ending up here, so we don't need custom code. --- .../views/dialogs/CreateGroupDialog.js | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/src/components/views/dialogs/CreateGroupDialog.js b/src/components/views/dialogs/CreateGroupDialog.js index 2b22054947..10285ccee0 100644 --- a/src/components/views/dialogs/CreateGroupDialog.js +++ b/src/components/views/dialogs/CreateGroupDialog.js @@ -83,25 +83,11 @@ export default createReactClass({ localpart: this.state.groupId, profile: profile, }).then((result) => { - if (result.room_id) { - dis.dispatch({ - action: 'view_room', - room_id: result.room_id, - }); - - // Ensure the tag gets selected now that we've created it - dis.dispatch({action: 'deselect_tags'}, true); - dis.dispatch({ - action: 'select_tag', - tag: result.group_id, - }); - } else { - dis.dispatch({ - action: 'view_group', - group_id: result.group_id, - group_is_new: true, - }); - } + dis.dispatch({ + action: 'view_group', + group_id: result.group_id, + group_is_new: true, + }); this.props.onFinished(true); }).catch((e) => { this.setState({createError: e}); From 4f29770adb8880e451067d58574b6d1f06e02de1 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 26 Aug 2020 11:02:14 -0600 Subject: [PATCH 4/4] Force the GroupStore to update after creating a prototype community --- .../views/dialogs/CreateCommunityPrototypeDialog.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/views/dialogs/CreateCommunityPrototypeDialog.tsx b/src/components/views/dialogs/CreateCommunityPrototypeDialog.tsx index 5f8321fd7d..58412c23d6 100644 --- a/src/components/views/dialogs/CreateCommunityPrototypeDialog.tsx +++ b/src/components/views/dialogs/CreateCommunityPrototypeDialog.tsx @@ -24,6 +24,7 @@ import { MatrixClientPeg } from "../../../MatrixClientPeg"; import InfoTooltip from "../elements/InfoTooltip"; import dis from "../../../dispatcher/dispatcher"; import {showCommunityRoomInviteDialog} from "../../../RoomInvite"; +import GroupStore from "../../../stores/GroupStore"; interface IProps extends IDialogProps { } @@ -92,6 +93,8 @@ export default class CreateCommunityPrototypeDialog extends React.PureComponent< this.props.onFinished(true); if (result.room_id) { + // Force the group store to update as it might have missed the general chat + await GroupStore.refreshGroupRooms(result.group_id); dis.dispatch({ action: 'view_room', room_id: result.room_id,