General delint, cleanup

This commit is contained in:
lukebarnard 2018-02-06 11:51:46 +00:00
parent e46f436a47
commit 83996c09d9
1 changed files with 33 additions and 32 deletions

View File

@ -20,6 +20,7 @@ limitations under the License.
import Promise from 'bluebird'; import Promise from 'bluebird';
import React from 'react'; import React from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import PropTypes from 'prop-types';
import sdk from 'matrix-react-sdk'; import sdk from 'matrix-react-sdk';
import { _t, _td } from 'matrix-react-sdk/lib/languageHandler'; import { _t, _td } from 'matrix-react-sdk/lib/languageHandler';
import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg'; import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg';
@ -28,14 +29,15 @@ import DMRoomMap from 'matrix-react-sdk/lib/utils/DMRoomMap';
import * as Rooms from 'matrix-react-sdk/lib/Rooms'; import * as Rooms from 'matrix-react-sdk/lib/Rooms';
import * as RoomNotifs from 'matrix-react-sdk/lib/RoomNotifs'; import * as RoomNotifs from 'matrix-react-sdk/lib/RoomNotifs';
import Modal from 'matrix-react-sdk/lib/Modal'; import Modal from 'matrix-react-sdk/lib/Modal';
import RoomListActions from 'matrix-react-sdk/lib/actions/RoomListActions';
module.exports = React.createClass({ module.exports = React.createClass({
displayName: 'RoomTileContextMenu', displayName: 'RoomTileContextMenu',
propTypes: { propTypes: {
room: React.PropTypes.object.isRequired, room: PropTypes.object.isRequired,
/* callback called when the menu is dismissed */ /* callback called when the menu is dismissed */
onFinished: React.PropTypes.func, onFinished: PropTypes.func,
}, },
getInitialState() { getInitialState() {
@ -45,7 +47,7 @@ module.exports = React.createClass({
isFavourite: this.props.room.tags.hasOwnProperty("m.favourite"), isFavourite: this.props.room.tags.hasOwnProperty("m.favourite"),
isLowPriority: this.props.room.tags.hasOwnProperty("m.lowpriority"), isLowPriority: this.props.room.tags.hasOwnProperty("m.lowpriority"),
isDirectMessage: Boolean(dmRoomMap.getUserIdForRoomId(this.props.room.roomId)), isDirectMessage: Boolean(dmRoomMap.getUserIdForRoomId(this.props.room.roomId)),
} };
}, },
componentWillMount: function() { componentWillMount: function() {
@ -132,22 +134,22 @@ module.exports = React.createClass({
}, },
_onClickDM: function() { _onClickDM: function() {
if (MatrixClientPeg.get().isGuest()) return;
const newIsDirectMessage = !this.state.isDirectMessage; const newIsDirectMessage = !this.state.isDirectMessage;
this.setState({ this.setState({
isDirectMessage: newIsDirectMessage, isDirectMessage: newIsDirectMessage,
}); });
if (MatrixClientPeg.get().isGuest()) return;
Rooms.guessAndSetDMRoom( Rooms.guessAndSetDMRoom(
this.props.room, newIsDirectMessage this.props.room, newIsDirectMessage,
).delay(500).finally(() => { ).delay(500).finally(() => {
// Close the context menu // Close the context menu
if (this.props.onFinished) { if (this.props.onFinished) {
this.props.onFinished(); this.props.onFinished();
}; }
}, (err) => { }, (err) => {
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
Modal.createTrackedDialog('Failed to set Direct Message status of room', '', ErrorDialog, { Modal.createTrackedDialog('Failed to set Direct Message status of room', '', ErrorDialog, {
title: _t('Failed to set Direct Message status of room'), title: _t('Failed to set Direct Message status of room'),
description: ((err && err.message) ? err.message : _t('Operation failed')), description: ((err && err.message) ? err.message : _t('Operation failed')),
@ -165,7 +167,7 @@ module.exports = React.createClass({
// Close the context menu // Close the context menu
if (this.props.onFinished) { if (this.props.onFinished) {
this.props.onFinished(); this.props.onFinished();
}; }
}, },
_onClickReject: function() { _onClickReject: function() {
@ -177,7 +179,7 @@ module.exports = React.createClass({
// Close the context menu // Close the context menu
if (this.props.onFinished) { if (this.props.onFinished) {
this.props.onFinished(); this.props.onFinished();
}; }
}, },
_onClickForget: function() { _onClickForget: function() {
@ -185,8 +187,8 @@ module.exports = React.createClass({
MatrixClientPeg.get().forget(this.props.room.roomId).done(function() { MatrixClientPeg.get().forget(this.props.room.roomId).done(function() {
dis.dispatch({ action: 'view_next_room' }); dis.dispatch({ action: 'view_next_room' });
}, function(err) { }, function(err) {
var errCode = err.errcode || _td("unknown error code"); const errCode = err.errcode || _td("unknown error code");
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
Modal.createTrackedDialog('Failed to forget room', '', ErrorDialog, { Modal.createTrackedDialog('Failed to forget room', '', ErrorDialog, {
title: _t('Failed to forget room %(errCode)s', {errCode: errCode}), title: _t('Failed to forget room %(errCode)s', {errCode: errCode}),
description: ((err && err.message) ? err.message : _t('Operation failed')), description: ((err && err.message) ? err.message : _t('Operation failed')),
@ -196,20 +198,19 @@ module.exports = React.createClass({
// Close the context menu // Close the context menu
if (this.props.onFinished) { if (this.props.onFinished) {
this.props.onFinished(); this.props.onFinished();
}; }
}, },
_saveNotifState: function(newState) { _saveNotifState: function(newState) {
if (MatrixClientPeg.get().isGuest()) return;
const oldState = this.state.roomNotifState; const oldState = this.state.roomNotifState;
const roomId = this.props.room.roomId; const roomId = this.props.room.roomId;
var cli = MatrixClientPeg.get();
if (cli.isGuest()) return;
this.setState({ this.setState({
roomNotifState: newState, roomNotifState: newState,
}); });
RoomNotifs.setRoomNotifsState(this.props.room.roomId, newState).done(() => { RoomNotifs.setRoomNotifsState(roomId, newState).done(() => {
// delay slightly so that the user can see their state change // delay slightly so that the user can see their state change
// before closing the menu // before closing the menu
return Promise.delay(500).then(() => { return Promise.delay(500).then(() => {
@ -217,7 +218,7 @@ module.exports = React.createClass({
// Close the context menu // Close the context menu
if (this.props.onFinished) { if (this.props.onFinished) {
this.props.onFinished(); this.props.onFinished();
}; }
}); });
}, (error) => { }, (error) => {
// TODO: some form of error notification to the user // TODO: some form of error notification to the user
@ -247,22 +248,22 @@ module.exports = React.createClass({
}, },
_renderNotifMenu: function() { _renderNotifMenu: function() {
var alertMeClasses = classNames({ const alertMeClasses = classNames({
'mx_RoomTileContextMenu_notif_field': true, 'mx_RoomTileContextMenu_notif_field': true,
'mx_RoomTileContextMenu_notif_fieldSet': this.state.roomNotifState == RoomNotifs.ALL_MESSAGES_LOUD, 'mx_RoomTileContextMenu_notif_fieldSet': this.state.roomNotifState == RoomNotifs.ALL_MESSAGES_LOUD,
}); });
var allNotifsClasses = classNames({ const allNotifsClasses = classNames({
'mx_RoomTileContextMenu_notif_field': true, 'mx_RoomTileContextMenu_notif_field': true,
'mx_RoomTileContextMenu_notif_fieldSet': this.state.roomNotifState == RoomNotifs.ALL_MESSAGES, 'mx_RoomTileContextMenu_notif_fieldSet': this.state.roomNotifState == RoomNotifs.ALL_MESSAGES,
}); });
var mentionsClasses = classNames({ const mentionsClasses = classNames({
'mx_RoomTileContextMenu_notif_field': true, 'mx_RoomTileContextMenu_notif_field': true,
'mx_RoomTileContextMenu_notif_fieldSet': this.state.roomNotifState == RoomNotifs.MENTIONS_ONLY, 'mx_RoomTileContextMenu_notif_fieldSet': this.state.roomNotifState == RoomNotifs.MENTIONS_ONLY,
}); });
var muteNotifsClasses = classNames({ const muteNotifsClasses = classNames({
'mx_RoomTileContextMenu_notif_field': true, 'mx_RoomTileContextMenu_notif_field': true,
'mx_RoomTileContextMenu_notif_fieldSet': this.state.roomNotifState == RoomNotifs.MUTE, 'mx_RoomTileContextMenu_notif_fieldSet': this.state.roomNotifState == RoomNotifs.MUTE,
}); });
@ -372,7 +373,7 @@ module.exports = React.createClass({
render: function() { render: function() {
const myMember = this.props.room.getMember( const myMember = this.props.room.getMember(
MatrixClientPeg.get().credentials.userId MatrixClientPeg.get().credentials.userId,
); );
// Can't set notif level or tags on non-join rooms // Can't set notif level or tags on non-join rooms
@ -389,5 +390,5 @@ module.exports = React.createClass({
{ this._renderRoomTagMenu() } { this._renderRoomTagMenu() }
</div> </div>
); );
} },
}); });