From 81d70a921df18ac86291a95b3b95f725668647c7 Mon Sep 17 00:00:00 2001
From: Richard van der Hoff <richard@matrix.org>
Date: Wed, 16 Nov 2016 23:10:51 +0000
Subject: [PATCH] Add a 'View decrypted source' button

---
 src/components/structures/ViewSource.js       |  6 +++---
 .../views/context_menus/MessageContextMenu.js | 21 ++++++++++++++++++-
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/src/components/structures/ViewSource.js b/src/components/structures/ViewSource.js
index 1dbc5319c1..a0e198cecc 100644
--- a/src/components/structures/ViewSource.js
+++ b/src/components/structures/ViewSource.js
@@ -22,7 +22,8 @@ module.exports = React.createClass({
     displayName: 'ViewSource',
 
     propTypes: {
-        onFinished: React.PropTypes.func.isRequired
+        content: React.PropTypes.object.isRequired,
+        onFinished: React.PropTypes.func.isRequired,
     },
 
     componentDidMount: function() {
@@ -45,10 +46,9 @@ module.exports = React.createClass({
         return (
             <div className="mx_ViewSource">
                 <pre>
-                    {JSON.stringify(this.props.mxEvent.event, null, 2)}
+                    {JSON.stringify(this.props.content, null, 2)}
                 </pre>
             </div>
         );
     }
 });
-
diff --git a/src/components/views/context_menus/MessageContextMenu.js b/src/components/views/context_menus/MessageContextMenu.js
index 7786b9bd5d..4b62b87edb 100644
--- a/src/components/views/context_menus/MessageContextMenu.js
+++ b/src/components/views/context_menus/MessageContextMenu.js
@@ -47,7 +47,16 @@ module.exports = React.createClass({
     onViewSourceClick: function() {
         var ViewSource = sdk.getComponent('structures.ViewSource');
         Modal.createDialog(ViewSource, {
-            mxEvent: this.props.mxEvent
+            content: this.props.mxEvent.event,
+        }, 'mx_Dialog_viewsource');
+        if (this.props.onFinished) this.props.onFinished();
+    },
+
+    onViewClearSourceClick: function() {
+        var ViewSource = sdk.getComponent('structures.ViewSource');
+        Modal.createDialog(ViewSource, {
+            // FIXME: _clearEvent is private
+            content: this.props.mxEvent._clearEvent,
         }, 'mx_Dialog_viewsource');
         if (this.props.onFinished) this.props.onFinished();
     },
@@ -97,6 +106,7 @@ module.exports = React.createClass({
         var eventStatus = this.props.mxEvent.status;
         var resendButton;
         var viewSourceButton;
+        var viewClearSourceButton;
         var redactButton;
         var cancelButton;
         var permalinkButton;
@@ -133,6 +143,14 @@ module.exports = React.createClass({
             </div>
         );
 
+        if (this.props.mxEvent.getType() !== this.props.mxEvent.getWireType()) {
+            viewClearSourceButton = (
+                <div className="mx_MessageContextMenu_field" onClick={this.onViewClearSourceClick}>
+                    View Decrypted Source
+                </div>
+            );
+        }
+
         if (this.props.eventTileOps) {
             if (this.props.eventTileOps.isWidgetHidden()) {
                 unhidePreviewButton = (
@@ -174,6 +192,7 @@ module.exports = React.createClass({
                 {redactButton}
                 {cancelButton}
                 {viewSourceButton}
+                {viewClearSourceButton}
                 {unhidePreviewButton}
                 {permalinkButton}
                 {UserSettingsStore.isFeatureEnabled('rich_text_editor') ? quoteButton : null}