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

Commit bff1ef3

Browse files
Use styled mxids in member list v2 (#8110)
* Revert "Revert "Use styled mxids in member list (#6328)" (#8107)" This reverts commit 709e6e7. * Fix disambiguated profile for bubbles Signed-off-by: Šimon Brandner <[email protected]>
1 parent cfabcdd commit bff1ef3

File tree

13 files changed

+141
-55
lines changed

13 files changed

+141
-55
lines changed

res/css/_components.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
@import "./views/messages/_CallEvent.scss";
194194
@import "./views/messages/_CreateEvent.scss";
195195
@import "./views/messages/_DateSeparator.scss";
196+
@import "./views/messages/_DisambiguatedProfile.scss";
196197
@import "./views/messages/_EventTileBubble.scss";
197198
@import "./views/messages/_HiddenBody.scss";
198199
@import "./views/messages/_JumpToDatePicker.scss";
@@ -215,7 +216,6 @@
215216
@import "./views/messages/_ReactionsRowButton.scss";
216217
@import "./views/messages/_RedactedBody.scss";
217218
@import "./views/messages/_RoomAvatarEvent.scss";
218-
@import "./views/messages/_SenderProfile.scss";
219219
@import "./views/messages/_TextualEvent.scss";
220220
@import "./views/messages/_UnknownBody.scss";
221221
@import "./views/messages/_ViewSourceEvent.scss";

res/css/structures/_FilePanel.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ limitations under the License.
9393
text-decoration: none;
9494
}
9595

96-
.mx_FilePanel .mx_EventTile .mx_SenderProfile {
96+
.mx_FilePanel .mx_EventTile .mx_DisambiguatedProfile {
9797
flex: 1 1 auto;
9898
line-height: initial;
9999
padding: 0px;

res/css/structures/_NotificationPanel.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ limitations under the License.
7777
display: none; // we don't need this in this view
7878
}
7979

80-
.mx_NotificationPanel .mx_EventTile .mx_SenderProfile,
80+
.mx_NotificationPanel .mx_EventTile .mx_DisambiguatedProfile,
8181
.mx_NotificationPanel .mx_EventTile .mx_MessageTimestamp {
8282
color: $primary-content;
8383
font-size: $font-12px;
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright 2015, 2016 OpenMarket Ltd
3+
Copyright 2021 Šimon Brandner <[email protected]>
34
45
Licensed under the Apache License, Version 2.0 (the "License");
56
you may not use this file except in compliance with the License.
@@ -14,13 +15,18 @@ See the License for the specific language governing permissions and
1415
limitations under the License.
1516
*/
1617

17-
.mx_SenderProfile_displayName {
18-
font-weight: 600;
19-
}
18+
.mx_DisambiguatedProfile {
19+
overflow: hidden;
20+
text-overflow: ellipsis;
21+
22+
.mx_DisambiguatedProfile_displayName {
23+
font-weight: 600;
24+
}
2025

21-
.mx_SenderProfile_mxid {
22-
font-weight: 600;
23-
font-size: 1.1rem;
24-
margin-left: 5px;
25-
opacity: 0.5; // Match mx_TextualEvent
26+
.mx_DisambiguatedProfile_mxid {
27+
font-weight: 600;
28+
font-size: 1.1rem;
29+
margin-left: 5px;
30+
opacity: 0.5; // Match mx_TextualEvent
31+
}
2632
}

res/css/views/rooms/_EventBubbleTile.scss

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ limitations under the License.
8888
}
8989
}
9090

91-
.mx_SenderProfile,
91+
.mx_DisambiguatedProfile,
9292
.mx_EventTile_line {
9393
width: fit-content;
9494
max-width: 70%;
9595
// fixed line height to prevent emoji from being taller than text
9696
line-height: $font-18px;
9797
}
9898

99-
> .mx_SenderProfile {
99+
> .mx_DisambiguatedProfile {
100100
position: relative;
101101
top: -2px;
102102
left: 2px;
@@ -168,11 +168,11 @@ limitations under the License.
168168
margin-right: calc(-1 * var(--gutterSize));
169169
}
170170

171-
.mx_SenderProfile {
171+
.mx_DisambiguatedProfile {
172172
display: none;
173173
}
174174

175-
.mx_ReplyTile .mx_SenderProfile {
175+
.mx_ReplyTile .mx_DisambiguatedProfile {
176176
display: block;
177177
}
178178

@@ -379,7 +379,7 @@ limitations under the License.
379379
.mx_EventTile_avatar {
380380
position: static;
381381
}
382-
.mx_SenderProfile {
382+
.mx_DisambiguatedProfile {
383383
display: none;
384384
}
385385
}

res/css/views/rooms/_EventTile.scss

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ $left-gutter: 64px;
126126
max-width: calc(100% - $left-gutter);
127127
}
128128

129-
.mx_SenderProfile .mx_Flair {
129+
.mx_DisambiguatedProfile .mx_Flair {
130130
opacity: 0.7;
131131
margin-left: 5px;
132132
display: inline-block;
@@ -141,6 +141,21 @@ $left-gutter: 64px;
141141
}
142142
}
143143

144+
.mx_DisambiguatedProfile {
145+
color: $primary-content;
146+
font-size: $font-14px;
147+
display: inline-block; /* anti-zalgo, with overflow hidden */
148+
overflow: hidden;
149+
cursor: pointer;
150+
padding-bottom: 0px;
151+
padding-top: 0px;
152+
margin: 0px;
153+
/* the next three lines, along with overflow hidden, truncate long display names */
154+
white-space: nowrap;
155+
text-overflow: ellipsis;
156+
max-width: calc(100% - $left-gutter);
157+
}
158+
144159
&.mx_EventTile_isEditing .mx_MessageTimestamp {
145160
visibility: hidden;
146161
}

res/css/views/rooms/_GroupLayout.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $left-gutter: 64px;
1919

2020
.mx_GroupLayout {
2121
.mx_EventTile {
22-
> .mx_SenderProfile {
22+
> .mx_DisambiguatedProfile {
2323
line-height: $font-20px;
2424
margin-left: $left-gutter;
2525
}
@@ -65,7 +65,7 @@ $left-gutter: 64px;
6565
}
6666
}
6767

68-
.mx_SenderProfile {
68+
.mx_DisambiguatedProfile {
6969
font-size: $font-13px;
7070
}
7171

res/css/views/rooms/_IRCLayout.scss

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,42 +173,42 @@ $irc-line-height: $font-18px;
173173
border-left: 0;
174174
}
175175

176-
.mx_SenderProfile {
176+
.mx_DisambiguatedProfile {
177177
width: var(--name-width);
178178
display: flex;
179179
order: 2;
180180
flex-shrink: 0;
181181
justify-content: flex-start;
182182
align-items: center;
183183

184-
> .mx_SenderProfile_displayName {
184+
> .mx_DisambiguatedProfile_displayName {
185185
width: 100%;
186186
text-align: end;
187187
overflow: hidden;
188188
text-overflow: ellipsis;
189189
}
190190

191-
> .mx_SenderProfile_mxid {
191+
> .mx_DisambiguatedProfile_mxid {
192192
visibility: collapse;
193193
// Override the inherited margin.
194194
margin-left: 0;
195195
padding: 0 5px;
196196
}
197197
}
198198

199-
.mx_SenderProfile:hover {
199+
.mx_DisambiguatedProfile:hover {
200200
overflow: visible;
201201
z-index: 10;
202202

203-
> .mx_SenderProfile_displayName {
203+
> .mx_DisambiguatedProfile_displayName {
204204
overflow: visible;
205205
display: inline;
206206
background-color: $event-selected-color;
207207
border-radius: 8px 0 0 8px;
208208
padding-right: 8px;
209209
}
210210

211-
> .mx_SenderProfile_mxid {
211+
> .mx_DisambiguatedProfile_mxid {
212212
visibility: visible;
213213
opacity: 1;
214214
background-color: $event-selected-color;
@@ -217,7 +217,7 @@ $irc-line-height: $font-18px;
217217

218218
.mx_ReplyChain {
219219
margin: 0;
220-
.mx_SenderProfile {
220+
.mx_DisambiguatedProfile {
221221
order: unset;
222222
max-width: unset;
223223
width: unset;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Copyright 2021 Šimon Brandner <[email protected]>
3+
Copyright 2022 The Matrix.org Foundation C.I.C.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
import React from 'react';
19+
import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
20+
import classNames from 'classnames';
21+
22+
import { getUserNameColorClass } from '../../../utils/FormattingUtils';
23+
import UserIdentifier from "../../../customisations/UserIdentifier";
24+
25+
interface IProps {
26+
member?: RoomMember;
27+
fallbackName: string;
28+
flair?: JSX.Element;
29+
onClick?(): void;
30+
colored?: boolean;
31+
emphasizeDisplayName?: boolean;
32+
}
33+
34+
export default class DisambiguatedProfile extends React.Component<IProps> {
35+
render() {
36+
const { fallbackName, member, flair, colored, emphasizeDisplayName, onClick } = this.props;
37+
const rawDisplayName = member?.rawDisplayName || fallbackName;
38+
const mxid = member?.userId;
39+
40+
let colorClass;
41+
if (colored) {
42+
colorClass = getUserNameColorClass(fallbackName);
43+
}
44+
45+
let mxidElement;
46+
if (member?.disambiguate && mxid) {
47+
mxidElement = (
48+
<span className="mx_DisambiguatedProfile_mxid">
49+
{ UserIdentifier.getDisplayUserIdentifier(
50+
mxid, { withDisplayName: true, roomId: member.roomId },
51+
) }
52+
</span>
53+
);
54+
}
55+
56+
const displayNameClasses = classNames({
57+
"mx_DisambiguatedProfile_displayName": emphasizeDisplayName,
58+
[colorClass]: true,
59+
});
60+
61+
return (
62+
<div className="mx_DisambiguatedProfile" dir="auto" onClick={onClick}>
63+
<span className={displayNameClasses}>
64+
{ rawDisplayName }
65+
</span>
66+
{ mxidElement }
67+
{ flair }
68+
</div>
69+
);
70+
}
71+
}

src/components/views/messages/SenderProfile.tsx

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
2121

2222
import Flair from '../elements/Flair';
2323
import FlairStore from '../../../stores/FlairStore';
24-
import { getUserNameColorClass } from '../../../utils/FormattingUtils';
2524
import MatrixClientContext from "../../../contexts/MatrixClientContext";
2625
import { replaceableComponent } from "../../../utils/replaceableComponent";
27-
import UserIdentifier from '../../../customisations/UserIdentifier';
26+
import DisambiguatedProfile from "./DisambiguatedProfile";
2827
import RoomContext, { TimelineRenderingType } from '../../../contexts/RoomContext';
2928
import SettingsStore from "../../../settings/SettingsStore";
3029
import { MatrixClientPeg } from "../../../MatrixClientPeg";
@@ -106,9 +105,8 @@ export default class SenderProfile extends React.Component<IProps, IState> {
106105
}
107106

108107
render() {
109-
const { mxEvent } = this.props;
110-
const colorClass = getUserNameColorClass(mxEvent.getSender());
111-
const { msgtype } = mxEvent.getContent();
108+
const { mxEvent, onClick } = this.props;
109+
const msgtype = mxEvent.getContent().msgtype;
112110

113111
let member = mxEvent.sender;
114112
if (SettingsStore.getValue("feature_use_only_current_profiles")) {
@@ -118,10 +116,6 @@ export default class SenderProfile extends React.Component<IProps, IState> {
118116
}
119117
}
120118

121-
const disambiguate = member?.disambiguate || mxEvent.sender?.disambiguate;
122-
const displayName = member?.rawDisplayName || mxEvent.getSender() || "";
123-
const mxid = member?.userId || mxEvent.getSender() || "";
124-
125119
return <RoomContext.Consumer>
126120
{ roomContext => {
127121
if (msgtype === MsgType.Emote &&
@@ -130,17 +124,6 @@ export default class SenderProfile extends React.Component<IProps, IState> {
130124
return null; // emote message must include the name so don't duplicate it
131125
}
132126

133-
let mxidElement;
134-
if (disambiguate) {
135-
mxidElement = (
136-
<span className="mx_SenderProfile_mxid">
137-
{ UserIdentifier.getDisplayUserIdentifier(
138-
mxid, { withDisplayName: true, roomId: mxEvent.getRoomId() },
139-
) }
140-
</span>
141-
);
142-
}
143-
144127
let flair;
145128
if (this.props.enableFlair) {
146129
const displayedGroups = this.getDisplayedGroups(
@@ -151,13 +134,14 @@ export default class SenderProfile extends React.Component<IProps, IState> {
151134
}
152135

153136
return (
154-
<div className="mx_SenderProfile" dir="auto" onClick={this.props.onClick}>
155-
<span className={`mx_SenderProfile_displayName ${colorClass}`}>
156-
{ displayName }
157-
</span>
158-
{ mxidElement }
159-
{ flair }
160-
</div>
137+
<DisambiguatedProfile
138+
fallbackName={mxEvent.getSender() || ""}
139+
flair={flair}
140+
onClick={onClick}
141+
member={member}
142+
colored={true}
143+
emphasizeDisplayName={true}
144+
/>
161145
);
162146
} }
163147
</RoomContext.Consumer>;

0 commit comments

Comments
 (0)