2015-10-15 14:14:33 +01:00
|
|
|
/*
|
|
|
|
Copyright 2015 OpenMarket 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var React = require('react');
|
|
|
|
|
|
|
|
var MatrixClientPeg = require('matrix-react-sdk/lib/MatrixClientPeg');
|
|
|
|
var dis = require('matrix-react-sdk/lib/dispatcher');
|
2015-10-15 14:41:12 +01:00
|
|
|
var sdk = require('matrix-react-sdk')
|
|
|
|
var Modal = require('matrix-react-sdk/lib/Modal');
|
2015-11-05 15:59:03 +00:00
|
|
|
var Resend = require("../../../../Resend");
|
2015-10-15 14:14:33 +01:00
|
|
|
|
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'MessageContextMenu',
|
|
|
|
|
|
|
|
onResendClick: function() {
|
2015-11-05 15:59:03 +00:00
|
|
|
Resend.resend(this.props.mxEvent);
|
2015-10-15 14:14:33 +01:00
|
|
|
if (this.props.onFinished) this.props.onFinished();
|
|
|
|
},
|
|
|
|
|
|
|
|
onViewSourceClick: function() {
|
2015-10-15 14:41:12 +01:00
|
|
|
var ViewSource = sdk.getComponent('organisms.ViewSource');
|
|
|
|
Modal.createDialog(ViewSource, {
|
|
|
|
mxEvent: this.props.mxEvent
|
|
|
|
});
|
|
|
|
if (this.props.onFinished) this.props.onFinished();
|
2015-10-15 14:14:33 +01:00
|
|
|
},
|
|
|
|
|
2015-10-21 15:52:35 +01:00
|
|
|
onRedactClick: function() {
|
|
|
|
MatrixClientPeg.get().redactEvent(
|
|
|
|
this.props.mxEvent.getRoomId(), this.props.mxEvent.getId()
|
|
|
|
).done(function() {
|
|
|
|
// message should disappear by itself
|
|
|
|
}, function(e) {
|
|
|
|
var ErrorDialog = sdk.getComponent("organisms.ErrorDialog");
|
|
|
|
// display error message stating you couldn't delete this.
|
|
|
|
var code = e.errcode || e.statusCode;
|
|
|
|
Modal.createDialog(ErrorDialog, {
|
|
|
|
title: "Error",
|
|
|
|
description: "You cannot delete this message. (" + code + ")"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
if (this.props.onFinished) this.props.onFinished();
|
|
|
|
},
|
|
|
|
|
2015-10-15 14:14:33 +01:00
|
|
|
render: function() {
|
|
|
|
var resendButton;
|
|
|
|
var viewSourceButton;
|
2015-10-21 15:52:35 +01:00
|
|
|
var redactButton;
|
2015-10-15 14:14:33 +01:00
|
|
|
|
|
|
|
if (this.props.mxEvent.status == 'not_sent') {
|
|
|
|
resendButton = (
|
|
|
|
<div className="mx_ContextualMenu_field" onClick={this.onResendClick}>
|
|
|
|
Resend
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2015-10-21 15:52:35 +01:00
|
|
|
else {
|
|
|
|
redactButton = (
|
|
|
|
<div className="mx_ContextualMenu_field" onClick={this.onRedactClick}>
|
2015-10-25 02:13:01 +00:00
|
|
|
Redact
|
2015-10-21 15:52:35 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2015-10-15 14:14:33 +01:00
|
|
|
viewSourceButton = (
|
|
|
|
<div className="mx_ContextualMenu_field" onClick={this.onViewSourceClick}>
|
|
|
|
View Source
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{resendButton}
|
2015-10-21 15:52:35 +01:00
|
|
|
{redactButton}
|
2015-10-15 14:14:33 +01:00
|
|
|
{viewSourceButton}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|