2020-01-17 19:10:59 +03:00
|
|
|
/*
|
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
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-01-23 17:06:38 +03:00
|
|
|
import * as sdk from '../../../index';
|
2020-01-17 19:10:59 +03:00
|
|
|
import Modal from '../../../Modal';
|
2020-01-23 16:27:46 +03:00
|
|
|
import SettingsStore, {SettingLevel} from "../../../settings/SettingsStore";
|
2020-01-21 15:20:30 +03:00
|
|
|
import AccessibleButton from "../elements/AccessibleButton";
|
2020-01-24 18:15:06 +03:00
|
|
|
import {formatBytes, formatCountLong} from "../../../utils/FormattingUtils";
|
2020-01-17 19:10:59 +03:00
|
|
|
import EventIndexPeg from "../../../indexing/EventIndexPeg";
|
|
|
|
|
|
|
|
export default class EventIndexPanel extends React.Component {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-17 19:10:59 +03:00
|
|
|
async componentWillMount(): 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
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-21 15:20:30 +03:00
|
|
|
_onManage = async () => {
|
|
|
|
Modal.createTrackedDialogAsync('Message search', 'Message search',
|
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,
|
|
|
|
);
|
2020-01-17 19:10:59 +03:00
|
|
|
}
|
|
|
|
|
2020-01-23 16:27:46 +03:00
|
|
|
_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();
|
|
|
|
}
|
|
|
|
|
2020-01-17 19:10:59 +03:00
|
|
|
render() {
|
|
|
|
let eventIndexingSettings = null;
|
2020-01-23 17:06:38 +03:00
|
|
|
const InlineSpinner = sdk.getComponent('elements.InlineSpinner');
|
2020-01-17 19:10:59 +03:00
|
|
|
|
|
|
|
if (EventIndexPeg.get() !== null) {
|
|
|
|
eventIndexingSettings = (
|
2020-01-21 12:06:04 +03:00
|
|
|
<div>
|
2020-01-17 19:10:59 +03:00
|
|
|
<div className='mx_SettingsTab_subsectionText'>
|
2020-01-21 15:20:30 +03:00
|
|
|
{_t( "Securely cache encrypted messages locally for them " +
|
|
|
|
"to appear in search results, using ")
|
|
|
|
} {formatBytes(this.state.eventIndexSize, 0)}
|
2020-01-24 18:15:06 +03:00
|
|
|
{_t( " to store messages from ")}
|
|
|
|
{formatCountLong(this.state.roomCount)} {_t("rooms.")}
|
2020-01-21 15:20:30 +03:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<AccessibleButton kind="primary" onClick={this._onManage}>
|
|
|
|
{_t("Manage")}
|
|
|
|
</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>
|
|
|
|
<div className='mx_SettingsTab_subsectionText'>
|
2020-01-23 17:06:38 +03:00
|
|
|
{_t( "Securely cache encrypted messages locally for them to " +
|
|
|
|
"appear in search results.")}
|
2020-01-23 16:27:46 +03:00
|
|
|
</div>
|
|
|
|
<div>
|
2020-01-23 17:06:38 +03:00
|
|
|
<AccessibleButton kind="primary" disabled={this.state.enabling}
|
|
|
|
onClick={this._onEnable}>
|
2020-01-23 16:27:46 +03:00
|
|
|
{_t("Enable")}
|
|
|
|
</AccessibleButton>
|
2020-01-23 17:06:38 +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 = (
|
|
|
|
"https://github.com/vector-im/riot-web/blob/develop/" +
|
|
|
|
"docs/native-node-modules.md#" +
|
|
|
|
"adding-seshat-for-search-in-e2e-encrypted-rooms"
|
|
|
|
);
|
|
|
|
|
2020-01-24 17:26:54 +03:00
|
|
|
eventIndexingSettings = (
|
|
|
|
<div>
|
|
|
|
{
|
|
|
|
_t( "Riot is missing some components required for securely " +
|
|
|
|
"caching encrypted messages locally. If you'd like to " +
|
|
|
|
"experiment with this feature, build a custom Riot Desktop " +
|
|
|
|
"with <nativeLink>search components added</nativeLink>.",
|
|
|
|
{},
|
|
|
|
{
|
2020-01-27 18:50:33 +03:00
|
|
|
'nativeLink': (sub) => <a href={nativeLink} target="_blank"
|
2020-02-24 01:14:29 +03:00
|
|
|
rel="noreferrer noopener">{sub}</a>,
|
2020-01-24 17:26:54 +03:00
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
);
|
2020-01-21 12:06:04 +03:00
|
|
|
} else {
|
|
|
|
eventIndexingSettings = (
|
|
|
|
<div>
|
|
|
|
{
|
2020-01-23 16:27:46 +03:00
|
|
|
_t( "Riot can't securely cache encrypted messages locally " +
|
2020-01-24 13:44:56 +03:00
|
|
|
"while running in a web browser. Use <riotLink>Riot Desktop</riotLink> " +
|
|
|
|
"for encrypted messages to appear in search results.",
|
|
|
|
{},
|
|
|
|
{
|
2020-01-27 18:50:33 +03:00
|
|
|
'riotLink': (sub) => <a href="https://riot.im/download/desktop"
|
2020-02-24 01:14:29 +03:00
|
|
|
target="_blank" rel="noreferrer noopener">{sub}</a>,
|
2020-01-24 13:56:43 +03:00
|
|
|
},
|
2020-01-21 12:06:04 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
);
|
2020-01-17 19:10:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return eventIndexingSettings;
|
|
|
|
}
|
|
|
|
}
|