diff --git a/client/src/builtin/E2EE.js b/client/src/builtin/E2EE.js
index 0ca2c0f3..8be72a91 100644
--- a/client/src/builtin/E2EE.js
+++ b/client/src/builtin/E2EE.js
@@ -12,7 +12,9 @@ import { Settings } from 'modules';
import BuiltinModule from './BuiltinModule';
import { WebpackModules, ReactComponents, MonkeyPatch, Patcher, DiscordApi } from 'modules';
import { VueInjector, Reflection } from 'ui';
+import { ClientLogger as Logger } from 'common';
import E2EEComponent from './E2EEComponent.vue';
+import E2EEMessageButton from './E2EEMessageButton.vue';
import aes256 from 'aes256';
let seed = Math.random().toString(36).replace(/[^a-z]+/g, '');
@@ -22,6 +24,7 @@ export default new class E2EE extends BuiltinModule {
constructor() {
super();
this.master = this.encrypt(seed, 'temporarymasterkey');
+ this.encryptNewMessages = true;
}
setMaster(key) {
@@ -36,7 +39,7 @@ export default new class E2EE extends BuiltinModule {
}
get database() {
- return Settings.getSet('security').settings.find(s => s.id === 'e2eedb').settings[0].value;
+ return Settings.getSetting('security', 'e2eedb', 'e2ekvps').value;
}
encrypt(key, content, prefix = '') {
@@ -65,10 +68,11 @@ export default new class E2EE extends BuiltinModule {
async patchMessageContent() {
const selector = '.' + WebpackModules.getClassName('container', 'containerCozy', 'containerCompact', 'edited');
const MessageContent = await ReactComponents.getComponent('MessageContent', { selector });
- MonkeyPatch('BD:E2EE', MessageContent.component.prototype).before('render', this.renderMessageContent.bind(this));
+ MonkeyPatch('BD:E2EE', MessageContent.component.prototype).before('render', this.beforeRenderMessageContent.bind(this));
+ MonkeyPatch('BD:E2EE', MessageContent.component.prototype).after('render', this.renderMessageContent.bind(this));
}
- renderMessageContent(component, args, retVal) {
+ beforeRenderMessageContent(component, args, retVal) {
const key = this.getKey(DiscordApi.currentChannel.id);
if (!key) return; // We don't have a key for this channel
@@ -85,14 +89,24 @@ export default new class E2EE extends BuiltinModule {
decrypt = this.decrypt(this.decrypt(this.decrypt(seed, this.master), key), component.props.message.content);
} catch (err) { return } // Ignore errors such as non empty
+ component.props.message.bd_encrypted = true;
+
// Create a new message to parse it properly
- const create = Message.create(MessageParser.createMessage(currentChannel, MessageParser.parse(currentChannel, decrypt).content));
+ const create = Message.create(MessageParser.createMessage(currentChannel, MessageParser.parse(currentChannel, decrypt).content));
if (!create.content || !create.contentParsed) return;
component.props.message.content = create.content;
component.props.message.contentParsed = create.contentParsed;
}
+ renderMessageContent(component, args, retVal) {
+ if (!component.props.message.bd_encrypted) return;
+
+ retVal.props.children[0].props.children.props.children.props.children.unshift(VueInjector.createReactElement(E2EEMessageButton, {
+ message: component.props.message
+ }));
+ }
+
patchChannelTextArea(cta) {
MonkeyPatch('BD:E2EE', cta.component.prototype).after('render', this.renderChannelTextArea);
}
@@ -100,7 +114,7 @@ export default new class E2EE extends BuiltinModule {
renderChannelTextArea(component, args, retVal) {
if (!(retVal.props.children instanceof Array)) retVal.props.children = [retVal.props.children];
const inner = retVal.props.children.find(child => child.props.className && child.props.className.includes('inner'));
- inner.props.children.splice(0, 0, VueInjector.createReactElement(E2EEComponent, {}, false));
+ inner.props.children.splice(0, 0, VueInjector.createReactElement(E2EEComponent));
}
patchChannelTextAreaSubmit(cta) {
@@ -109,7 +123,7 @@ export default new class E2EE extends BuiltinModule {
handleChannelTextAreaSubmit(component, args, retVal) {
const key = this.getKey(DiscordApi.currentChannel.id);
- if (!key) return;
+ if (!this.encryptNewMessages || !key) return;
component.props.value = this.encrypt(this.decrypt(this.decrypt(seed, this.master), key), component.props.value, '$:');
}
diff --git a/client/src/builtin/E2EEComponent.vue b/client/src/builtin/E2EEComponent.vue
index 18228efa..cd8fdb38 100644
--- a/client/src/builtin/E2EEComponent.vue
+++ b/client/src/builtin/E2EEComponent.vue
@@ -10,21 +10,19 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -33,10 +31,12 @@
import { E2EE } from 'builtin';
import { DiscordApi } from 'modules';
import { MiLock } from '../ui/components/common/MaterialIcon';
+
export default {
components: { MiLock },
data() {
return {
+ E2EE,
state: 'loading',
error: null
};
diff --git a/client/src/builtin/E2EEMessageButton.vue b/client/src/builtin/E2EEMessageButton.vue
new file mode 100644
index 00000000..9edf4968
--- /dev/null
+++ b/client/src/builtin/E2EEMessageButton.vue
@@ -0,0 +1,28 @@
+/**
+ * BetterDiscord E2EE Component
+ * Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
+ * All rights reserved.
+ * https://betterdiscord.net
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+*/
+
+
+
+
+
+
diff --git a/client/src/styles/partials/bdsettings/e2ee.scss b/client/src/styles/partials/bdsettings/e2ee.scss
index cb6adf40..b0aaba54 100644
--- a/client/src/styles/partials/bdsettings/e2ee.scss
+++ b/client/src/styles/partials/bdsettings/e2ee.scss
@@ -60,8 +60,25 @@
&.bd-warn {
fill: #ccab3e;
+ }
+
+ &.bd-loading {
animation: bd-pulse 2s ease-in-out infinite;
}
}
}
}
+
+.bd-e2eeMessageButtonWrap {
+ .bd-e2eeMessageButton {
+ fill: #99aab5;
+ margin-left: 6px;
+ margin-right: -2px;
+ opacity: .4;
+ transition: opacity .2s ease;
+
+ &:hover {
+ opacity: 1;
+ }
+ }
+}