Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit c40f97f

Browse files
committed
Add reset option for corrupted event index store
1 parent 356e4bc commit c40f97f

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright 2020 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import React from 'react';
18+
import PropTypes from 'prop-types';
19+
import {_t} from "../../../languageHandler";
20+
import * as sdk from "../../../index";
21+
import {replaceableComponent} from "../../../utils/replaceableComponent";
22+
23+
@replaceableComponent("views.dialogs.SeshatResetDialog")
24+
export default class SeshatResetDialog extends React.Component {
25+
static propTypes = {
26+
onFinished: PropTypes.func.isRequired,
27+
};
28+
render() {
29+
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
30+
const DialogButtons = sdk.getComponent('views.elements.DialogButtons');
31+
32+
return (
33+
<BaseDialog
34+
hasCancel={true}
35+
onFinished={this.props.onFinished.bind(null, false)}
36+
title={_t("Reset event index store?")}>
37+
<div>
38+
<p>
39+
{_t(
40+
"Your event store appears corrupted. " +
41+
"This action will restart this application.",
42+
)}
43+
</p>
44+
</div>
45+
<DialogButtons
46+
primaryButton={_t("Reset event store")}
47+
onPrimaryButtonClick={this.props.onFinished.bind(null, true)}
48+
primaryButtonClass="danger"
49+
cancelButton={_t("Cancel")}
50+
onCancel={this.props.onFinished.bind(null, false)}
51+
/>
52+
</BaseDialog>
53+
);
54+
}
55+
}

src/components/views/settings/EventIndexPanel.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {formatBytes, formatCountLong} from "../../../utils/FormattingUtils";
2626
import EventIndexPeg from "../../../indexing/EventIndexPeg";
2727
import {SettingLevel} from "../../../settings/SettingLevel";
2828
import {replaceableComponent} from "../../../utils/replaceableComponent";
29+
import SeshatResetDialog from '../dialogs/SeshatResetDialog';
2930

3031
@replaceableComponent("views.settings.EventIndexPanel")
3132
export default class EventIndexPanel extends React.Component {
@@ -122,6 +123,16 @@ export default class EventIndexPanel extends React.Component {
122123
await this.updateState();
123124
}
124125

126+
_confirmEventStoreReset() {
127+
Modal.createDialog(SeshatResetDialog, {
128+
onFinished: (success) => {
129+
if (success) {
130+
EventIndexPeg.resetEventStore();
131+
}
132+
},
133+
});
134+
}
135+
125136
render() {
126137
let eventIndexingSettings = null;
127138
const InlineSpinner = sdk.getComponent('elements.InlineSpinner');
@@ -220,6 +231,11 @@ export default class EventIndexPanel extends React.Component {
220231
<code>
221232
{EventIndexPeg.error.message}
222233
</code>
234+
<p>
235+
<AccessibleButton key="delete" kind="danger" onClick={this._confirmEventStoreReset}>
236+
{_t("Reset")}
237+
</AccessibleButton>
238+
</p>
223239
</details>
224240
)}
225241

src/i18n/strings/en_EN.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,6 +2300,9 @@
23002300
"Use your preferred Matrix homeserver if you have one, or host your own.": "Use your preferred Matrix homeserver if you have one, or host your own.",
23012301
"Learn more": "Learn more",
23022302
"About homeservers": "About homeservers",
2303+
"Reset event index store?": "Reset event index store?",
2304+
"Your event store appears corrupted. This action will restart this application.": "Your event store appears corrupted. This action will restart this application.",
2305+
"Reset event store": "Reset event store",
23032306
"Sign out and remove encryption keys?": "Sign out and remove encryption keys?",
23042307
"Clear Storage and Sign Out": "Clear Storage and Sign Out",
23052308
"Send Logs": "Send Logs",

src/indexing/BaseEventIndexManager.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,14 @@ export default abstract class BaseEventIndexManager {
309309
async deleteEventIndex(): Promise<void> {
310310
throw new Error("Unimplemented");
311311
}
312+
313+
/**
314+
* Reset a potentially corrupted event store
315+
*
316+
* @return {Promise} A promise that will resolve once the event store has
317+
* been deleted.
318+
*/
319+
async resetEventStore(): Promise<void> {
320+
throw new Error("Unimplemented");
321+
}
312322
}

src/indexing/EventIndexPeg.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ class EventIndexPeg {
179179
await indexManager.deleteEventIndex();
180180
}
181181
}
182+
183+
resetEventStore() {
184+
const indexManager = PlatformPeg.get().getEventIndexingManager();
185+
return indexManager.resetEventStore();
186+
}
182187
}
183188

184189
if (!global.mxEventIndexPeg) {

0 commit comments

Comments
 (0)