Expand groups into variables with readable names

This commit is contained in:
Luke Barnard 2017-07-17 19:31:36 +01:00
parent b1e3dc406c
commit d207ee5244

View file

@ -177,25 +177,27 @@ module.exports = React.createClass({
const href = node.getAttribute("href");
// HtmlUtils transforms `matrix.to` links to local links, so match against
// user or room app links.
const match = /^#\/(user|room)\/(.*)$/.exec(href);
if (match) {
const match = /^#\/(user|room)\/(.*)$/.exec(href) || [];
const resourceType = match[1]; // "user" or "room"
const resourceId = match[2]; // user ID or room ID
if (match && resourceType && resourceId) {
let avatar;
let roomId;
let room;
let member;
switch (match[1]) {
switch (resourceType) {
case "user":
roomId = this.props.mxEvent.getRoomId();
room = MatrixClientPeg.get().getRoom(roomId);
member = room.getMember(match[2]) ||
new RoomMember(null, match[2]);
avatar = <MemberAvatar member={member} width={16} height={16} name={match[2]}/>;
member = room.getMember(resourceId) ||
new RoomMember(null, resourceId);
avatar = <MemberAvatar member={member} width={16} height={16} name={resourceId}/>;
break;
case "room":
room = match[2][0] === '#' ?
room = resourceId[0] === '#' ?
MatrixClientPeg.get().getRooms().find((r) => {
return r.getCanonicalAlias() === match[2];
}) : MatrixClientPeg.get().getRoom(match[2]);
return r.getCanonicalAlias() === resourceId;
}) : MatrixClientPeg.get().getRoom(resourceId);
if (room) {
avatar = <RoomAvatar room={room} width={16} height={16}/>;
}
@ -204,7 +206,7 @@ module.exports = React.createClass({
if (avatar) {
const avatarContainer = document.createElement('span');
node.className = "mx_MTextBody_pill " +
(match[1] === "user" ? "mx_UserPill" : "mx_RoomPill");
(resourceType === "user" ? "mx_UserPill" : "mx_RoomPill");
ReactDOM.render(avatar, avatarContainer);
node.insertBefore(avatarContainer, node.firstChild);
}