2020-01-17 19:10:59 +03:00
|
|
|
/*
|
2021-04-06 14:26:50 +03:00
|
|
|
Copyright 2020-2021 The Matrix.org Foundation C.I.C.
|
2020-01-17 19:10:59 +03: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import { _t } from '../../../languageHandler';
|
2020-07-10 21:07:11 +03:00
|
|
|
import SdkConfig from "../../../SdkConfig";
|
2020-01-17 19:10:59 +03:00
|
|
|
import Modal from '../../../Modal';
|
2020-07-28 20:53:43 +03:00
|
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
2020-01-21 15:20:30 +03:00
|
|
|
import AccessibleButton from "../elements/AccessibleButton";
|
2021-06-29 15:11:58 +03:00
|
|
|
import { formatBytes, formatCountLong } from "../../../utils/FormattingUtils";
|
2020-01-17 19:10:59 +03:00
|
|
|
import EventIndexPeg from "../../../indexing/EventIndexPeg";
|
2021-06-29 15:11:58 +03:00
|
|
|
import { SettingLevel } from "../../../settings/SettingLevel";
|
|
|
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
2021-03-26 12:44:52 +03:00
|
|
|
import SeshatResetDialog from '../dialogs/SeshatResetDialog';
|
2021-07-03 11:06:42 +03:00
|
|
|
import InlineSpinner from '../elements/InlineSpinner';
|
2020-01-17 19:10:59 +03:00
|
|
|
|
2021-04-06 14:26:50 +03:00
|
|
|
interface IState {
|
|
|
|
enabling: boolean;
|
|
|
|
eventIndexSize: number;
|
|
|
|
roomCount: number;
|
|
|
|
eventIndexingEnabled: boolean;
|
|
|
|
}
|
|
|
|
|
2021-03-09 06:20:07 +03:00
|
|
|
@replaceableComponent("views.settings.EventIndexPanel")
|
2021-04-06 14:26:50 +03:00
|
|
|
export default class EventIndexPanel extends React.Component<{}, IState> {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2020-01-17 19:10:59 +03:00
|
|
|
|
|
|
|
this.state = {
|
2020-01-23 17:06:38 +03:00
|
|
|
enabling: false,
|
2020-01-17 19:10:59 +03:00
|
|
|
eventIndexSize: 0,
|
2020-01-20 19:42:24 +03:00
|
|
|
roomCount: 0,
|
2020-01-23 16:27:46 +03:00
|
|
|
eventIndexingEnabled:
|
|
|
|
SettingsStore.getValueAt(SettingLevel.DEVICE, 'enableEventIndexing'),
|
2020-01-17 19:10:59 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-02-20 05:35:30 +03:00
|
|
|
updateCurrentRoom = async (room) => {
|
2020-01-20 19:43:55 +03:00
|
|
|
const eventIndex = EventIndexPeg.get();
|
2020-02-18 14:21:47 +03:00
|
|
|
let stats;
|
|
|
|
|
|
|
|
try {
|
|
|
|
stats = await eventIndex.getStats();
|
|
|
|
} catch {
|
2020-02-19 16:17:19 +03:00
|
|
|
// This call may fail if sporadically, not a huge issue as we will
|
|
|
|
// try later again and probably succeed.
|
2020-02-18 14:21:47 +03:00
|
|
|
return;
|
|
|
|
}
|
2020-01-20 19:43:55 +03:00
|
|
|
|
|
|
|
this.setState({
|
|
|
|
eventIndexSize: stats.size,
|
|
|
|
roomCount: stats.roomCount,
|
|
|
|
});
|
2020-02-20 05:35:30 +03:00
|
|
|
};
|
2020-01-20 19:43:55 +03:00
|
|
|
|
|
|
|
componentWillUnmount(): void {
|
|
|
|
const eventIndex = EventIndexPeg.get();
|
|
|
|
|
|
|
|
if (eventIndex !== null) {
|
2020-02-20 05:35:30 +03:00
|
|
|
eventIndex.removeListener("changedCheckpoint", this.updateCurrentRoom);
|
2020-01-20 19:43:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-06 14:26:50 +03:00
|
|
|
componentDidMount(): void {
|
2020-01-23 16:27:46 +03:00
|
|
|
this.updateState();
|
|
|
|
}
|
|
|
|
|
|
|
|
async updateState() {
|
2020-01-17 19:10:59 +03:00
|
|
|
const eventIndex = EventIndexPeg.get();
|
2020-01-23 16:27:46 +03:00
|
|
|
const eventIndexingEnabled = SettingsStore.getValueAt(SettingLevel.DEVICE, 'enableEventIndexing');
|
2020-01-23 17:06:38 +03:00
|
|
|
const enabling = false;
|
|
|
|
|
|
|
|
let eventIndexSize = 0;
|
|
|
|
let roomCount = 0;
|
2020-01-17 19:10:59 +03:00
|
|
|
|
|
|
|
if (eventIndex !== null) {
|
2020-02-20 05:35:30 +03:00
|
|
|
eventIndex.on("changedCheckpoint", this.updateCurrentRoom);
|
2020-01-20 19:43:55 +03:00
|
|
|
|
2020-02-18 14:21:47 +03:00
|
|
|
try {
|
|
|
|
const stats = await eventIndex.getStats();
|
|
|
|
eventIndexSize = stats.size;
|
|
|
|
roomCount = stats.roomCount;
|
|
|
|
} catch {
|
2020-02-19 16:17:19 +03:00
|
|
|
// This call may fail if sporadically, not a huge issue as we
|
|
|
|
// will try later again in the updateCurrentRoom call and
|
|
|
|
// probably succeed.
|
2020-02-18 14:21:47 +03:00
|
|
|
}
|
2020-01-17 19:10:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({
|
2020-01-23 17:06:38 +03:00
|
|
|
enabling,
|
2020-01-17 19:10:59 +03:00
|
|
|
eventIndexSize,
|
2020-01-20 19:42:24 +03:00
|
|
|
roomCount,
|
2020-01-23 16:27:46 +03:00
|
|
|
eventIndexingEnabled,
|
2020-01-17 19:10:59 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-26 16:02:53 +03:00
|
|
|
private onManage = async () => {
|
2020-01-21 15:20:30 +03:00
|
|
|
Modal.createTrackedDialogAsync('Message search', 'Message search',
|
2021-04-06 14:26:50 +03:00
|
|
|
// @ts-ignore: TS doesn't seem to like the type of this now that it
|
|
|
|
// has also been converted to TS as well, but I can't figure out why...
|
2020-01-24 11:54:46 +03:00
|
|
|
import('../../../async-components/views/dialogs/eventindex/ManageEventIndexDialog'),
|
2020-01-21 15:20:30 +03:00
|
|
|
{
|
|
|
|
onFinished: () => {},
|
|
|
|
}, null, /* priority = */ false, /* static = */ true,
|
|
|
|
);
|
2021-06-29 15:11:58 +03:00
|
|
|
};
|
2020-01-17 19:10:59 +03:00
|
|
|
|
2021-04-26 16:02:53 +03:00
|
|
|
private onEnable = async () => {
|
2020-01-23 17:06:38 +03:00
|
|
|
this.setState({
|
|
|
|
enabling: true,
|
|
|
|
});
|
|
|
|
|
2020-01-23 16:27:46 +03:00
|
|
|
await EventIndexPeg.initEventIndex();
|
|
|
|
await EventIndexPeg.get().addInitialCheckpoints();
|
|
|
|
await EventIndexPeg.get().startCrawler();
|
|
|
|
await SettingsStore.setValue('enableEventIndexing', null, SettingLevel.DEVICE, true);
|
|
|
|
await this.updateState();
|
2021-06-29 15:11:58 +03:00
|
|
|
};
|
2020-01-23 16:27:46 +03:00
|
|
|
|
2021-04-26 16:02:53 +03:00
|
|
|
private confirmEventStoreReset = () => {
|
2021-03-29 17:46:58 +03:00
|
|
|
const { close } = Modal.createDialog(SeshatResetDialog, {
|
|
|
|
onFinished: async (success) => {
|
2021-03-26 12:44:52 +03:00
|
|
|
if (success) {
|
2021-03-29 17:46:58 +03:00
|
|
|
await SettingsStore.setValue('enableEventIndexing', null, SettingLevel.DEVICE, false);
|
|
|
|
await EventIndexPeg.deleteEventIndex();
|
2021-04-26 16:02:53 +03:00
|
|
|
await this.onEnable();
|
2021-03-29 17:46:58 +03:00
|
|
|
close();
|
2021-03-26 12:44:52 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2021-06-29 15:11:58 +03:00
|
|
|
};
|
2021-03-26 12:44:52 +03:00
|
|
|
|
2020-01-17 19:10:59 +03:00
|
|
|
render() {
|
|
|
|
let eventIndexingSettings = null;
|
2020-07-10 21:07:11 +03:00
|
|
|
const brand = SdkConfig.get().brand;
|
2020-01-17 19:10:59 +03:00
|
|
|
|
|
|
|
if (EventIndexPeg.get() !== null) {
|
|
|
|
eventIndexingSettings = (
|
2020-01-21 12:06:04 +03:00
|
|
|
<div>
|
2021-07-20 00:43:11 +03:00
|
|
|
<div className='mx_SettingsTab_subsectionText'>{ _t(
|
2021-04-23 20:11:54 +03:00
|
|
|
"Securely cache encrypted messages locally for them " +
|
|
|
|
"to appear in search results, using %(size)s to store messages from %(rooms)s rooms.",
|
|
|
|
{
|
|
|
|
size: formatBytes(this.state.eventIndexSize, 0),
|
|
|
|
// This drives the singular / plural string
|
|
|
|
// selection for "room" / "rooms" only.
|
|
|
|
count: this.state.roomCount,
|
|
|
|
rooms: formatCountLong(this.state.roomCount),
|
|
|
|
},
|
2021-07-20 00:43:11 +03:00
|
|
|
) }</div>
|
2020-01-21 15:20:30 +03:00
|
|
|
<div>
|
2021-04-26 16:02:53 +03:00
|
|
|
<AccessibleButton kind="primary" onClick={this.onManage}>
|
2021-07-20 00:43:11 +03:00
|
|
|
{ _t("Manage") }
|
2020-01-21 15:20:30 +03:00
|
|
|
</AccessibleButton>
|
2020-01-17 19:10:59 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2020-01-23 16:27:46 +03:00
|
|
|
} else if (!this.state.eventIndexingEnabled && EventIndexPeg.supportIsInstalled()) {
|
|
|
|
eventIndexingSettings = (
|
|
|
|
<div>
|
2021-07-20 00:43:11 +03:00
|
|
|
<div className='mx_SettingsTab_subsectionText'>{ _t(
|
2021-04-23 20:11:54 +03:00
|
|
|
"Securely cache encrypted messages locally for them to " +
|
|
|
|
"appear in search results.",
|
2021-07-20 00:43:11 +03:00
|
|
|
) }</div>
|
2020-01-23 16:27:46 +03:00
|
|
|
<div>
|
2021-07-23 12:23:45 +03:00
|
|
|
<AccessibleButton
|
|
|
|
kind="primary"
|
|
|
|
disabled={this.state.enabling}
|
|
|
|
onClick={this.onEnable}
|
|
|
|
>
|
2021-07-20 00:43:11 +03:00
|
|
|
{ _t("Enable") }
|
2020-01-23 16:27:46 +03:00
|
|
|
</AccessibleButton>
|
2021-07-20 00:43:11 +03:00
|
|
|
{ this.state.enabling ? <InlineSpinner /> : <div /> }
|
2020-01-23 16:27:46 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2020-01-24 17:26:54 +03:00
|
|
|
} else if (EventIndexPeg.platformHasSupport() && !EventIndexPeg.supportIsInstalled()) {
|
2020-01-24 18:22:09 +03:00
|
|
|
const nativeLink = (
|
2021-03-29 18:03:06 +03:00
|
|
|
"https://github.com/vector-im/element-desktop/blob/develop/" +
|
2020-01-24 18:22:09 +03:00
|
|
|
"docs/native-node-modules.md#" +
|
|
|
|
"adding-seshat-for-search-in-e2e-encrypted-rooms"
|
|
|
|
);
|
|
|
|
|
2020-01-24 17:26:54 +03:00
|
|
|
eventIndexingSettings = (
|
2021-07-20 00:43:11 +03:00
|
|
|
<div className='mx_SettingsTab_subsectionText'>{ _t(
|
2021-04-23 20:11:54 +03:00
|
|
|
"%(brand)s is missing some components required for securely " +
|
|
|
|
"caching encrypted messages locally. If you'd like to " +
|
|
|
|
"experiment with this feature, build a custom %(brand)s Desktop " +
|
|
|
|
"with <nativeLink>search components added</nativeLink>.",
|
2020-01-24 17:26:54 +03:00
|
|
|
{
|
2021-04-23 20:11:54 +03:00
|
|
|
brand,
|
|
|
|
},
|
|
|
|
{
|
2021-07-23 12:23:45 +03:00
|
|
|
nativeLink: sub => <a
|
|
|
|
href={nativeLink}
|
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer noopener"
|
2021-07-20 00:43:11 +03:00
|
|
|
>{ sub }</a>,
|
2021-04-23 20:11:54 +03:00
|
|
|
},
|
2021-07-20 00:43:11 +03:00
|
|
|
) }</div>
|
2020-01-24 17:26:54 +03:00
|
|
|
);
|
2021-03-24 14:51:39 +03:00
|
|
|
} else if (!EventIndexPeg.platformHasSupport()) {
|
2020-01-21 12:06:04 +03:00
|
|
|
eventIndexingSettings = (
|
2021-07-20 00:43:11 +03:00
|
|
|
<div className='mx_SettingsTab_subsectionText'>{ _t(
|
2021-04-23 20:11:54 +03:00
|
|
|
"%(brand)s can't securely cache encrypted messages locally " +
|
|
|
|
"while running in a web browser. Use <desktopLink>%(brand)s Desktop</desktopLink> " +
|
|
|
|
"for encrypted messages to appear in search results.",
|
2020-01-21 12:06:04 +03:00
|
|
|
{
|
2021-04-23 20:11:54 +03:00
|
|
|
brand,
|
|
|
|
},
|
|
|
|
{
|
2021-07-23 12:23:45 +03:00
|
|
|
desktopLink: sub => <a
|
|
|
|
href="https://element.io/get-started"
|
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer noopener"
|
2021-07-20 00:43:11 +03:00
|
|
|
>{ sub }</a>,
|
2021-04-23 20:11:54 +03:00
|
|
|
},
|
2021-07-20 00:43:11 +03:00
|
|
|
) }</div>
|
2020-01-21 12:06:04 +03:00
|
|
|
);
|
2021-03-24 14:51:39 +03:00
|
|
|
} else {
|
|
|
|
eventIndexingSettings = (
|
|
|
|
<div className='mx_SettingsTab_subsectionText'>
|
|
|
|
<p>
|
2021-07-20 00:43:11 +03:00
|
|
|
{ this.state.enabling
|
2021-03-29 17:46:58 +03:00
|
|
|
? <InlineSpinner />
|
2021-04-23 19:31:27 +03:00
|
|
|
: _t("Message search initialisation failed")
|
2021-03-29 17:46:58 +03:00
|
|
|
}
|
2021-03-24 14:51:39 +03:00
|
|
|
</p>
|
2021-07-20 00:43:11 +03:00
|
|
|
{ EventIndexPeg.error && (
|
2021-04-23 20:11:54 +03:00
|
|
|
<details>
|
2021-07-20 00:43:11 +03:00
|
|
|
<summary>{ _t("Advanced") }</summary>
|
2021-04-23 20:11:54 +03:00
|
|
|
<code>
|
2021-07-20 00:43:11 +03:00
|
|
|
{ EventIndexPeg.error.message }
|
2021-04-23 20:11:54 +03:00
|
|
|
</code>
|
|
|
|
<p>
|
2021-04-26 16:02:53 +03:00
|
|
|
<AccessibleButton key="delete" kind="danger" onClick={this.confirmEventStoreReset}>
|
2021-07-20 00:43:11 +03:00
|
|
|
{ _t("Reset") }
|
2021-04-23 20:11:54 +03:00
|
|
|
</AccessibleButton>
|
|
|
|
</p>
|
|
|
|
</details>
|
2021-07-20 00:43:11 +03:00
|
|
|
) }
|
2021-03-24 14:51:39 +03:00
|
|
|
</div>
|
|
|
|
);
|
2020-01-17 19:10:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return eventIndexingSettings;
|
|
|
|
}
|
|
|
|
}
|