2015-11-27 14:50:33 +03:00
|
|
|
/*
|
2016-01-07 07:06:39 +03:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2020-01-31 00:38:40 +03:00
|
|
|
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
|
2015-11-27 14:50:33 +03:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2018-12-19 01:11:08 +03:00
|
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
2019-09-06 17:04:46 +03:00
|
|
|
import React from 'react';
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2019-09-06 17:04:46 +03:00
|
|
|
import createReactClass from 'create-react-class';
|
2019-12-21 00:41:07 +03:00
|
|
|
import * as sdk from "../../../index";
|
2020-05-14 05:41:41 +03:00
|
|
|
import dis from "../../../dispatcher/dispatcher";
|
2017-06-08 16:08:51 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2020-01-31 00:38:40 +03:00
|
|
|
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
2020-05-14 06:03:12 +03:00
|
|
|
import {Action} from "../../../dispatcher/actions";
|
2015-11-27 14:50:33 +03:00
|
|
|
|
2019-12-20 03:45:24 +03:00
|
|
|
export default createReactClass({
|
2015-11-27 14:50:33 +03:00
|
|
|
displayName: 'MemberTile',
|
|
|
|
|
2016-01-13 18:55:28 +03:00
|
|
|
propTypes: {
|
2017-12-26 04:03:18 +03:00
|
|
|
member: PropTypes.any.isRequired, // RoomMember
|
2018-03-19 19:47:12 +03:00
|
|
|
showPresence: PropTypes.bool,
|
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
showPresence: true,
|
|
|
|
};
|
2016-01-13 18:55:28 +03:00
|
|
|
},
|
|
|
|
|
2015-11-27 14:50:33 +03:00
|
|
|
getInitialState: function() {
|
2019-01-15 02:51:42 +03:00
|
|
|
return {
|
|
|
|
statusMessage: this.getStatusMessage(),
|
2020-01-31 00:38:40 +03:00
|
|
|
isRoomEncrypted: false,
|
|
|
|
e2eStatus: null,
|
2019-01-15 02:51:42 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount() {
|
2020-01-31 00:38:40 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
|
|
|
|
if (SettingsStore.isFeatureEnabled("feature_custom_status")) {
|
|
|
|
const { user } = this.props.member;
|
|
|
|
if (user) {
|
|
|
|
user.on("User._unstable_statusMessage", this._onStatusMessageCommitted);
|
|
|
|
}
|
2019-01-15 02:51:42 +03:00
|
|
|
}
|
2020-01-31 00:38:40 +03:00
|
|
|
|
2020-05-27 12:28:25 +03:00
|
|
|
const { roomId } = this.props.member;
|
|
|
|
if (roomId) {
|
|
|
|
const isRoomEncrypted = cli.isRoomEncrypted(roomId);
|
|
|
|
this.setState({
|
|
|
|
isRoomEncrypted,
|
|
|
|
});
|
|
|
|
if (isRoomEncrypted) {
|
|
|
|
cli.on("userTrustStatusChanged", this.onUserTrustStatusChanged);
|
|
|
|
cli.on("deviceVerificationChanged", this.onDeviceVerificationChanged);
|
|
|
|
this.updateE2EStatus();
|
|
|
|
} else {
|
|
|
|
// Listen for room to become encrypted
|
|
|
|
cli.on("RoomState.events", this.onRoomStateEvents);
|
2020-01-31 00:38:40 +03:00
|
|
|
}
|
2019-01-15 02:51:42 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-03-29 05:39:35 +03:00
|
|
|
componentWillUnmount() {
|
2020-01-31 00:38:40 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
|
2019-01-15 02:51:42 +03:00
|
|
|
const { user } = this.props.member;
|
2020-01-31 00:38:40 +03:00
|
|
|
if (user) {
|
|
|
|
user.removeListener(
|
|
|
|
"User._unstable_statusMessage",
|
|
|
|
this._onStatusMessageCommitted,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cli) {
|
|
|
|
cli.removeListener("RoomState.events", this.onRoomStateEvents);
|
|
|
|
cli.removeListener("userTrustStatusChanged", this.onUserTrustStatusChanged);
|
2020-03-25 21:38:12 +03:00
|
|
|
cli.removeListener("deviceVerificationChanged", this.onDeviceVerificationChanged);
|
2020-01-31 00:38:40 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onRoomStateEvents: function(ev) {
|
|
|
|
if (ev.getType() !== "m.room.encryption") return;
|
|
|
|
const { roomId } = this.props.member;
|
|
|
|
if (ev.getRoomId() !== roomId) return;
|
|
|
|
|
|
|
|
// The room is encrypted now.
|
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
cli.removeListener("RoomState.events", this.onRoomStateEvents);
|
|
|
|
this.setState({
|
|
|
|
isRoomEncrypted: true,
|
|
|
|
});
|
|
|
|
this.updateE2EStatus();
|
|
|
|
},
|
|
|
|
|
|
|
|
onUserTrustStatusChanged: function(userId, trustStatus) {
|
|
|
|
if (userId !== this.props.member.userId) return;
|
|
|
|
this.updateE2EStatus();
|
|
|
|
},
|
|
|
|
|
2020-03-25 21:38:12 +03:00
|
|
|
onDeviceVerificationChanged: function(userId, deviceId, deviceInfo) {
|
|
|
|
if (userId !== this.props.member.userId) return;
|
|
|
|
this.updateE2EStatus();
|
|
|
|
},
|
|
|
|
|
2020-01-31 00:38:40 +03:00
|
|
|
updateE2EStatus: async function() {
|
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
const { userId } = this.props.member;
|
|
|
|
const isMe = userId === cli.getUserId();
|
2020-03-28 03:21:17 +03:00
|
|
|
const userTrust = cli.checkUserTrust(userId);
|
|
|
|
if (!userTrust.isCrossSigningVerified()) {
|
2020-01-31 00:38:40 +03:00
|
|
|
this.setState({
|
2020-03-28 03:21:17 +03:00
|
|
|
e2eStatus: userTrust.wasCrossSigningVerified() ? "warning" : "normal",
|
2020-01-31 00:38:40 +03:00
|
|
|
});
|
2019-01-15 02:51:42 +03:00
|
|
|
return;
|
|
|
|
}
|
2020-01-31 00:38:40 +03:00
|
|
|
|
2020-04-29 13:02:22 +03:00
|
|
|
const devices = cli.getStoredDevicesForUser(userId);
|
2020-01-31 00:38:40 +03:00
|
|
|
const anyDeviceUnverified = devices.some(device => {
|
|
|
|
const { deviceId } = device;
|
|
|
|
// For your own devices, we use the stricter check of cross-signing
|
|
|
|
// verification to encourage everyone to trust their own devices via
|
|
|
|
// cross-signing so that other users can then safely trust you.
|
|
|
|
// For other people's devices, the more general verified check that
|
|
|
|
// includes locally verified devices can be used.
|
|
|
|
const deviceTrust = cli.checkDeviceTrust(userId, deviceId);
|
|
|
|
return isMe ? !deviceTrust.isCrossSigningVerified() : !deviceTrust.isVerified();
|
|
|
|
});
|
|
|
|
this.setState({
|
|
|
|
e2eStatus: anyDeviceUnverified ? "warning" : "verified",
|
|
|
|
});
|
2019-01-15 02:51:42 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
getStatusMessage() {
|
|
|
|
const { user } = this.props.member;
|
|
|
|
if (!user) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return user._unstable_statusMessage;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onStatusMessageCommitted() {
|
|
|
|
// The `User` object has observed a status message change.
|
|
|
|
this.setState({
|
|
|
|
statusMessage: this.getStatusMessage(),
|
|
|
|
});
|
2015-11-27 14:50:33 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
shouldComponentUpdate: function(nextProps, nextState) {
|
|
|
|
if (
|
|
|
|
this.member_last_modified_time === undefined ||
|
|
|
|
this.member_last_modified_time < nextProps.member.getLastModifiedTime()
|
|
|
|
) {
|
2016-01-18 18:19:49 +03:00
|
|
|
return true;
|
2015-11-27 14:50:33 +03:00
|
|
|
}
|
|
|
|
if (
|
|
|
|
nextProps.member.user &&
|
|
|
|
(this.user_last_modified_time === undefined ||
|
|
|
|
this.user_last_modified_time < nextProps.member.user.getLastModifiedTime())
|
|
|
|
) {
|
2017-01-20 17:22:27 +03:00
|
|
|
return true;
|
2015-11-27 14:50:33 +03:00
|
|
|
}
|
2020-01-31 00:38:40 +03:00
|
|
|
if (
|
|
|
|
nextState.isRoomEncrypted !== this.state.isRoomEncrypted ||
|
|
|
|
nextState.e2eStatus !== this.state.e2eStatus
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-11-27 14:50:33 +03:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
onClick: function(e) {
|
|
|
|
dis.dispatch({
|
2020-05-14 06:03:12 +03:00
|
|
|
action: Action.ViewUser,
|
2015-11-27 14:50:33 +03:00
|
|
|
member: this.props.member,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-01-13 19:55:28 +03:00
|
|
|
_getDisplayName: function() {
|
|
|
|
return this.props.member.name;
|
|
|
|
},
|
|
|
|
|
2015-11-27 14:50:33 +03:00
|
|
|
getPowerLabel: function() {
|
2019-01-15 02:27:35 +03:00
|
|
|
return _t("%(userName)s (power %(powerLevelNumber)s)", {
|
|
|
|
userName: this.props.member.userId,
|
|
|
|
powerLevelNumber: this.props.member.powerLevel,
|
|
|
|
});
|
2015-11-27 14:50:33 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2017-10-11 19:56:17 +03:00
|
|
|
const MemberAvatar = sdk.getComponent('avatars.MemberAvatar');
|
|
|
|
const EntityTile = sdk.getComponent('rooms.EntityTile');
|
2016-01-18 18:19:49 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const member = this.props.member;
|
|
|
|
const name = this._getDisplayName();
|
|
|
|
const presenceState = member.user ? member.user.presence : null;
|
2018-12-19 01:11:08 +03:00
|
|
|
|
|
|
|
let statusMessage = null;
|
|
|
|
if (member.user && SettingsStore.isFeatureEnabled("feature_custom_status")) {
|
2019-01-15 02:51:42 +03:00
|
|
|
statusMessage = this.state.statusMessage;
|
2018-12-19 01:11:08 +03:00
|
|
|
}
|
2016-01-13 18:55:28 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const av = (
|
2020-02-28 14:40:43 +03:00
|
|
|
<MemberAvatar member={member} width={36} height={36} aria-hidden="true" />
|
2016-01-18 19:55:51 +03:00
|
|
|
);
|
2016-01-18 18:19:49 +03:00
|
|
|
|
2016-01-18 19:55:51 +03:00
|
|
|
if (member.user) {
|
|
|
|
this.user_last_modified_time = member.user.getLastModifiedTime();
|
2016-01-15 19:13:25 +03:00
|
|
|
}
|
2016-01-18 19:55:51 +03:00
|
|
|
this.member_last_modified_time = member.getLastModifiedTime();
|
2016-04-18 03:35:40 +03:00
|
|
|
|
2019-02-27 02:59:40 +03:00
|
|
|
const powerStatusMap = new Map([
|
|
|
|
[100, EntityTile.POWER_STATUS_ADMIN],
|
|
|
|
[50, EntityTile.POWER_STATUS_MODERATOR],
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Find the nearest power level with a badge
|
|
|
|
let powerLevel = this.props.member.powerLevel;
|
|
|
|
for (const [pl] of powerStatusMap) {
|
|
|
|
if (this.props.member.powerLevel >= pl) {
|
|
|
|
powerLevel = pl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const powerStatus = powerStatusMap.get(powerLevel);
|
2017-11-06 19:37:16 +03:00
|
|
|
|
2020-01-31 00:38:40 +03:00
|
|
|
let e2eStatus;
|
|
|
|
if (this.state.isRoomEncrypted) {
|
|
|
|
e2eStatus = this.state.e2eStatus;
|
|
|
|
}
|
|
|
|
|
2015-11-27 14:50:33 +03:00
|
|
|
return (
|
2020-01-31 00:38:40 +03:00
|
|
|
<EntityTile
|
|
|
|
{...this.props}
|
|
|
|
presenceState={presenceState}
|
2017-10-11 19:56:17 +03:00
|
|
|
presenceLastActiveAgo={member.user ? member.user.lastActiveAgo : 0}
|
|
|
|
presenceLastTs={member.user ? member.user.lastPresenceTs : 0}
|
|
|
|
presenceCurrentlyActive={member.user ? member.user.currentlyActive : false}
|
2020-01-31 00:38:40 +03:00
|
|
|
avatarJsx={av}
|
|
|
|
title={this.getPowerLabel()}
|
|
|
|
name={name}
|
|
|
|
powerStatus={powerStatus}
|
|
|
|
showPresence={this.props.showPresence}
|
2018-12-12 07:40:11 +03:00
|
|
|
subtextLabel={statusMessage}
|
2020-01-31 00:38:40 +03:00
|
|
|
e2eStatus={e2eStatus}
|
|
|
|
onClick={this.onClick}
|
2018-12-12 07:40:11 +03:00
|
|
|
/>
|
2015-11-27 14:50:33 +03:00
|
|
|
);
|
2017-10-11 19:56:17 +03:00
|
|
|
},
|
2015-11-27 14:50:33 +03:00
|
|
|
});
|