diff --git a/src/TextForEvent.js b/src/TextForEvent.js index 0cdaaac4ab..3d2e3c1fb5 100644 --- a/src/TextForEvent.js +++ b/src/TextForEvent.js @@ -19,16 +19,30 @@ import { _t } from './languageHandler'; import * as Roles from './Roles'; import dis from "./dispatcher"; import React from 'react'; +import PropTypes from 'prop-types'; -function onUsernameClick(e) { - dis.dispatch({ - action: 'insert_mention', - user_id: e.target.id, - }); -} +class ClickableUsername extends React.PureComponent { + static propTypes = { + mxid: PropTypes.string.isRequired, + text: PropTypes.string.isRequired, + }; -function makeUsernameSpan(mxid, text) { - return { text }; + constructor(props) { + 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 { text }; + } } function textForMemberEvent(ev) { @@ -36,8 +50,8 @@ function textForMemberEvent(ev) { const senderName = ev.sender ? ev.sender.name : ev.getSender(); const targetName = ev.target ? ev.target.name : ev.getStateKey(); - const sender = makeUsernameSpan(ev.getSender(), senderName); - const target = makeUsernameSpan(ev.getStateKey(), targetName); + const sender = ; + const target = ; const prevContent = ev.getPrevContent(); const content = ev.getContent(); @@ -71,18 +85,18 @@ function textForMemberEvent(ev) { if (prevContent && prevContent.membership === 'join') { if (prevContent.displayname && content.displayname && prevContent.displayname !== content.displayname) { return _t(' changed their display name to .', {}, { - oldDisplayName: makeUsernameSpan(ev.getStateKey(), prevContent.displayname), - displayName: makeUsernameSpan(ev.getStateKey(), content.displayname), + oldDisplayName: , + displayName: , }); } else if (!prevContent.displayname && content.displayname) { return _t(' set their display name to .', {}, { sender, - displayName: makeUsernameSpan(ev.getSender(), content.displayname), + displayName: , }); } else if (prevContent.displayname && !content.displayname) { return _t(' removed their display name ().', { sender, - oldDisplayName: makeUsernameSpan(ev.getSender(), prevContent.displayname), + oldDisplayName: , }); } else if (prevContent.avatar_url && !content.avatar_url) { return _t(' removed their profile picture.', {}, {sender}); @@ -129,13 +143,13 @@ function textForTopicEvent(ev) { return _t(' changed the topic to "%(topic)s".', { topic: ev.getContent().topic, }, { - sender: makeUsernameSpan(ev.getSender(), senderDisplayName), + sender: , }); } function textForRoomNameEvent(ev) { const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender(); - const sender = makeUsernameSpan(ev.getSender(), senderDisplayName); + const sender = ; if (!ev.getContent().name || ev.getContent().name.trim().length === 0) { return _t(' removed the room name.', {}, {sender}); @@ -154,7 +168,7 @@ function textForMessageEvent(ev) { message = "* " + senderDisplayName + " " + message; } else if (ev.getContent().msgtype === "m.image") { message = _t(' sent an image.', {}, { - sender: makeUsernameSpan(ev.getSender(), senderDisplayName), + sender: , }); } return message; @@ -164,7 +178,7 @@ function textForCallAnswerEvent(event) { const senderName = event.sender ? event.sender.name : _t('Someone'); const supported = MatrixClientPeg.get().supportsVoip() ? '' : _t('(not supported by this browser)'); return _t(' answered the call.', {}, { - sender: makeUsernameSpan(event.getSender(), senderName), + sender: , }) + ' ' + supported; } @@ -184,13 +198,13 @@ function textForCallHangupEvent(event) { } } return _t(' ended the call.', {}, { - sender: makeUsernameSpan(event.getSender(), senderName), + sender: , }) + ' ' + reason; } function textForCallInviteEvent(event) { const senderName = event.sender ? event.sender.name : _t('Someone'); - const sender = makeUsernameSpan(event.getSender(), senderName); + const sender = ; // FIXME: Find a better way to determine this from the event? let callType = "voice"; if (event.getContent().offer && event.getContent().offer.sdp && @@ -206,13 +220,13 @@ function textForThreePidInviteEvent(event) { return _t(' sent an invitation to %(targetDisplayName)s to join the room.', { targetDisplayName: event.getContent().display_name, }, { - sender: makeUsernameSpan(event.getSender(), senderName), + sender: , }); } function textForHistoryVisibilityEvent(event) { const senderName = event.sender ? event.sender.name : event.getSender(); - const sender = makeUsernameSpan(event.getSender(), senderName); + const sender = ; switch (event.getContent().history_visibility) { case 'invited': return _t(' made future room history visible to all room members, ' @@ -238,7 +252,7 @@ function textForEncryptionEvent(event) { return _t(' turned on end-to-end encryption (algorithm %(algorithm)s).', { algorithm: event.getContent().algorithm, }, { - sender: makeUsernameSpan(event.getSender(), senderName), + sender: , }); } @@ -274,7 +288,7 @@ function textForPowerEvent(event) { fromPowerLevel: Roles.textualPowerLevel(from, userDefault), toPowerLevel: Roles.textualPowerLevel(to, userDefault), }, { - user: makeUsernameSpan(userId, userId), + user: , }), ); } @@ -285,19 +299,19 @@ function textForPowerEvent(event) { return _t(' changed the power level of %(powerLevelDiffText)s.', { powerLevelDiffText: diff.join(", "), }, { - sender: makeUsernameSpan(event.getSender(), senderName), + sender: , }); } function textForPinnedEvent(event) { const senderName = event.sender ? event.sender.name : event.getSender(); - const sender = makeUsernameSpan(event.getSender(), senderName); + const sender = ; return _t(" changed the pinned messages for the room.", {}, {sender}); } function textForWidgetEvent(event) { const senderName = event.sender ? event.sender.name : event.getSender(); - const sender = makeUsernameSpan(event.getSender(), senderName); + const sender = ; const {name: prevName, type: prevType, url: prevUrl} = event.getPrevContent(); const {name, type, url} = event.getContent() || {};