From 7b98fe81a72419c7a4ed0d1936cf3b9c1071cabd Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 19 Nov 2021 10:49:23 +0000 Subject: [PATCH 1/3] Show room context details in forward dialog --- res/css/views/dialogs/_ForwardDialog.scss | 16 ++++++-- .../views/dialogs/ForwardDialog.tsx | 6 +++ src/i18n/strings/en_EN.json | 3 ++ src/utils/Room.ts | 38 +++++++++++++++++++ 4 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 src/utils/Room.ts diff --git a/res/css/views/dialogs/_ForwardDialog.scss b/res/css/views/dialogs/_ForwardDialog.scss index 97cd8b87879..d36875093d3 100644 --- a/res/css/views/dialogs/_ForwardDialog.scss +++ b/res/css/views/dialogs/_ForwardDialog.scss @@ -110,18 +110,28 @@ limitations under the License. margin-right: 12px; } - .mx_ForwardList_entry_name { - font-size: $font-15px; + .mx_ForwardList_entry_name, + .mx_ForwardList_entry_detail { line-height: 30px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; - margin-right: 12px; + } + + .mx_ForwardList_entry_name { + font-size: $font-15px; + } + + .mx_ForwardList_entry_detail { + font-size: $font-12px; + margin-left: 8px; + color: $tertiary-content; } } .mx_ForwardList_sendButton { position: relative; + margin-left: 12px; &:not(.mx_ForwardList_canSend) .mx_ForwardList_sendLabel { // Hide the "Send" label while preserving button size diff --git a/src/components/views/dialogs/ForwardDialog.tsx b/src/components/views/dialogs/ForwardDialog.tsx index c3e1848b11b..a4aa1a120c8 100644 --- a/src/components/views/dialogs/ForwardDialog.tsx +++ b/src/components/views/dialogs/ForwardDialog.tsx @@ -44,6 +44,7 @@ import TruncatedList from "../elements/TruncatedList"; import EntityTile from "../rooms/EntityTile"; import BaseAvatar from "../avatars/BaseAvatar"; import SpaceStore from "../../../stores/spaces/SpaceStore"; +import { roomContextDetailsText } from "../../../utils/Room"; const AVATAR_SIZE = 30; @@ -121,6 +122,8 @@ const Entry: React.FC = ({ room, event, matrixClient: cli, onFinish />; } + const detailsText = roomContextDetailsText(room); + return
= ({ room, event, matrixClient: cli, onFinish > { room.name } + { detailsText && + { detailsText } + } Date: Fri, 19 Nov 2021 10:51:47 +0000 Subject: [PATCH 2/3] outdent --- src/utils/Room.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/utils/Room.ts b/src/utils/Room.ts index 9347634457e..00172c31487 100644 --- a/src/utils/Room.ts +++ b/src/utils/Room.ts @@ -21,18 +21,18 @@ import DMRoomMap from "./DMRoomMap"; import { _t } from "../languageHandler"; export function roomContextDetailsText(room: Room): string { - if (!room.isSpaceRoom()) { - const dmPartner = DMRoomMap.shared().getUserIdForRoomId(room.roomId); - if (dmPartner) { - return room.getMember(dmPartner)?.name; - } - - const [parent, ...otherParents] = SpaceStore.instance.getKnownParents(room.roomId); - if (parent) { - return _t("%(spaceName)s and %(count)s others", { - spaceName: room.client.getRoom(parent).name, - count: otherParents.length, - }); - } + if (room.isSpaceRoom()) return undefined; + + const dmPartner = DMRoomMap.shared().getUserIdForRoomId(room.roomId); + if (dmPartner) { + return room.getMember(dmPartner)?.name; + } + + const [parent, ...otherParents] = SpaceStore.instance.getKnownParents(room.roomId); + if (parent) { + return _t("%(spaceName)s and %(count)s others", { + spaceName: room.client.getRoom(parent).name, + count: otherParents.length, + }); } } From 88b3e389cf6ed92b9406342c9e4a2ef27fffb783 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 19 Nov 2021 17:34:13 +0000 Subject: [PATCH 3/3] move method into a more appropriate file --- src/Rooms.ts | 26 ++++++++++++- .../views/dialogs/ForwardDialog.tsx | 2 +- src/utils/Room.ts | 38 ------------------- 3 files changed, 25 insertions(+), 41 deletions(-) delete mode 100644 src/utils/Room.ts diff --git a/src/Rooms.ts b/src/Rooms.ts index 6e2fd4d3a24..fbea536fafc 100644 --- a/src/Rooms.ts +++ b/src/Rooms.ts @@ -18,6 +18,9 @@ import { Room } from "matrix-js-sdk/src/models/room"; import { MatrixClientPeg } from './MatrixClientPeg'; import AliasCustomisations from './customisations/Alias'; +import DMRoomMap from "./utils/DMRoomMap"; +import SpaceStore from "./stores/spaces/SpaceStore"; +import { _t } from "./languageHandler"; /** * Given a room object, return the alias we should use for it, @@ -80,8 +83,8 @@ export function guessAndSetDMRoom(room: Room, isDirect: boolean): Promise * Marks or unmarks the given room as being as a DM room. * @param {string} roomId The ID of the room to modify * @param {string} userId The user ID of the desired DM - room target user or null to un-mark - this room as a DM room + room target user or null to un-mark + this room as a DM room * @returns {object} A promise */ export async function setDMRoom(roomId: string, userId: string): Promise { @@ -153,3 +156,22 @@ function guessDMRoomTargetId(room: Room, myUserId: string): string { if (oldestUser === undefined) return myUserId; return oldestUser.userId; } + +export function roomContextDetailsText(room: Room): string { + if (room.isSpaceRoom()) return undefined; + + const dmPartner = DMRoomMap.shared().getUserIdForRoomId(room.roomId); + if (dmPartner) { + return room.getMember(dmPartner)?.rawDisplayName; + } + + const [parent, ...otherParents] = SpaceStore.instance.getKnownParents(room.roomId); + if (parent) { + return _t("%(spaceName)s and %(count)s others", { + spaceName: room.client.getRoom(parent).name, + count: otherParents.length, + }); + } + + return room.getCanonicalAlias(); +} diff --git a/src/components/views/dialogs/ForwardDialog.tsx b/src/components/views/dialogs/ForwardDialog.tsx index a4aa1a120c8..626615ef649 100644 --- a/src/components/views/dialogs/ForwardDialog.tsx +++ b/src/components/views/dialogs/ForwardDialog.tsx @@ -44,7 +44,7 @@ import TruncatedList from "../elements/TruncatedList"; import EntityTile from "../rooms/EntityTile"; import BaseAvatar from "../avatars/BaseAvatar"; import SpaceStore from "../../../stores/spaces/SpaceStore"; -import { roomContextDetailsText } from "../../../utils/Room"; +import { roomContextDetailsText } from "../../../Rooms"; const AVATAR_SIZE = 30; diff --git a/src/utils/Room.ts b/src/utils/Room.ts deleted file mode 100644 index 00172c31487..00000000000 --- a/src/utils/Room.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* -Copyright 2021 The Matrix.org Foundation C.I.C. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -import { Room } from "matrix-js-sdk/src/models/room"; - -import SpaceStore from "../stores/spaces/SpaceStore"; -import DMRoomMap from "./DMRoomMap"; -import { _t } from "../languageHandler"; - -export function roomContextDetailsText(room: Room): string { - if (room.isSpaceRoom()) return undefined; - - const dmPartner = DMRoomMap.shared().getUserIdForRoomId(room.roomId); - if (dmPartner) { - return room.getMember(dmPartner)?.name; - } - - const [parent, ...otherParents] = SpaceStore.instance.getKnownParents(room.roomId); - if (parent) { - return _t("%(spaceName)s and %(count)s others", { - spaceName: room.client.getRoom(parent).name, - count: otherParents.length, - }); - } -}