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 13:13:09 +03:00
|
|
|
import {formatBytes, formatCount} 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-01-20 19:43:55 +03:00
|
|
|
async updateCurrentRoom(room) {
|
|
|
|
const eventIndex = EventIndexPeg.get();
|
|
|
|
const stats = await eventIndex.getStats();
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
eventIndexSize: stats.size,
|
|
|
|
roomCount: stats.roomCount,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount(): void {
|
|
|
|
const eventIndex = EventIndexPeg.get();
|
|
|
|
|
|
|
|
if (eventIndex !== null) {
|
|
|
|
eventIndex.removeListener("changedCheckpoint", this.updateCurrentRoom.bind(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-01-20 19:43:55 +03:00
|
|
|
eventIndex.on("changedCheckpoint", this.updateCurrentRoom.bind(this));
|
|
|
|
|
2020-01-20 19:42:24 +03:00
|
|
|
const stats = await eventIndex.getStats();
|
|
|
|
eventIndexSize = stats.size;
|
|
|
|
roomCount = stats.roomCount;
|
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 13:13:09 +03:00
|
|
|
{_t( " to store messages from ")} {formatCount(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-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.",
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
'riotLink': (sub) => <a href="https://riot.im/download/desktop">{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;
|
|
|
|
}
|
|
|
|
}
|