mirror of https://github.com/vector-im/riot-web
switch to <ClickableUsername> and use `<a>` over `<span>`
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>pull/21833/head
parent
a1261614a6
commit
1d91469104
|
@ -19,16 +19,30 @@ import { _t } from './languageHandler';
|
||||||
import * as Roles from './Roles';
|
import * as Roles from './Roles';
|
||||||
import dis from "./dispatcher";
|
import dis from "./dispatcher";
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
function onUsernameClick(e) {
|
class ClickableUsername extends React.PureComponent {
|
||||||
dis.dispatch({
|
static propTypes = {
|
||||||
action: 'insert_mention',
|
mxid: PropTypes.string.isRequired,
|
||||||
user_id: e.target.id,
|
text: PropTypes.string.isRequired,
|
||||||
});
|
};
|
||||||
}
|
|
||||||
|
|
||||||
function makeUsernameSpan(mxid, text) {
|
constructor(props) {
|
||||||
return <span className="mx_TextForEvent_username" dir="auto" onClick={onUsernameClick} id={mxid}>{ text }</span>;
|
super(props);
|
||||||
|
this.onClick = this.onClick.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
onClick() {
|
||||||
|
dis.dispatch({
|
||||||
|
action: 'insert_mention',
|
||||||
|
user_id: this.props.mxid,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const {mxid, text} = this.props;
|
||||||
|
return <a className="mx_TextForEvent_username" dir="auto" onClick={this.onClick} data-mxid={mxid}>{ text }</a>;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function textForMemberEvent(ev) {
|
function textForMemberEvent(ev) {
|
||||||
|
@ -36,8 +50,8 @@ function textForMemberEvent(ev) {
|
||||||
const senderName = ev.sender ? ev.sender.name : ev.getSender();
|
const senderName = ev.sender ? ev.sender.name : ev.getSender();
|
||||||
const targetName = ev.target ? ev.target.name : ev.getStateKey();
|
const targetName = ev.target ? ev.target.name : ev.getStateKey();
|
||||||
|
|
||||||
const sender = makeUsernameSpan(ev.getSender(), senderName);
|
const sender = <ClickableUsername mxid={ev.getSender()} text={senderName} />;
|
||||||
const target = makeUsernameSpan(ev.getStateKey(), targetName);
|
const target = <ClickableUsername mxid={ev.getStateKey()} text={targetName} />;
|
||||||
|
|
||||||
const prevContent = ev.getPrevContent();
|
const prevContent = ev.getPrevContent();
|
||||||
const content = ev.getContent();
|
const content = ev.getContent();
|
||||||
|
@ -71,18 +85,18 @@ function textForMemberEvent(ev) {
|
||||||
if (prevContent && prevContent.membership === 'join') {
|
if (prevContent && prevContent.membership === 'join') {
|
||||||
if (prevContent.displayname && content.displayname && prevContent.displayname !== content.displayname) {
|
if (prevContent.displayname && content.displayname && prevContent.displayname !== content.displayname) {
|
||||||
return _t('<oldDisplayName> changed their display name to <displayName>.', {}, {
|
return _t('<oldDisplayName> changed their display name to <displayName>.', {}, {
|
||||||
oldDisplayName: makeUsernameSpan(ev.getStateKey(), prevContent.displayname),
|
oldDisplayName: <ClickableUsername mxid={ev.getStateKey()} text={prevContent.displayname} />,
|
||||||
displayName: makeUsernameSpan(ev.getStateKey(), content.displayname),
|
displayName: <ClickableUsername mxid={ev.getStateKey()} text={content.displayname} />,
|
||||||
});
|
});
|
||||||
} else if (!prevContent.displayname && content.displayname) {
|
} else if (!prevContent.displayname && content.displayname) {
|
||||||
return _t('<sender> set their display name to <displayName>.', {}, {
|
return _t('<sender> set their display name to <displayName>.', {}, {
|
||||||
sender,
|
sender,
|
||||||
displayName: makeUsernameSpan(ev.getSender(), content.displayname),
|
displayName: <ClickableUsername mxid={ev.getSender()} text={content.displayname} />,
|
||||||
});
|
});
|
||||||
} else if (prevContent.displayname && !content.displayname) {
|
} else if (prevContent.displayname && !content.displayname) {
|
||||||
return _t('<sender> removed their display name (<oldDisplayName>).', {
|
return _t('<sender> removed their display name (<oldDisplayName>).', {
|
||||||
sender,
|
sender,
|
||||||
oldDisplayName: makeUsernameSpan(ev.getSender(), prevContent.displayname),
|
oldDisplayName: <ClickableUsername mxid={ev.getSender()} text={prevContent.displayname} />,
|
||||||
});
|
});
|
||||||
} else if (prevContent.avatar_url && !content.avatar_url) {
|
} else if (prevContent.avatar_url && !content.avatar_url) {
|
||||||
return _t('<sender> removed their profile picture.', {}, {sender});
|
return _t('<sender> removed their profile picture.', {}, {sender});
|
||||||
|
@ -129,13 +143,13 @@ function textForTopicEvent(ev) {
|
||||||
return _t('<sender> changed the topic to "%(topic)s".', {
|
return _t('<sender> changed the topic to "%(topic)s".', {
|
||||||
topic: ev.getContent().topic,
|
topic: ev.getContent().topic,
|
||||||
}, {
|
}, {
|
||||||
sender: makeUsernameSpan(ev.getSender(), senderDisplayName),
|
sender: <ClickableUsername mxid={ev.getSender()} text={senderDisplayName} />,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function textForRoomNameEvent(ev) {
|
function textForRoomNameEvent(ev) {
|
||||||
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
||||||
const sender = makeUsernameSpan(ev.getSender(), senderDisplayName);
|
const sender = <ClickableUsername mxid={ev.getSender()} text={senderDisplayName} />;
|
||||||
|
|
||||||
if (!ev.getContent().name || ev.getContent().name.trim().length === 0) {
|
if (!ev.getContent().name || ev.getContent().name.trim().length === 0) {
|
||||||
return _t('<sender> removed the room name.', {}, {sender});
|
return _t('<sender> removed the room name.', {}, {sender});
|
||||||
|
@ -154,7 +168,7 @@ function textForMessageEvent(ev) {
|
||||||
message = "* " + senderDisplayName + " " + message;
|
message = "* " + senderDisplayName + " " + message;
|
||||||
} else if (ev.getContent().msgtype === "m.image") {
|
} else if (ev.getContent().msgtype === "m.image") {
|
||||||
message = _t('<sender> sent an image.', {}, {
|
message = _t('<sender> sent an image.', {}, {
|
||||||
sender: makeUsernameSpan(ev.getSender(), senderDisplayName),
|
sender: <ClickableUsername mxid={ev.getSender()} text={senderDisplayName} />,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return message;
|
return message;
|
||||||
|
@ -164,7 +178,7 @@ function textForCallAnswerEvent(event) {
|
||||||
const senderName = event.sender ? event.sender.name : _t('Someone');
|
const senderName = event.sender ? event.sender.name : _t('Someone');
|
||||||
const supported = MatrixClientPeg.get().supportsVoip() ? '' : _t('(not supported by this browser)');
|
const supported = MatrixClientPeg.get().supportsVoip() ? '' : _t('(not supported by this browser)');
|
||||||
return _t('<sender> answered the call.', {}, {
|
return _t('<sender> answered the call.', {}, {
|
||||||
sender: makeUsernameSpan(event.getSender(), senderName),
|
sender: <ClickableUsername mxid={event.getSender()} text={senderName} />,
|
||||||
}) + ' ' + supported;
|
}) + ' ' + supported;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,13 +198,13 @@ function textForCallHangupEvent(event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return _t('<sender> ended the call.', {}, {
|
return _t('<sender> ended the call.', {}, {
|
||||||
sender: makeUsernameSpan(event.getSender(), senderName),
|
sender: <ClickableUsername mxid={event.getSender()} text={senderName} />,
|
||||||
}) + ' ' + reason;
|
}) + ' ' + reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
function textForCallInviteEvent(event) {
|
function textForCallInviteEvent(event) {
|
||||||
const senderName = event.sender ? event.sender.name : _t('Someone');
|
const senderName = event.sender ? event.sender.name : _t('Someone');
|
||||||
const sender = makeUsernameSpan(event.getSender(), senderName);
|
const sender = <ClickableUsername mxid={event.getSender()} text={senderName} />;
|
||||||
// FIXME: Find a better way to determine this from the event?
|
// FIXME: Find a better way to determine this from the event?
|
||||||
let callType = "voice";
|
let callType = "voice";
|
||||||
if (event.getContent().offer && event.getContent().offer.sdp &&
|
if (event.getContent().offer && event.getContent().offer.sdp &&
|
||||||
|
@ -206,13 +220,13 @@ function textForThreePidInviteEvent(event) {
|
||||||
return _t('<sender> sent an invitation to %(targetDisplayName)s to join the room.', {
|
return _t('<sender> sent an invitation to %(targetDisplayName)s to join the room.', {
|
||||||
targetDisplayName: event.getContent().display_name,
|
targetDisplayName: event.getContent().display_name,
|
||||||
}, {
|
}, {
|
||||||
sender: makeUsernameSpan(event.getSender(), senderName),
|
sender: <ClickableUsername mxid={event.getSender()} text={senderName} />,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function textForHistoryVisibilityEvent(event) {
|
function textForHistoryVisibilityEvent(event) {
|
||||||
const senderName = event.sender ? event.sender.name : event.getSender();
|
const senderName = event.sender ? event.sender.name : event.getSender();
|
||||||
const sender = makeUsernameSpan(event.getSender(), senderName);
|
const sender = <ClickableUsername mxid={event.getSender()} text={senderName} />;
|
||||||
switch (event.getContent().history_visibility) {
|
switch (event.getContent().history_visibility) {
|
||||||
case 'invited':
|
case 'invited':
|
||||||
return _t('<sender> made future room history visible to all room members, '
|
return _t('<sender> made future room history visible to all room members, '
|
||||||
|
@ -238,7 +252,7 @@ function textForEncryptionEvent(event) {
|
||||||
return _t('<sender> turned on end-to-end encryption (algorithm %(algorithm)s).', {
|
return _t('<sender> turned on end-to-end encryption (algorithm %(algorithm)s).', {
|
||||||
algorithm: event.getContent().algorithm,
|
algorithm: event.getContent().algorithm,
|
||||||
}, {
|
}, {
|
||||||
sender: makeUsernameSpan(event.getSender(), senderName),
|
sender: <ClickableUsername mxid={event.getSender()} text={senderName} />,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +288,7 @@ function textForPowerEvent(event) {
|
||||||
fromPowerLevel: Roles.textualPowerLevel(from, userDefault),
|
fromPowerLevel: Roles.textualPowerLevel(from, userDefault),
|
||||||
toPowerLevel: Roles.textualPowerLevel(to, userDefault),
|
toPowerLevel: Roles.textualPowerLevel(to, userDefault),
|
||||||
}, {
|
}, {
|
||||||
user: makeUsernameSpan(userId, userId),
|
user: <ClickableUsername mxid={userId} text={userId} />,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -285,19 +299,19 @@ function textForPowerEvent(event) {
|
||||||
return _t('<sender> changed the power level of %(powerLevelDiffText)s.', {
|
return _t('<sender> changed the power level of %(powerLevelDiffText)s.', {
|
||||||
powerLevelDiffText: diff.join(", "),
|
powerLevelDiffText: diff.join(", "),
|
||||||
}, {
|
}, {
|
||||||
sender: makeUsernameSpan(event.getSender(), senderName),
|
sender: <ClickableUsername mxid={event.getSender()} text={senderName} />,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function textForPinnedEvent(event) {
|
function textForPinnedEvent(event) {
|
||||||
const senderName = event.sender ? event.sender.name : event.getSender();
|
const senderName = event.sender ? event.sender.name : event.getSender();
|
||||||
const sender = makeUsernameSpan(event.getSender(), senderName);
|
const sender = <ClickableUsername mxid={event.getSender()} text={senderName} />;
|
||||||
return _t("<sender> changed the pinned messages for the room.", {}, {sender});
|
return _t("<sender> changed the pinned messages for the room.", {}, {sender});
|
||||||
}
|
}
|
||||||
|
|
||||||
function textForWidgetEvent(event) {
|
function textForWidgetEvent(event) {
|
||||||
const senderName = event.sender ? event.sender.name : event.getSender();
|
const senderName = event.sender ? event.sender.name : event.getSender();
|
||||||
const sender = makeUsernameSpan(event.getSender(), senderName);
|
const sender = <ClickableUsername mxid={event.getSender()} text={senderName} />;
|
||||||
|
|
||||||
const {name: prevName, type: prevType, url: prevUrl} = event.getPrevContent();
|
const {name: prevName, type: prevType, url: prevUrl} = event.getPrevContent();
|
||||||
const {name, type, url} = event.getContent() || {};
|
const {name, type, url} = event.getContent() || {};
|
||||||
|
|
Loading…
Reference in New Issue