/* Copyright 2017 Vector Creations Ltd 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. */ import React from 'react'; import sdk from '../../../index'; import MatrixClientPeg from '../../../MatrixClientPeg'; import GeminiScrollbar from 'react-gemini-scrollbar'; import Resend from '../../../Resend'; import { _t } from '../../../languageHandler'; function DeviceListEntry(props) { const {userId, device} = props; const DeviceVerifyButtons = sdk.getComponent('elements.DeviceVerifyButtons'); return (
  • { device.deviceId }
    { device.getDisplayName() }
  • ); } DeviceListEntry.propTypes = { userId: React.PropTypes.string.isRequired, // deviceinfo device: React.PropTypes.object.isRequired, }; function UserUnknownDeviceList(props) { const {userId, userDevices} = props; const deviceListEntries = Object.keys(userDevices).map((deviceId) => , ); return ( ); } UserUnknownDeviceList.propTypes = { userId: React.PropTypes.string.isRequired, // map from deviceid -> deviceinfo userDevices: React.PropTypes.object.isRequired, }; function UnknownDeviceList(props) { const {devices} = props; const userListEntries = Object.keys(devices).map((userId) =>
  • { userId }:

  • , ); return ; } UnknownDeviceList.propTypes = { // map from userid -> deviceid -> deviceinfo devices: React.PropTypes.object.isRequired, }; export default React.createClass({ displayName: 'UnknownDeviceDialog', propTypes: { room: React.PropTypes.object.isRequired, onFinished: React.PropTypes.func.isRequired, }, componentWillMount: function() { this._unmounted = false; const roomMembers = this.props.room.getJoinedMembers().map((m) => { return m.userId; }); this.setState({ // map from userid -> deviceid -> deviceinfo devices: null, }); MatrixClientPeg.get().downloadKeys(roomMembers, false).then((devices) => { if (this._unmounted) return; const unknownDevices = {}; // This is all devices in this room, so find the unknown ones. Object.keys(devices).forEach((userId) => { Object.keys(devices[userId]).map((deviceId) => { const device = devices[userId][deviceId]; if (device.isUnverified() && !device.isKnown()) { if (unknownDevices[userId] === undefined) { unknownDevices[userId] = {}; } unknownDevices[userId][deviceId] = device; } // Given we've now shown the user the unknown device, it is no longer // unknown to them. Therefore mark it as 'known'. if (!device.isKnown()) { MatrixClientPeg.get().setDeviceKnown(userId, deviceId, true); } }); }); this.setState({ devices: unknownDevices, }); }); }, componentWillUnmount: function() { this._unmounted = true; }, render: function() { if (this.state.devices === null) { const Spinner = sdk.getComponent("elements.Spinner"); return ; } // The global value is treated as a default for when rooms don't specify a value. const client = MatrixClientPeg.get(); let blacklistUnverified = client.getGlobalBlacklistUnverifiedDevices(); if (this.props.room.getBlacklistUnverifiedDevices() !== null) { blacklistUnverified = this.props.room.getBlacklistUnverifiedDevices(); } let warning; if (blacklistUnverified) { warning = (

    { _t("You are currently blacklisting unverified devices; to send " + "messages to these devices you must verify them.") }

    ); } else { warning = (

    { _t("We recommend you go through the verification process " + "for each device to confirm they belong to their legitimate owner, " + "but you can resend the message without verifying if you prefer.") }

    ); } const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog'); return ( { // XXX: temporary logging to try to diagnose // https://github.com/vector-im/riot-web/issues/3148 console.log("UnknownDeviceDialog closed by escape"); this.props.onFinished(); }} title={_t('Room contains unknown devices')} >

    { _t('"%(RoomName)s" contains devices that you haven\'t seen before.', {RoomName: this.props.room.name}) }

    { warning } { _t("Unknown devices") }:
    ); // XXX: do we want to give the user the option to enable blacklistUnverifiedDevices for this room (or globally) at this point? // It feels like confused users will likely turn it on and then disappear in a cloud of UISIs... }, });