make username clickable

This commit is contained in:
Bruno Windels 2019-04-17 10:57:45 +02:00
parent 8a371080d7
commit 86620839ae
3 changed files with 41 additions and 17 deletions

View file

@ -118,4 +118,6 @@ limitations under the License.
.mx_RoomPreviewBar_inviter { .mx_RoomPreviewBar_inviter {
font-weight: 600; font-weight: 600;
text-decoration: underline;
cursor: pointer;
} }

View file

@ -579,6 +579,12 @@ export default React.createClass({
}, 0); }, 0);
} }
break; break;
// different from view_user,
// this show the user panel outside of the context
// of a room, like a /user/<id> url
case 'view_user_info':
this._viewUser(payload.userId);
break;
case 'view_room': case 'view_room':
// Takes either a room ID or room alias: if switching to a room the client is already // Takes either a room ID or room alias: if switching to a room the client is already
// known to be in (eg. user clicks on a room in the recents panel), supply the ID // known to be in (eg. user clicks on a room in the recents panel), supply the ID
@ -933,6 +939,22 @@ export default React.createClass({
this.notifyNewScreen('home'); this.notifyNewScreen('home');
}, },
_viewUser: function(userId, action) {
// Wait for the first sync so that `getRoom` gives us a room object if it's
// in the sync response
const waitFor = this.firstSyncPromise ?
this.firstSyncPromise.promise : Promise.resolve();
waitFor.then(() => {
if (action === 'chat') {
this._chatCreateOrReuse(userId);
return;
}
this.notifyNewScreen('user/' + userId);
this.setState({currentUserId: userId});
this._setPage(PageTypes.UserView);
});
},
_setMxId: function(payload) { _setMxId: function(payload) {
const SetMxIdDialog = sdk.getComponent('views.dialogs.SetMxIdDialog'); const SetMxIdDialog = sdk.getComponent('views.dialogs.SetMxIdDialog');
const close = Modal.createTrackedDialog('Set MXID', '', SetMxIdDialog, { const close = Modal.createTrackedDialog('Set MXID', '', SetMxIdDialog, {
@ -1626,20 +1648,7 @@ export default React.createClass({
dis.dispatch(payload); dis.dispatch(payload);
} else if (screen.indexOf('user/') == 0) { } else if (screen.indexOf('user/') == 0) {
const userId = screen.substring(5); const userId = screen.substring(5);
this._viewUser(userId, params.action);
// Wait for the first sync so that `getRoom` gives us a room object if it's
// in the sync response
const waitFor = this.firstSyncPromise ?
this.firstSyncPromise.promise : Promise.resolve();
waitFor.then(() => {
if (params.action === 'chat') {
this._chatCreateOrReuse(userId);
return;
}
this.notifyNewScreen('user/' + userId);
this.setState({currentUserId: userId});
this._setPage(PageTypes.UserView);
});
} else if (screen.indexOf('group/') == 0) { } else if (screen.indexOf('group/') == 0) {
const groupId = screen.substring(6); const groupId = screen.substring(6);

View file

@ -106,6 +106,12 @@ module.exports = React.createClass({
} }
}, },
_onInviterClick(evt) {
evt.preventDefault();
const member = this._getInviteMember();
dis.dispatch({action: 'view_user_info', userId: member.userId});
},
_getMessageCase() { _getMessageCase() {
const isGuest = MatrixClientPeg.get().isGuest(); const isGuest = MatrixClientPeg.get().isGuest();
@ -320,9 +326,16 @@ module.exports = React.createClass({
let inviterElement; let inviterElement;
if (inviteMember) { if (inviteMember) {
const MemberAvatar = sdk.getComponent("views.avatars.MemberAvatar"); const MemberAvatar = sdk.getComponent("views.avatars.MemberAvatar");
avatar = (<MemberAvatar member={inviteMember} viewUserOnClick={true} />); avatar = (<MemberAvatar member={inviteMember} onClick={this._onInviterClick} />);
const colorClass = getUserNameColorClass(inviteMember.userId); const inviterClasses = [
inviterElement = (<span className={`mx_RoomPreviewBar_inviter ${colorClass}`}>{inviteMember.name}</span>); "mx_RoomPreviewBar_inviter",
getUserNameColorClass(inviteMember.userId),
].join(" ");
inviterElement = (
<a onClick={this._onInviterClick} className={inviterClasses}>
{inviteMember.name}
</a>
);
} else { } else {
inviterElement = this.props.inviterName; inviterElement = this.props.inviterName;
} }