2017-04-21 14:56:59 +03:00
|
|
|
/*
|
|
|
|
Copyright 2017 Vector Creations Ltd
|
|
|
|
Copyright 2017 Michael Telatynski
|
|
|
|
|
|
|
|
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 MatrixClientPeg from '../../../MatrixClientPeg';
|
|
|
|
import dis from '../../../dispatcher';
|
2017-04-25 00:14:45 +03:00
|
|
|
import KeyCode from '../../../KeyCode';
|
2017-04-21 14:56:59 +03:00
|
|
|
|
|
|
|
|
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'ForwardMessage',
|
|
|
|
|
|
|
|
propTypes: {
|
2017-04-24 22:17:29 +03:00
|
|
|
currentRoomId: React.PropTypes.string.isRequired,
|
2017-05-19 03:29:11 +03:00
|
|
|
|
|
|
|
/* the MatrixEvent to be forwarded */
|
|
|
|
mxEvent: React.PropTypes.object.isRequired,
|
2017-04-21 14:56:59 +03:00
|
|
|
|
|
|
|
onCancelClick: React.PropTypes.func.isRequired,
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillMount: function() {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'ui_opacity',
|
2017-05-19 02:20:32 +03:00
|
|
|
leftOpacity: 1.0,
|
|
|
|
rightOpacity: 0.3,
|
|
|
|
middleOpacity: 0.5,
|
2017-04-21 14:56:59 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount: function() {
|
|
|
|
this.dispatcherRef = dis.register(this.onAction);
|
|
|
|
document.addEventListener('keydown', this._onKeyDown);
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'ui_opacity',
|
|
|
|
sideOpacity: 1.0,
|
|
|
|
middleOpacity: 1.0,
|
|
|
|
});
|
|
|
|
dis.unregister(this.dispatcherRef);
|
|
|
|
document.removeEventListener('keydown', this._onKeyDown);
|
|
|
|
},
|
|
|
|
|
|
|
|
onAction: function(payload) {
|
|
|
|
if (payload.action === 'view_room') {
|
2017-05-19 03:29:11 +03:00
|
|
|
const event = this.props.mxEvent;
|
2017-04-25 00:14:45 +03:00
|
|
|
const Client = MatrixClientPeg.get();
|
2017-05-19 03:29:11 +03:00
|
|
|
Client.sendEvent(payload.room_id, event.getType(), event.getContent()).done(() => {
|
2017-04-25 00:14:45 +03:00
|
|
|
dis.dispatch({action: 'message_sent'});
|
|
|
|
}, (err) => {
|
|
|
|
if (err.name === "UnknownDeviceError") {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'unknown_device_error',
|
|
|
|
err: err,
|
|
|
|
room: Client.getRoom(payload.room_id),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
dis.dispatch({action: 'message_send_failed'});
|
|
|
|
});
|
2017-04-24 22:17:29 +03:00
|
|
|
if (this.props.currentRoomId === payload.room_id) this.props.onCancelClick();
|
2017-04-21 14:56:59 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_onKeyDown: function(ev) {
|
|
|
|
switch (ev.keyCode) {
|
|
|
|
case KeyCode.ESCAPE:
|
|
|
|
this.props.onCancelClick();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<div className="mx_ForwardMessage">
|
2017-05-19 02:34:35 +03:00
|
|
|
<h1>Please select the destination room for this message</h1>
|
2017-04-21 14:56:59 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|