Merge pull request #3279 from matrix-org/t3chguy/remove_withMatrixClient
Remove withMatrixClient as we are committed to using Contexts
This commit is contained in:
commit
8c446bbd29
9 changed files with 80 additions and 117 deletions
|
@ -19,7 +19,7 @@ import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { _t } from '../../../languageHandler';
|
import { _t } from '../../../languageHandler';
|
||||||
|
|
||||||
import * as Matrix from 'matrix-js-sdk';
|
import { MatrixClient } from 'matrix-js-sdk';
|
||||||
import * as MegolmExportEncryption from '../../../utils/MegolmExportEncryption';
|
import * as MegolmExportEncryption from '../../../utils/MegolmExportEncryption';
|
||||||
import sdk from '../../../index';
|
import sdk from '../../../index';
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ export default React.createClass({
|
||||||
displayName: 'ExportE2eKeysDialog',
|
displayName: 'ExportE2eKeysDialog',
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
matrixClient: PropTypes.instanceOf(Matrix.MatrixClient).isRequired,
|
matrixClient: PropTypes.instanceOf(MatrixClient).isRequired,
|
||||||
onFinished: PropTypes.func.isRequired,
|
onFinished: PropTypes.func.isRequired,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import * as Matrix from 'matrix-js-sdk';
|
import { MatrixClient } from 'matrix-js-sdk';
|
||||||
import * as MegolmExportEncryption from '../../../utils/MegolmExportEncryption';
|
import * as MegolmExportEncryption from '../../../utils/MegolmExportEncryption';
|
||||||
import sdk from '../../../index';
|
import sdk from '../../../index';
|
||||||
import { _t } from '../../../languageHandler';
|
import { _t } from '../../../languageHandler';
|
||||||
|
@ -41,7 +41,7 @@ export default React.createClass({
|
||||||
displayName: 'ImportE2eKeysDialog',
|
displayName: 'ImportE2eKeysDialog',
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
matrixClient: PropTypes.instanceOf(Matrix.MatrixClient).isRequired,
|
matrixClient: PropTypes.instanceOf(MatrixClient).isRequired,
|
||||||
onFinished: PropTypes.func.isRequired,
|
onFinished: PropTypes.func.isRequired,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as Matrix from 'matrix-js-sdk';
|
import { MatrixClient } from 'matrix-js-sdk';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { DragDropContext } from 'react-beautiful-dnd';
|
import { DragDropContext } from 'react-beautiful-dnd';
|
||||||
|
@ -62,7 +62,7 @@ const LoggedInView = React.createClass({
|
||||||
displayName: 'LoggedInView',
|
displayName: 'LoggedInView',
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
matrixClient: PropTypes.instanceOf(Matrix.MatrixClient).isRequired,
|
matrixClient: PropTypes.instanceOf(MatrixClient).isRequired,
|
||||||
page_type: PropTypes.string.isRequired,
|
page_type: PropTypes.string.isRequired,
|
||||||
onRoomCreated: PropTypes.func,
|
onRoomCreated: PropTypes.func,
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ const LoggedInView = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
childContextTypes: {
|
childContextTypes: {
|
||||||
matrixClient: PropTypes.instanceOf(Matrix.MatrixClient),
|
matrixClient: PropTypes.instanceOf(MatrixClient),
|
||||||
authCache: PropTypes.object,
|
authCache: PropTypes.object,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2017 Vector Creations Ltd
|
Copyright 2017 Vector Creations Ltd
|
||||||
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -16,19 +17,15 @@ limitations under the License.
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import { MatrixClient } from 'matrix-js-sdk';
|
||||||
import sdk from '../../index';
|
import sdk from '../../index';
|
||||||
import { _t } from '../../languageHandler';
|
import { _t } from '../../languageHandler';
|
||||||
import dis from '../../dispatcher';
|
import dis from '../../dispatcher';
|
||||||
import withMatrixClient from '../../wrappers/withMatrixClient';
|
|
||||||
import AccessibleButton from '../views/elements/AccessibleButton';
|
import AccessibleButton from '../views/elements/AccessibleButton';
|
||||||
|
|
||||||
export default withMatrixClient(React.createClass({
|
export default React.createClass({
|
||||||
displayName: 'MyGroups',
|
displayName: 'MyGroups',
|
||||||
|
|
||||||
propTypes: {
|
|
||||||
matrixClient: PropTypes.object.isRequired,
|
|
||||||
},
|
|
||||||
|
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
groups: null,
|
groups: null,
|
||||||
|
@ -36,6 +33,10 @@ export default withMatrixClient(React.createClass({
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
contextTypes: {
|
||||||
|
matrixClient: PropTypes.instanceOf(MatrixClient).isRequired,
|
||||||
|
},
|
||||||
|
|
||||||
componentWillMount: function() {
|
componentWillMount: function() {
|
||||||
this._fetch();
|
this._fetch();
|
||||||
},
|
},
|
||||||
|
@ -45,7 +46,7 @@ export default withMatrixClient(React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
_fetch: function() {
|
_fetch: function() {
|
||||||
this.props.matrixClient.getJoinedGroups().done((result) => {
|
this.context.matrixClient.getJoinedGroups().done((result) => {
|
||||||
this.setState({groups: result.groups, error: null});
|
this.setState({groups: result.groups, error: null});
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
if (err.errcode === 'M_GUEST_ACCESS_FORBIDDEN') {
|
if (err.errcode === 'M_GUEST_ACCESS_FORBIDDEN') {
|
||||||
|
@ -146,4 +147,4 @@ export default withMatrixClient(React.createClass({
|
||||||
</div>
|
</div>
|
||||||
</div>;
|
</div>;
|
||||||
},
|
},
|
||||||
}));
|
});
|
||||||
|
|
|
@ -134,9 +134,6 @@ Flair.propTypes = {
|
||||||
groups: PropTypes.arrayOf(PropTypes.string),
|
groups: PropTypes.arrayOf(PropTypes.string),
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: We've decided that all components should follow this pattern, which means removing withMatrixClient and using
|
|
||||||
// this.context.matrixClient everywhere instead of this.props.matrixClient.
|
|
||||||
// See https://github.com/vector-im/riot-web/issues/4951.
|
|
||||||
Flair.contextTypes = {
|
Flair.contextTypes = {
|
||||||
matrixClient: PropTypes.instanceOf(MatrixClient).isRequired,
|
matrixClient: PropTypes.instanceOf(MatrixClient).isRequired,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2017 Vector Creations Ltd
|
Copyright 2017 Vector Creations Ltd
|
||||||
Copyright 2017 New Vector Ltd
|
Copyright 2017 New Vector Ltd
|
||||||
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -17,16 +18,15 @@ limitations under the License.
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import { MatrixClient } from 'matrix-js-sdk';
|
||||||
import sdk from '../../../index';
|
import sdk from '../../../index';
|
||||||
import dis from '../../../dispatcher';
|
import dis from '../../../dispatcher';
|
||||||
import { GroupMemberType } from '../../../groups';
|
import { GroupMemberType } from '../../../groups';
|
||||||
import withMatrixClient from '../../../wrappers/withMatrixClient';
|
|
||||||
|
|
||||||
export default withMatrixClient(React.createClass({
|
export default React.createClass({
|
||||||
displayName: 'GroupMemberTile',
|
displayName: 'GroupMemberTile',
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
matrixClient: PropTypes.object,
|
|
||||||
groupId: PropTypes.string.isRequired,
|
groupId: PropTypes.string.isRequired,
|
||||||
member: GroupMemberType.isRequired,
|
member: GroupMemberType.isRequired,
|
||||||
},
|
},
|
||||||
|
@ -35,6 +35,10 @@ export default withMatrixClient(React.createClass({
|
||||||
return {};
|
return {};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
contextTypes: {
|
||||||
|
matrixClient: PropTypes.instanceOf(MatrixClient).isRequired,
|
||||||
|
},
|
||||||
|
|
||||||
onClick: function(e) {
|
onClick: function(e) {
|
||||||
dis.dispatch({
|
dis.dispatch({
|
||||||
action: 'view_group_user',
|
action: 'view_group_user',
|
||||||
|
@ -48,7 +52,7 @@ export default withMatrixClient(React.createClass({
|
||||||
const EntityTile = sdk.getComponent('rooms.EntityTile');
|
const EntityTile = sdk.getComponent('rooms.EntityTile');
|
||||||
|
|
||||||
const name = this.props.member.displayname || this.props.member.userId;
|
const name = this.props.member.displayname || this.props.member.userId;
|
||||||
const avatarUrl = this.props.matrixClient.mxcUrlToHttp(
|
const avatarUrl = this.context.matrixClient.mxcUrlToHttp(
|
||||||
this.props.member.avatarUrl,
|
this.props.member.avatarUrl,
|
||||||
36, 36, 'crop',
|
36, 36, 'crop',
|
||||||
);
|
);
|
||||||
|
@ -67,4 +71,4 @@ export default withMatrixClient(React.createClass({
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
}));
|
});
|
||||||
|
|
|
@ -29,11 +29,10 @@ const Modal = require('../../../Modal');
|
||||||
|
|
||||||
const sdk = require('../../../index');
|
const sdk = require('../../../index');
|
||||||
const TextForEvent = require('../../../TextForEvent');
|
const TextForEvent = require('../../../TextForEvent');
|
||||||
import withMatrixClient from '../../../wrappers/withMatrixClient';
|
|
||||||
|
|
||||||
import dis from '../../../dispatcher';
|
import dis from '../../../dispatcher';
|
||||||
import SettingsStore from "../../../settings/SettingsStore";
|
import SettingsStore from "../../../settings/SettingsStore";
|
||||||
import {EventStatus} from 'matrix-js-sdk';
|
import {EventStatus, MatrixClient} from 'matrix-js-sdk';
|
||||||
|
|
||||||
const ObjectUtils = require('../../../ObjectUtils');
|
const ObjectUtils = require('../../../ObjectUtils');
|
||||||
|
|
||||||
|
@ -85,13 +84,10 @@ const MAX_READ_AVATARS = 5;
|
||||||
// | '--------------------------------------' |
|
// | '--------------------------------------' |
|
||||||
// '----------------------------------------------------------'
|
// '----------------------------------------------------------'
|
||||||
|
|
||||||
module.exports = withMatrixClient(React.createClass({
|
module.exports = React.createClass({
|
||||||
displayName: 'EventTile',
|
displayName: 'EventTile',
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
/* MatrixClient instance for sender verification etc */
|
|
||||||
matrixClient: PropTypes.object.isRequired,
|
|
||||||
|
|
||||||
/* the MatrixEvent to show */
|
/* the MatrixEvent to show */
|
||||||
mxEvent: PropTypes.object.isRequired,
|
mxEvent: PropTypes.object.isRequired,
|
||||||
|
|
||||||
|
@ -192,6 +188,10 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
contextTypes: {
|
||||||
|
matrixClient: PropTypes.instanceOf(MatrixClient).isRequired,
|
||||||
|
},
|
||||||
|
|
||||||
componentWillMount: function() {
|
componentWillMount: function() {
|
||||||
// don't do RR animations until we are mounted
|
// don't do RR animations until we are mounted
|
||||||
this._suppressReadReceiptAnimation = true;
|
this._suppressReadReceiptAnimation = true;
|
||||||
|
@ -200,7 +200,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
|
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
this._suppressReadReceiptAnimation = false;
|
this._suppressReadReceiptAnimation = false;
|
||||||
const client = this.props.matrixClient;
|
const client = this.context.matrixClient;
|
||||||
client.on("deviceVerificationChanged", this.onDeviceVerificationChanged);
|
client.on("deviceVerificationChanged", this.onDeviceVerificationChanged);
|
||||||
this.props.mxEvent.on("Event.decrypted", this._onDecrypted);
|
this.props.mxEvent.on("Event.decrypted", this._onDecrypted);
|
||||||
if (this.props.showReactions) {
|
if (this.props.showReactions) {
|
||||||
|
@ -225,7 +225,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount: function() {
|
componentWillUnmount: function() {
|
||||||
const client = this.props.matrixClient;
|
const client = this.context.matrixClient;
|
||||||
client.removeListener("deviceVerificationChanged", this.onDeviceVerificationChanged);
|
client.removeListener("deviceVerificationChanged", this.onDeviceVerificationChanged);
|
||||||
this.props.mxEvent.removeListener("Event.decrypted", this._onDecrypted);
|
this.props.mxEvent.removeListener("Event.decrypted", this._onDecrypted);
|
||||||
if (this.props.showReactions) {
|
if (this.props.showReactions) {
|
||||||
|
@ -254,7 +254,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const verified = await this.props.matrixClient.isEventSenderVerified(mxEvent);
|
const verified = await this.context.matrixClient.isEventSenderVerified(mxEvent);
|
||||||
this.setState({
|
this.setState({
|
||||||
verified: verified,
|
verified: verified,
|
||||||
}, () => {
|
}, () => {
|
||||||
|
@ -312,11 +312,11 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
shouldHighlight: function() {
|
shouldHighlight: function() {
|
||||||
const actions = this.props.matrixClient.getPushActionsForEvent(this.props.mxEvent);
|
const actions = this.context.matrixClient.getPushActionsForEvent(this.props.mxEvent);
|
||||||
if (!actions || !actions.tweaks) { return false; }
|
if (!actions || !actions.tweaks) { return false; }
|
||||||
|
|
||||||
// don't show self-highlights from another of our clients
|
// don't show self-highlights from another of our clients
|
||||||
if (this.props.mxEvent.getSender() === this.props.matrixClient.credentials.userId) {
|
if (this.props.mxEvent.getSender() === this.context.matrixClient.credentials.userId) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,7 +424,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
// Cancel any outgoing key request for this event and resend it. If a response
|
// Cancel any outgoing key request for this event and resend it. If a response
|
||||||
// is received for the request with the required keys, the event could be
|
// is received for the request with the required keys, the event could be
|
||||||
// decrypted successfully.
|
// decrypted successfully.
|
||||||
this.props.matrixClient.cancelAndResendEventRoomKeyRequest(this.props.mxEvent);
|
this.context.matrixClient.cancelAndResendEventRoomKeyRequest(this.props.mxEvent);
|
||||||
},
|
},
|
||||||
|
|
||||||
onPermalinkClicked: function(e) {
|
onPermalinkClicked: function(e) {
|
||||||
|
@ -457,7 +457,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.props.matrixClient.isRoomEncrypted(ev.getRoomId())) {
|
if (this.context.matrixClient.isRoomEncrypted(ev.getRoomId())) {
|
||||||
// else if room is encrypted
|
// else if room is encrypted
|
||||||
// and event is being encrypted or is not_sent (Unknown Devices/Network Error)
|
// and event is being encrypted or is not_sent (Unknown Devices/Network Error)
|
||||||
if (ev.status === EventStatus.ENCRYPTING) {
|
if (ev.status === EventStatus.ENCRYPTING) {
|
||||||
|
@ -691,7 +691,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
|
|
||||||
switch (this.props.tileShape) {
|
switch (this.props.tileShape) {
|
||||||
case 'notif': {
|
case 'notif': {
|
||||||
const room = this.props.matrixClient.getRoom(this.props.mxEvent.getRoomId());
|
const room = this.context.matrixClient.getRoom(this.props.mxEvent.getRoomId());
|
||||||
return (
|
return (
|
||||||
<div className={classes}>
|
<div className={classes}>
|
||||||
<div className="mx_EventTile_roomName">
|
<div className="mx_EventTile_roomName">
|
||||||
|
@ -816,7 +816,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}));
|
});
|
||||||
|
|
||||||
// XXX this'll eventually be dynamic based on the fields once we have extensible event types
|
// XXX this'll eventually be dynamic based on the fields once we have extensible event types
|
||||||
const messageTypes = ['m.room.message', 'm.sticker'];
|
const messageTypes = ['m.room.message', 'm.sticker'];
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2015, 2016 OpenMarket Ltd
|
Copyright 2015, 2016 OpenMarket Ltd
|
||||||
Copyright 2017, 2018 Vector Creations Ltd
|
Copyright 2017, 2018 Vector Creations Ltd
|
||||||
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -29,6 +30,7 @@ limitations under the License.
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
import { MatrixClient } from 'matrix-js-sdk';
|
||||||
import dis from '../../../dispatcher';
|
import dis from '../../../dispatcher';
|
||||||
import Modal from '../../../Modal';
|
import Modal from '../../../Modal';
|
||||||
import sdk from '../../../index';
|
import sdk from '../../../index';
|
||||||
|
@ -37,7 +39,6 @@ import createRoom from '../../../createRoom';
|
||||||
import DMRoomMap from '../../../utils/DMRoomMap';
|
import DMRoomMap from '../../../utils/DMRoomMap';
|
||||||
import Unread from '../../../Unread';
|
import Unread from '../../../Unread';
|
||||||
import { findReadReceiptFromUserId } from '../../../utils/Receipt';
|
import { findReadReceiptFromUserId } from '../../../utils/Receipt';
|
||||||
import withMatrixClient from '../../../wrappers/withMatrixClient';
|
|
||||||
import AccessibleButton from '../elements/AccessibleButton';
|
import AccessibleButton from '../elements/AccessibleButton';
|
||||||
import RoomViewStore from '../../../stores/RoomViewStore';
|
import RoomViewStore from '../../../stores/RoomViewStore';
|
||||||
import SdkConfig from '../../../SdkConfig';
|
import SdkConfig from '../../../SdkConfig';
|
||||||
|
@ -46,11 +47,10 @@ import SettingsStore from "../../../settings/SettingsStore";
|
||||||
import E2EIcon from "./E2EIcon";
|
import E2EIcon from "./E2EIcon";
|
||||||
import AutoHideScrollbar from "../../structures/AutoHideScrollbar";
|
import AutoHideScrollbar from "../../structures/AutoHideScrollbar";
|
||||||
|
|
||||||
module.exports = withMatrixClient(React.createClass({
|
module.exports = React.createClass({
|
||||||
displayName: 'MemberInfo',
|
displayName: 'MemberInfo',
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
matrixClient: PropTypes.object.isRequired,
|
|
||||||
member: PropTypes.object.isRequired,
|
member: PropTypes.object.isRequired,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -71,13 +71,17 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
contextTypes: {
|
||||||
|
matrixClient: PropTypes.instanceOf(MatrixClient).isRequired,
|
||||||
|
},
|
||||||
|
|
||||||
componentWillMount: function() {
|
componentWillMount: function() {
|
||||||
this._cancelDeviceList = null;
|
this._cancelDeviceList = null;
|
||||||
|
const cli = this.context.matrixClient;
|
||||||
|
|
||||||
// only display the devices list if our client supports E2E
|
// only display the devices list if our client supports E2E
|
||||||
this._enableDevices = this.props.matrixClient.isCryptoEnabled();
|
this._enableDevices = cli.isCryptoEnabled();
|
||||||
|
|
||||||
const cli = this.props.matrixClient;
|
|
||||||
cli.on("deviceVerificationChanged", this.onDeviceVerificationChanged);
|
cli.on("deviceVerificationChanged", this.onDeviceVerificationChanged);
|
||||||
cli.on("Room", this.onRoom);
|
cli.on("Room", this.onRoom);
|
||||||
cli.on("deleteRoom", this.onDeleteRoom);
|
cli.on("deleteRoom", this.onDeleteRoom);
|
||||||
|
@ -103,7 +107,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount: function() {
|
componentWillUnmount: function() {
|
||||||
const client = this.props.matrixClient;
|
const client = this.context.matrixClient;
|
||||||
if (client) {
|
if (client) {
|
||||||
client.removeListener("deviceVerificationChanged", this.onDeviceVerificationChanged);
|
client.removeListener("deviceVerificationChanged", this.onDeviceVerificationChanged);
|
||||||
client.removeListener("Room", this.onRoom);
|
client.removeListener("Room", this.onRoom);
|
||||||
|
@ -122,7 +126,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
_checkIgnoreState: function() {
|
_checkIgnoreState: function() {
|
||||||
const isIgnoring = this.props.matrixClient.isUserIgnored(this.props.member.userId);
|
const isIgnoring = this.context.matrixClient.isUserIgnored(this.props.member.userId);
|
||||||
this.setState({isIgnoring: isIgnoring});
|
this.setState({isIgnoring: isIgnoring});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -154,7 +158,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
|
|
||||||
// Promise.resolve to handle transition from static result to promise; can be removed
|
// Promise.resolve to handle transition from static result to promise; can be removed
|
||||||
// in future
|
// in future
|
||||||
Promise.resolve(this.props.matrixClient.getStoredDevicesForUser(userId)).then((devices) => {
|
Promise.resolve(this.context.matrixClient.getStoredDevicesForUser(userId)).then((devices) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
devices: devices,
|
devices: devices,
|
||||||
e2eStatus: this._getE2EStatus(devices),
|
e2eStatus: this._getE2EStatus(devices),
|
||||||
|
@ -188,7 +192,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
onRoomReceipt: function(receiptEvent, room) {
|
onRoomReceipt: function(receiptEvent, room) {
|
||||||
// because if we read a notification, it will affect notification count
|
// because if we read a notification, it will affect notification count
|
||||||
// only bother updating if there's a receipt from us
|
// only bother updating if there's a receipt from us
|
||||||
if (findReadReceiptFromUserId(receiptEvent, this.props.matrixClient.credentials.userId)) {
|
if (findReadReceiptFromUserId(receiptEvent, this.context.matrixClient.credentials.userId)) {
|
||||||
this.forceUpdate();
|
this.forceUpdate();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -233,7 +237,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
this._cancelDeviceList = function() { cancelled = true; };
|
this._cancelDeviceList = function() { cancelled = true; };
|
||||||
|
|
||||||
const client = this.props.matrixClient;
|
const client = this.context.matrixClient;
|
||||||
const self = this;
|
const self = this;
|
||||||
client.downloadKeys([member.userId], true).then(() => {
|
client.downloadKeys([member.userId], true).then(() => {
|
||||||
return client.getStoredDevicesForUser(member.userId);
|
return client.getStoredDevicesForUser(member.userId);
|
||||||
|
@ -258,7 +262,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
onIgnoreToggle: function() {
|
onIgnoreToggle: function() {
|
||||||
const ignoredUsers = this.props.matrixClient.getIgnoredUsers();
|
const ignoredUsers = this.context.matrixClient.getIgnoredUsers();
|
||||||
if (this.state.isIgnoring) {
|
if (this.state.isIgnoring) {
|
||||||
const index = ignoredUsers.indexOf(this.props.member.userId);
|
const index = ignoredUsers.indexOf(this.props.member.userId);
|
||||||
if (index !== -1) ignoredUsers.splice(index, 1);
|
if (index !== -1) ignoredUsers.splice(index, 1);
|
||||||
|
@ -266,7 +270,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
ignoredUsers.push(this.props.member.userId);
|
ignoredUsers.push(this.props.member.userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.props.matrixClient.setIgnoredUsers(ignoredUsers).then(() => {
|
this.context.matrixClient.setIgnoredUsers(ignoredUsers).then(() => {
|
||||||
return this.setState({isIgnoring: !this.state.isIgnoring});
|
return this.setState({isIgnoring: !this.state.isIgnoring});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -284,7 +288,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
if (!proceed) return;
|
if (!proceed) return;
|
||||||
|
|
||||||
this.setState({ updating: this.state.updating + 1 });
|
this.setState({ updating: this.state.updating + 1 });
|
||||||
this.props.matrixClient.kick(
|
this.context.matrixClient.kick(
|
||||||
this.props.member.roomId, this.props.member.userId,
|
this.props.member.roomId, this.props.member.userId,
|
||||||
reason || undefined,
|
reason || undefined,
|
||||||
).then(function() {
|
).then(function() {
|
||||||
|
@ -320,11 +324,11 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
this.setState({ updating: this.state.updating + 1 });
|
this.setState({ updating: this.state.updating + 1 });
|
||||||
let promise;
|
let promise;
|
||||||
if (this.props.member.membership === 'ban') {
|
if (this.props.member.membership === 'ban') {
|
||||||
promise = this.props.matrixClient.unban(
|
promise = this.context.matrixClient.unban(
|
||||||
this.props.member.roomId, this.props.member.userId,
|
this.props.member.roomId, this.props.member.userId,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
promise = this.props.matrixClient.ban(
|
promise = this.context.matrixClient.ban(
|
||||||
this.props.member.roomId, this.props.member.userId,
|
this.props.member.roomId, this.props.member.userId,
|
||||||
reason || undefined,
|
reason || undefined,
|
||||||
);
|
);
|
||||||
|
@ -370,11 +374,11 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
||||||
const roomId = this.props.member.roomId;
|
const roomId = this.props.member.roomId;
|
||||||
const target = this.props.member.userId;
|
const target = this.props.member.userId;
|
||||||
const room = this.props.matrixClient.getRoom(roomId);
|
const room = this.context.matrixClient.getRoom(roomId);
|
||||||
if (!room) return;
|
if (!room) return;
|
||||||
|
|
||||||
// if muting self, warn as it may be irreversible
|
// if muting self, warn as it may be irreversible
|
||||||
if (target === this.props.matrixClient.getUserId()) {
|
if (target === this.context.matrixClient.getUserId()) {
|
||||||
try {
|
try {
|
||||||
if (!(await this._warnSelfDemote())) return;
|
if (!(await this._warnSelfDemote())) return;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -402,7 +406,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
|
|
||||||
if (!isNaN(level)) {
|
if (!isNaN(level)) {
|
||||||
this.setState({ updating: this.state.updating + 1 });
|
this.setState({ updating: this.state.updating + 1 });
|
||||||
this.props.matrixClient.setPowerLevel(roomId, target, level, powerLevelEvent).then(
|
this.context.matrixClient.setPowerLevel(roomId, target, level, powerLevelEvent).then(
|
||||||
function() {
|
function() {
|
||||||
// NO-OP; rely on the m.room.member event coming down else we could
|
// NO-OP; rely on the m.room.member event coming down else we could
|
||||||
// get out of sync if we force setState here!
|
// get out of sync if we force setState here!
|
||||||
|
@ -424,13 +428,13 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
||||||
const roomId = this.props.member.roomId;
|
const roomId = this.props.member.roomId;
|
||||||
const target = this.props.member.userId;
|
const target = this.props.member.userId;
|
||||||
const room = this.props.matrixClient.getRoom(roomId);
|
const room = this.context.matrixClient.getRoom(roomId);
|
||||||
if (!room) return;
|
if (!room) return;
|
||||||
|
|
||||||
const powerLevelEvent = room.currentState.getStateEvents("m.room.power_levels", "");
|
const powerLevelEvent = room.currentState.getStateEvents("m.room.power_levels", "");
|
||||||
if (!powerLevelEvent) return;
|
if (!powerLevelEvent) return;
|
||||||
|
|
||||||
const me = room.getMember(this.props.matrixClient.credentials.userId);
|
const me = room.getMember(this.context.matrixClient.credentials.userId);
|
||||||
if (!me) return;
|
if (!me) return;
|
||||||
|
|
||||||
const defaultLevel = powerLevelEvent.getContent().users_default;
|
const defaultLevel = powerLevelEvent.getContent().users_default;
|
||||||
|
@ -439,7 +443,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
// toggle the level
|
// toggle the level
|
||||||
const newLevel = this.state.isTargetMod ? defaultLevel : modLevel;
|
const newLevel = this.state.isTargetMod ? defaultLevel : modLevel;
|
||||||
this.setState({ updating: this.state.updating + 1 });
|
this.setState({ updating: this.state.updating + 1 });
|
||||||
this.props.matrixClient.setPowerLevel(roomId, target, parseInt(newLevel), powerLevelEvent).then(
|
this.context.matrixClient.setPowerLevel(roomId, target, parseInt(newLevel), powerLevelEvent).then(
|
||||||
function() {
|
function() {
|
||||||
// NO-OP; rely on the m.room.member event coming down else we could
|
// NO-OP; rely on the m.room.member event coming down else we could
|
||||||
// get out of sync if we force setState here!
|
// get out of sync if we force setState here!
|
||||||
|
@ -462,7 +466,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
|
|
||||||
_applyPowerChange: function(roomId, target, powerLevel, powerLevelEvent) {
|
_applyPowerChange: function(roomId, target, powerLevel, powerLevelEvent) {
|
||||||
this.setState({ updating: this.state.updating + 1 });
|
this.setState({ updating: this.state.updating + 1 });
|
||||||
this.props.matrixClient.setPowerLevel(roomId, target, parseInt(powerLevel), powerLevelEvent).then(
|
this.context.matrixClient.setPowerLevel(roomId, target, parseInt(powerLevel), powerLevelEvent).then(
|
||||||
function() {
|
function() {
|
||||||
// NO-OP; rely on the m.room.member event coming down else we could
|
// NO-OP; rely on the m.room.member event coming down else we could
|
||||||
// get out of sync if we force setState here!
|
// get out of sync if we force setState here!
|
||||||
|
@ -483,7 +487,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
onPowerChange: async function(powerLevel) {
|
onPowerChange: async function(powerLevel) {
|
||||||
const roomId = this.props.member.roomId;
|
const roomId = this.props.member.roomId;
|
||||||
const target = this.props.member.userId;
|
const target = this.props.member.userId;
|
||||||
const room = this.props.matrixClient.getRoom(roomId);
|
const room = this.context.matrixClient.getRoom(roomId);
|
||||||
if (!room) return;
|
if (!room) return;
|
||||||
|
|
||||||
const powerLevelEvent = room.currentState.getStateEvents("m.room.power_levels", "");
|
const powerLevelEvent = room.currentState.getStateEvents("m.room.power_levels", "");
|
||||||
|
@ -494,7 +498,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const myUserId = this.props.matrixClient.getUserId();
|
const myUserId = this.context.matrixClient.getUserId();
|
||||||
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
|
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
|
||||||
|
|
||||||
// If we are changing our own PL it can only ever be decreasing, which we cannot reverse.
|
// If we are changing our own PL it can only ever be decreasing, which we cannot reverse.
|
||||||
|
@ -549,13 +553,13 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
can: {},
|
can: {},
|
||||||
muted: false,
|
muted: false,
|
||||||
};
|
};
|
||||||
const room = this.props.matrixClient.getRoom(member.roomId);
|
const room = this.context.matrixClient.getRoom(member.roomId);
|
||||||
if (!room) return defaultPerms;
|
if (!room) return defaultPerms;
|
||||||
|
|
||||||
const powerLevels = room.currentState.getStateEvents("m.room.power_levels", "");
|
const powerLevels = room.currentState.getStateEvents("m.room.power_levels", "");
|
||||||
if (!powerLevels) return defaultPerms;
|
if (!powerLevels) return defaultPerms;
|
||||||
|
|
||||||
const me = room.getMember(this.props.matrixClient.credentials.userId);
|
const me = room.getMember(this.context.matrixClient.credentials.userId);
|
||||||
if (!me) return defaultPerms;
|
if (!me) return defaultPerms;
|
||||||
|
|
||||||
const them = member;
|
const them = member;
|
||||||
|
@ -619,7 +623,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
const avatarUrl = member.getMxcAvatarUrl();
|
const avatarUrl = member.getMxcAvatarUrl();
|
||||||
if (!avatarUrl) return;
|
if (!avatarUrl) return;
|
||||||
|
|
||||||
const httpUrl = this.props.matrixClient.mxcUrlToHttp(avatarUrl);
|
const httpUrl = this.context.matrixClient.mxcUrlToHttp(avatarUrl);
|
||||||
const ImageView = sdk.getComponent("elements.ImageView");
|
const ImageView = sdk.getComponent("elements.ImageView");
|
||||||
const params = {
|
const params = {
|
||||||
src: httpUrl,
|
src: httpUrl,
|
||||||
|
@ -678,7 +682,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
_renderUserOptions: function() {
|
_renderUserOptions: function() {
|
||||||
const cli = this.props.matrixClient;
|
const cli = this.context.matrixClient;
|
||||||
const member = this.props.member;
|
const member = this.props.member;
|
||||||
|
|
||||||
let ignoreButton = null;
|
let ignoreButton = null;
|
||||||
|
@ -784,8 +788,8 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
let giveModButton;
|
let giveModButton;
|
||||||
let spinner;
|
let spinner;
|
||||||
|
|
||||||
if (this.props.member.userId !== this.props.matrixClient.credentials.userId) {
|
if (this.props.member.userId !== this.context.matrixClient.credentials.userId) {
|
||||||
const dmRoomMap = new DMRoomMap(this.props.matrixClient);
|
const dmRoomMap = new DMRoomMap(this.context.matrixClient);
|
||||||
// dmRooms will not include dmRooms that we have been invited into but did not join.
|
// dmRooms will not include dmRooms that we have been invited into but did not join.
|
||||||
// Because DMRoomMap runs off account_data[m.direct] which is only set on join of dm room.
|
// Because DMRoomMap runs off account_data[m.direct] which is only set on join of dm room.
|
||||||
// XXX: we potentially want DMs we have been invited to, to also show up here :L
|
// XXX: we potentially want DMs we have been invited to, to also show up here :L
|
||||||
|
@ -796,7 +800,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
|
|
||||||
const tiles = [];
|
const tiles = [];
|
||||||
for (const roomId of dmRooms) {
|
for (const roomId of dmRooms) {
|
||||||
const room = this.props.matrixClient.getRoom(roomId);
|
const room = this.context.matrixClient.getRoom(roomId);
|
||||||
if (room) {
|
if (room) {
|
||||||
const myMembership = room.getMyMembership();
|
const myMembership = room.getMyMembership();
|
||||||
// not a DM room if we have are not joined
|
// not a DM room if we have are not joined
|
||||||
|
@ -918,12 +922,12 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const room = this.props.matrixClient.getRoom(this.props.member.roomId);
|
const room = this.context.matrixClient.getRoom(this.props.member.roomId);
|
||||||
const powerLevelEvent = room ? room.currentState.getStateEvents("m.room.power_levels", "") : null;
|
const powerLevelEvent = room ? room.currentState.getStateEvents("m.room.power_levels", "") : null;
|
||||||
const powerLevelUsersDefault = powerLevelEvent ? powerLevelEvent.getContent().users_default : 0;
|
const powerLevelUsersDefault = powerLevelEvent ? powerLevelEvent.getContent().users_default : 0;
|
||||||
|
|
||||||
const enablePresenceByHsUrl = SdkConfig.get()["enable_presence_by_hs_url"];
|
const enablePresenceByHsUrl = SdkConfig.get()["enable_presence_by_hs_url"];
|
||||||
const hsUrl = this.props.matrixClient.baseUrl;
|
const hsUrl = this.context.matrixClient.baseUrl;
|
||||||
let showPresence = true;
|
let showPresence = true;
|
||||||
if (enablePresenceByHsUrl && enablePresenceByHsUrl[hsUrl] !== undefined) {
|
if (enablePresenceByHsUrl && enablePresenceByHsUrl[hsUrl] !== undefined) {
|
||||||
showPresence = enablePresenceByHsUrl[hsUrl];
|
showPresence = enablePresenceByHsUrl[hsUrl];
|
||||||
|
@ -962,7 +966,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
</div>
|
</div>
|
||||||
</div>;
|
</div>;
|
||||||
|
|
||||||
const isEncrypted = this.props.matrixClient.isRoomEncrypted(this.props.member.roomId);
|
const isEncrypted = this.context.matrixClient.isRoomEncrypted(this.props.member.roomId);
|
||||||
if (this.state.e2eStatus && isEncrypted) {
|
if (this.state.e2eStatus && isEncrypted) {
|
||||||
e2eIconElement = (<E2EIcon status={this.state.e2eStatus} isUser={true} />);
|
e2eIconElement = (<E2EIcon status={this.state.e2eStatus} isUser={true} />);
|
||||||
}
|
}
|
||||||
|
@ -971,14 +975,12 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
const avatarUrl = this.props.member.getMxcAvatarUrl();
|
const avatarUrl = this.props.member.getMxcAvatarUrl();
|
||||||
let avatarElement;
|
let avatarElement;
|
||||||
if (avatarUrl) {
|
if (avatarUrl) {
|
||||||
const httpUrl = this.props.matrixClient.mxcUrlToHttp(avatarUrl, 800, 800);
|
const httpUrl = this.context.matrixClient.mxcUrlToHttp(avatarUrl, 800, 800);
|
||||||
avatarElement = <div className="mx_MemberInfo_avatar">
|
avatarElement = <div className="mx_MemberInfo_avatar">
|
||||||
<img src={httpUrl} />
|
<img src={httpUrl} />
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const GeminiScrollbarWrapper = sdk.getComponent("elements.GeminiScrollbarWrapper");
|
|
||||||
|
|
||||||
let backButton;
|
let backButton;
|
||||||
if (this.props.member.roomId) {
|
if (this.props.member.roomId) {
|
||||||
backButton = (<AccessibleButton className="mx_MemberInfo_cancel"
|
backButton = (<AccessibleButton className="mx_MemberInfo_cancel"
|
||||||
|
@ -1020,4 +1022,4 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
}));
|
});
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright 2015, 2016 OpenMarket Ltd
|
|
||||||
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 * as Matrix from 'matrix-js-sdk';
|
|
||||||
import React from 'react';
|
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wraps a react class, pulling the MatrixClient from the context and adding it
|
|
||||||
* as a 'matrixClient' property instead.
|
|
||||||
*
|
|
||||||
* This abstracts the use of the context API, so that we can use a different
|
|
||||||
* mechanism in future.
|
|
||||||
*/
|
|
||||||
export default function(WrappedComponent) {
|
|
||||||
return React.createClass({
|
|
||||||
displayName: "withMatrixClient<" + WrappedComponent.displayName + ">",
|
|
||||||
|
|
||||||
contextTypes: {
|
|
||||||
matrixClient: PropTypes.instanceOf(Matrix.MatrixClient).isRequired,
|
|
||||||
},
|
|
||||||
|
|
||||||
render: function() {
|
|
||||||
return <WrappedComponent {...this.props} matrixClient={this.context.matrixClient} />;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
Loading…
Reference in a new issue