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

Commit b12cf79

Browse files
authored
Merge pull request #5624 from SimonBrandner/show-room-name
Display room name in pills instead of address
2 parents 5262194 + d8a9b84 commit b12cf79

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

src/components/views/elements/Pill.js

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import FlairStore from "../../../stores/FlairStore";
2626
import {getPrimaryPermalinkEntity, parseAppLocalLink} from "../../../utils/permalinks/Permalinks";
2727
import MatrixClientContext from "../../../contexts/MatrixClientContext";
2828
import {Action} from "../../../dispatcher/actions";
29+
import Tooltip from './Tooltip';
2930

3031
class Pill extends React.Component {
3132
static roomNotifPos(text) {
@@ -68,6 +69,8 @@ class Pill extends React.Component {
6869
group: null,
6970
// The room related to the room pill
7071
room: null,
72+
// Is the user hovering the pill
73+
hover: false,
7174
};
7275

7376
// TODO: [REACT-WARNING] Replace with appropriate lifecycle event
@@ -154,6 +157,18 @@ class Pill extends React.Component {
154157
this._unmounted = true;
155158
}
156159

160+
onMouseOver = () => {
161+
this.setState({
162+
hover: true,
163+
});
164+
};
165+
166+
onMouseLeave = () => {
167+
this.setState({
168+
hover: false,
169+
});
170+
};
171+
157172
doProfileLookup(userId, member) {
158173
MatrixClientPeg.get().getProfileInfo(userId).then((resp) => {
159174
if (this._unmounted) {
@@ -226,7 +241,7 @@ class Pill extends React.Component {
226241
case Pill.TYPE_ROOM_MENTION: {
227242
const room = this.state.room;
228243
if (room) {
229-
linkText = resource;
244+
linkText = room.name || resource;
230245
if (this.props.shouldShowPillAvatar) {
231246
avatar = <RoomAvatar room={room} width={16} height={16} aria-hidden="true" />;
232247
}
@@ -256,15 +271,36 @@ class Pill extends React.Component {
256271
});
257272

258273
if (this.state.pillType) {
274+
const {yOffset} = this.props;
275+
276+
let tip;
277+
if (this.state.hover && resource) {
278+
tip = <Tooltip label={resource} yOffset={yOffset} />;
279+
}
280+
259281
return <MatrixClientContext.Provider value={this._matrixClient}>
260282
{ this.props.inMessage ?
261-
<a className={classes} href={href} onClick={onClick} title={resource} data-offset-key={this.props.offsetKey}>
283+
<a
284+
className={classes}
285+
href={href}
286+
onClick={onClick}
287+
data-offset-key={this.props.offsetKey}
288+
onMouseOver={this.onMouseOver}
289+
onMouseLeave={this.onMouseLeave}
290+
>
262291
{ avatar }
263292
{ linkText }
293+
{ tip }
264294
</a> :
265-
<span className={classes} title={resource} data-offset-key={this.props.offsetKey}>
295+
<span
296+
className={classes}
297+
data-offset-key={this.props.offsetKey}
298+
onMouseOver={this.onMouseOver}
299+
onMouseLeave={this.onMouseLeave}
300+
>
266301
{ avatar }
267302
{ linkText }
303+
{ tip }
268304
</span> }
269305
</MatrixClientContext.Provider>;
270306
} else {

src/editor/parts.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ class NewlinePart extends BasePart implements IBasePart {
329329
}
330330

331331
class RoomPillPart extends PillPart {
332-
constructor(displayAlias, private room: Room) {
333-
super(displayAlias, displayAlias);
332+
constructor(resourceId: string, label: string, private room: Room) {
333+
super(resourceId, label);
334334
}
335335

336336
setAvatar(node: HTMLElement) {
@@ -357,6 +357,10 @@ class RoomPillPart extends PillPart {
357357
}
358358

359359
class AtRoomPillPart extends RoomPillPart {
360+
constructor(text: string, room: Room) {
361+
super(text, text, room);
362+
}
363+
360364
get type(): IPillPart["type"] {
361365
return Type.AtRoomPill;
362366
}
@@ -521,7 +525,7 @@ export class PartCreator {
521525
r.getAltAliases().includes(alias);
522526
});
523527
}
524-
return new RoomPillPart(alias, room);
528+
return new RoomPillPart(alias, room ? room.name : alias, room);
525529
}
526530

527531
atRoomPill(text: string) {

test/components/views/messages/TextualBody-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ describe("<TextualBody />", () => {
208208
const content = wrapper.find(".mx_EventTile_body");
209209
expect(content.html()).toBe('<span class="mx_EventTile_body markdown-body" dir="auto">' +
210210
'Hey <span>' +
211-
'<a class="mx_Pill mx_UserPill" title="@user:server">' +
211+
'<a class="mx_Pill mx_UserPill">' +
212212
'<img class="mx_BaseAvatar mx_BaseAvatar_image" src="mxc://avatar.url/image.png" ' +
213213
'style="width: 16px; height: 16px;" title="@member:domain.bla" alt="" aria-hidden="true">Member</a>' +
214214
'</span></span>');
@@ -267,8 +267,8 @@ describe("<TextualBody />", () => {
267267
expect(content.html()).toBe(
268268
'<span class="mx_EventTile_body markdown-body" dir="auto">' +
269269
'A <span><a class="mx_Pill mx_RoomPill" href="#/room/!ZxbRYPQXDXKGmDnJNg:example.com' +
270-
'?via=example.com&amp;via=bob.com" ' +
271-
'title="!ZxbRYPQXDXKGmDnJNg:example.com"><img class="mx_BaseAvatar mx_BaseAvatar_image" ' +
270+
'?via=example.com&amp;via=bob.com"' +
271+
'><img class="mx_BaseAvatar mx_BaseAvatar_image" ' +
272272
'src="mxc://avatar.url/room.png" ' +
273273
'style="width: 16px; height: 16px;" alt="" aria-hidden="true">' +
274274
'!ZxbRYPQXDXKGmDnJNg:example.com</a></span> with vias</span>',

0 commit comments

Comments
 (0)