2015-10-15 14:14:33 +01:00
|
|
|
/*
|
2016-01-07 04:17:56 +00:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2015-10-15 14:14:33 +01:00
|
|
|
|
|
|
|
|
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');
|
2016-10-11 19:07:15 +05:30
|
|
|
var sdk = require('matrix-react-sdk');
|
2015-10-15 14:41:12 +01:00
|
|
|
var Modal = require('matrix-react-sdk/lib/Modal');
|
2015-11-30 17:16:31 +00:00
|
|
|
var Resend = require("matrix-react-sdk/lib/Resend");
|
2016-10-11 19:07:15 +05:30
|
|
|
import * as UserSettingsStore from 'matrix-react-sdk/lib/UserSettingsStore';
|
2015-10-15 14:14:33 +01:00
|
|
|
|
|
|
|
|
module.exports = React.createClass({
|
|
|
|
|
displayName: 'MessageContextMenu',
|
|
|
|
|
|
2016-04-08 21:42:42 +01:00
|
|
|
propTypes: {
|
|
|
|
|
/* the MatrixEvent associated with the context menu */
|
|
|
|
|
mxEvent: React.PropTypes.object.isRequired,
|
|
|
|
|
|
|
|
|
|
/* an optional EventTileOps implementation that can be used to unhide preview widgets */
|
|
|
|
|
eventTileOps: React.PropTypes.object,
|
|
|
|
|
|
|
|
|
|
/* callback called when the menu is dismissed */
|
|
|
|
|
onFinished: React.PropTypes.func,
|
|
|
|
|
},
|
|
|
|
|
|
2015-10-15 14:14:33 +01:00
|
|
|
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-12-01 15:45:38 +00:00
|
|
|
var ViewSource = sdk.getComponent('structures.ViewSource');
|
2015-10-15 14:41:12 +01:00
|
|
|
Modal.createDialog(ViewSource, {
|
2016-11-16 23:10:51 +00:00
|
|
|
content: this.props.mxEvent.event,
|
|
|
|
|
}, 'mx_Dialog_viewsource');
|
|
|
|
|
if (this.props.onFinished) this.props.onFinished();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onViewClearSourceClick: function() {
|
2016-11-17 10:51:09 +00:00
|
|
|
const ViewSource = sdk.getComponent('structures.ViewSource');
|
2016-11-16 23:10:51 +00:00
|
|
|
Modal.createDialog(ViewSource, {
|
|
|
|
|
// FIXME: _clearEvent is private
|
|
|
|
|
content: this.props.mxEvent._clearEvent,
|
2016-07-18 10:31:17 +01:00
|
|
|
}, 'mx_Dialog_viewsource');
|
2015-10-15 14:41:12 +01:00
|
|
|
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() {
|
2017-03-18 17:45:13 -07:00
|
|
|
const ConfirmRedactDialog = sdk.getComponent("dialogs.ConfirmRedactDialog");
|
|
|
|
|
Modal.createDialog(ConfirmRedactDialog, {
|
|
|
|
|
onFinished: (proceed) => {
|
|
|
|
|
if (!proceed) return;
|
|
|
|
|
|
|
|
|
|
MatrixClientPeg.get().redactEvent(
|
|
|
|
|
this.props.mxEvent.getRoomId(), this.props.mxEvent.getId()
|
|
|
|
|
).catch(function(e) {
|
|
|
|
|
var ErrorDialog = sdk.getComponent("dialogs.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 + ")"
|
|
|
|
|
});
|
|
|
|
|
}).done();
|
|
|
|
|
},
|
|
|
|
|
}, 'mx_Dialog_confirmredact');
|
2015-10-21 15:52:35 +01:00
|
|
|
if (this.props.onFinished) this.props.onFinished();
|
|
|
|
|
},
|
|
|
|
|
|
2015-12-07 11:38:34 +00:00
|
|
|
onCancelSendClick: function() {
|
|
|
|
|
Resend.removeFromQueue(this.props.mxEvent);
|
2015-12-07 16:04:46 +00:00
|
|
|
if (this.props.onFinished) this.props.onFinished();
|
2015-12-07 11:38:34 +00:00
|
|
|
},
|
|
|
|
|
|
2016-11-08 17:08:50 +00:00
|
|
|
closeMenu: function() {
|
2016-03-19 23:26:04 +00:00
|
|
|
if (this.props.onFinished) this.props.onFinished();
|
|
|
|
|
},
|
|
|
|
|
|
2016-04-03 02:50:51 +01:00
|
|
|
onUnhidePreviewClick: function() {
|
2016-04-08 21:42:42 +01:00
|
|
|
if (this.props.eventTileOps) {
|
|
|
|
|
this.props.eventTileOps.unhideWidget();
|
|
|
|
|
}
|
2016-04-03 23:31:42 +01:00
|
|
|
if (this.props.onFinished) this.props.onFinished();
|
2016-04-03 02:50:51 +01:00
|
|
|
},
|
|
|
|
|
|
2016-09-05 17:39:32 +05:30
|
|
|
onQuoteClick: function () {
|
|
|
|
|
console.log(this.props.mxEvent);
|
|
|
|
|
dis.dispatch({
|
|
|
|
|
action: 'quote',
|
|
|
|
|
event: this.props.mxEvent,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2015-10-15 14:14:33 +01:00
|
|
|
render: function() {
|
2015-12-07 11:38:34 +00:00
|
|
|
var eventStatus = this.props.mxEvent.status;
|
2015-10-15 14:14:33 +01:00
|
|
|
var resendButton;
|
|
|
|
|
var viewSourceButton;
|
2016-11-16 23:10:51 +00:00
|
|
|
var viewClearSourceButton;
|
2015-10-21 15:52:35 +01:00
|
|
|
var redactButton;
|
2015-12-07 11:38:34 +00:00
|
|
|
var cancelButton;
|
2016-03-19 23:26:04 +00:00
|
|
|
var permalinkButton;
|
2016-04-03 02:50:51 +01:00
|
|
|
var unhidePreviewButton;
|
2016-11-08 16:26:10 +00:00
|
|
|
var externalURLButton;
|
2015-10-15 14:14:33 +01:00
|
|
|
|
2015-12-07 11:38:34 +00:00
|
|
|
if (eventStatus === 'not_sent') {
|
2015-10-15 14:14:33 +01:00
|
|
|
resendButton = (
|
2016-07-27 11:26:36 +01:00
|
|
|
<div className="mx_MessageContextMenu_field" onClick={this.onResendClick}>
|
2015-10-15 14:14:33 +01:00
|
|
|
Resend
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2015-12-07 11:38:34 +00:00
|
|
|
|
2017-03-16 17:03:16 +00:00
|
|
|
if (!eventStatus && !this.props.mxEvent.isRedacted()) { // sent and not redacted
|
2015-10-21 15:52:35 +01:00
|
|
|
redactButton = (
|
2016-07-27 11:26:36 +01:00
|
|
|
<div className="mx_MessageContextMenu_field" onClick={this.onRedactClick}>
|
2015-10-25 02:13:01 +00:00
|
|
|
Redact
|
2015-10-21 15:52:35 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2015-12-07 11:38:34 +00:00
|
|
|
|
2015-12-07 13:55:10 +00:00
|
|
|
if (eventStatus === "queued" || eventStatus === "not_sent") {
|
2015-12-07 11:38:34 +00:00
|
|
|
cancelButton = (
|
2016-07-27 11:26:36 +01:00
|
|
|
<div className="mx_MessageContextMenu_field" onClick={this.onCancelSendClick}>
|
2015-12-07 11:38:34 +00:00
|
|
|
Cancel Sending
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-15 14:14:33 +01:00
|
|
|
viewSourceButton = (
|
2016-07-27 11:26:36 +01:00
|
|
|
<div className="mx_MessageContextMenu_field" onClick={this.onViewSourceClick}>
|
2015-10-15 14:14:33 +01:00
|
|
|
View Source
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
2016-11-16 23:10:51 +00:00
|
|
|
if (this.props.mxEvent.getType() !== this.props.mxEvent.getWireType()) {
|
|
|
|
|
viewClearSourceButton = (
|
|
|
|
|
<div className="mx_MessageContextMenu_field" onClick={this.onViewClearSourceClick}>
|
|
|
|
|
View Decrypted Source
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-11 23:54:00 +01:00
|
|
|
if (this.props.eventTileOps) {
|
|
|
|
|
if (this.props.eventTileOps.isWidgetHidden()) {
|
2016-04-03 02:50:51 +01:00
|
|
|
unhidePreviewButton = (
|
2016-07-27 11:26:36 +01:00
|
|
|
<div className="mx_MessageContextMenu_field" onClick={this.onUnhidePreviewClick}>
|
2016-04-03 02:50:51 +01:00
|
|
|
Unhide Preview
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-19 23:26:04 +00:00
|
|
|
// XXX: if we use room ID, we should also include a server where the event can be found (other than in the domain of the event ID)
|
|
|
|
|
permalinkButton = (
|
2016-07-27 11:26:36 +01:00
|
|
|
<div className="mx_MessageContextMenu_field">
|
2016-08-28 02:11:57 +01:00
|
|
|
<a href={ "https://matrix.to/#/" + this.props.mxEvent.getRoomId() +"/"+ this.props.mxEvent.getId() }
|
2016-11-08 17:08:50 +00:00
|
|
|
target="_blank" rel="noopener" onClick={ this.closeMenu }>Permalink</a>
|
2016-03-19 23:26:04 +00:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
2016-09-05 17:39:32 +05:30
|
|
|
const quoteButton = (
|
|
|
|
|
<div className="mx_MessageContextMenu_field" onClick={this.onQuoteClick}>
|
|
|
|
|
Quote
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
2016-11-08 16:26:10 +00:00
|
|
|
// Bridges can provide a 'external_url' to link back to the source.
|
|
|
|
|
if( typeof(this.props.mxEvent.event.content.external_url) === "string") {
|
|
|
|
|
externalURLButton = (
|
|
|
|
|
<div className="mx_MessageContextMenu_field">
|
2016-11-08 17:08:50 +00:00
|
|
|
<a href={ this.props.mxEvent.event.content.external_url }
|
|
|
|
|
rel="noopener" target="_blank" onClick={ this.closeMenu }>Source URL</a>
|
2016-11-08 16:26:10 +00:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-10-15 14:14:33 +01:00
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
{resendButton}
|
2015-10-21 15:52:35 +01:00
|
|
|
{redactButton}
|
2015-12-07 11:38:34 +00:00
|
|
|
{cancelButton}
|
2015-10-15 14:14:33 +01:00
|
|
|
{viewSourceButton}
|
2016-11-16 23:10:51 +00:00
|
|
|
{viewClearSourceButton}
|
2016-04-03 02:50:51 +01:00
|
|
|
{unhidePreviewButton}
|
2016-03-19 23:26:04 +00:00
|
|
|
{permalinkButton}
|
2016-10-11 19:07:15 +05:30
|
|
|
{UserSettingsStore.isFeatureEnabled('rich_text_editor') ? quoteButton : null}
|
2016-11-08 16:26:10 +00:00
|
|
|
{externalURLButton}
|
2015-10-15 14:14:33 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|