From ab4220b20d98d4e47574f945baee64bbf2ec3b48 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 4 Mar 2021 13:04:58 +0000 Subject: [PATCH] Defer auto-joining within spaces and switch to using `suggested` --- .../structures/SpaceRoomDirectory.tsx | 33 ++++++++++--------- src/i18n/strings/en_EN.json | 2 +- src/stores/SpaceStore.tsx | 3 +- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/components/structures/SpaceRoomDirectory.tsx b/src/components/structures/SpaceRoomDirectory.tsx index 7f7b9dbb99..0a59ac0195 100644 --- a/src/components/structures/SpaceRoomDirectory.tsx +++ b/src/components/structures/SpaceRoomDirectory.tsx @@ -64,6 +64,7 @@ export interface ISpaceSummaryEvent { state_key: string; content: { order?: string; + suggested?: boolean; auto_join?: boolean; via?: string; }; @@ -91,7 +92,7 @@ const SubSpace: React.FC = ({ const name = space.name || space.canonical_alias || space.aliases?.[0] || _t("Unnamed Space"); const evContent = event?.getContent(); - const [autoJoin, _setAutoJoin] = useState(evContent?.auto_join); + const [suggested, _setSuggested] = useState(evContent?.suggested); const [removed, _setRemoved] = useState(!evContent?.via); const cli = MatrixClientPeg.get(); @@ -102,12 +103,12 @@ const SubSpace: React.FC = ({ let actions; if (editing && queueAction) { if (event && cli.getRoom(event.getRoomId())?.currentState.maySendStateEvent(event.getType(), cli.getUserId())) { - const setAutoJoin = () => { - _setAutoJoin(v => { + const setSuggested = () => { + _setSuggested(v => { queueAction({ event, removed, - autoJoin: !v, + suggested: !v, }); return !v; }); @@ -118,7 +119,7 @@ const SubSpace: React.FC = ({ queueAction({ event, removed: !v, - autoJoin, + suggested, }); return !v; }); @@ -131,7 +132,7 @@ const SubSpace: React.FC = ({ } else { actions = - + ; } } else { @@ -180,8 +181,8 @@ const SubSpace: React.FC = ({ interface IAction { event: MatrixEvent; + suggested: boolean; removed: boolean; - autoJoin: boolean; } interface IRoomTileProps { @@ -197,7 +198,7 @@ const RoomTile = ({ room, event, editing, queueAction, onPreviewClick, onJoinCli const name = room.name || room.canonical_alias || room.aliases?.[0] || _t("Unnamed Room"); const evContent = event?.getContent(); - const [autoJoin, _setAutoJoin] = useState(evContent?.auto_join); + const [suggested, _setSuggested] = useState(evContent?.suggested); const [removed, _setRemoved] = useState(!evContent?.via); const cli = MatrixClientPeg.get(); @@ -207,12 +208,12 @@ const RoomTile = ({ room, event, editing, queueAction, onPreviewClick, onJoinCli let actions; if (editing && queueAction) { if (event && cli.getRoom(event.getRoomId())?.currentState.maySendStateEvent(event.getType(), cli.getUserId())) { - const setAutoJoin = () => { - _setAutoJoin(v => { + const setSuggested = () => { + _setSuggested(v => { queueAction({ event, removed, - autoJoin: !v, + suggested: !v, }); return !v; }); @@ -223,7 +224,7 @@ const RoomTile = ({ room, event, editing, queueAction, onPreviewClick, onJoinCli queueAction({ event, removed: !v, - autoJoin, + suggested, }); return !v; }); @@ -236,7 +237,7 @@ const RoomTile = ({ room, event, editing, queueAction, onPreviewClick, onJoinCli } else { actions = - + ; } } else { @@ -441,10 +442,10 @@ const SpaceRoomDirectory: React.FC = ({ space, initialText = "", onFinis const onSaveButtonClicked = () => { // TODO setBusy - pendingActions.current.forEach(({event, autoJoin, removed}) => { + pendingActions.current.forEach(({event, suggested, removed}) => { const content = { ...event.getContent(), - auto_join: autoJoin, + suggested, }; if (removed) { @@ -459,7 +460,7 @@ const SpaceRoomDirectory: React.FC = ({ space, initialText = "", onFinis if (isEditing) { adminButton = - { _t("All users join by default") } + { _t("Promoted to users") } ; } else { adminButton = ; diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index e256e6bb2f..7b680b6590 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -2596,7 +2596,7 @@ "You're in this space": "You're in this space", "You're in this room": "You're in this room", "Save changes": "Save changes", - "All users join by default": "All users join by default", + "Promoted to users": "Promoted to users", "Manage rooms": "Manage rooms", "Find a room...": "Find a room...", "Accept Invite": "Accept Invite", diff --git a/src/stores/SpaceStore.tsx b/src/stores/SpaceStore.tsx index 8e0066da91..c334144d70 100644 --- a/src/stores/SpaceStore.tsx +++ b/src/stores/SpaceStore.tsx @@ -108,9 +108,10 @@ export class SpaceStoreClass extends AsyncStoreWithClient { } } - public addRoomToSpace(space: Room, roomId: string, via: string[], autoJoin = false) { + public addRoomToSpace(space: Room, roomId: string, via: string[], suggested = false, autoJoin = false) { return this.matrixClient.sendStateEvent(space.roomId, EventType.SpaceChild, { via, + suggested, auto_join: autoJoin, }, roomId); }