mirror of
https://github.com/CringeStudios/element-desktop.git
synced 2025-01-31 05:29:58 +01:00
Merge branch 'poljar/seshat-1.2.0-updates'
This commit is contained in:
commit
defd4550e1
@ -43,10 +43,19 @@ const Store = require('electron-store');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const afs = fs.promises;
|
const afs = fs.promises;
|
||||||
|
|
||||||
let Seshat = null;
|
let seshatSupported = false;
|
||||||
|
let Seshat;
|
||||||
|
let SeshatRecovery;
|
||||||
|
let ReindexError;
|
||||||
|
|
||||||
|
const seshatPassphrase = "DEFAULT_PASSPHRASE";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Seshat = require('matrix-seshat');
|
const seshatModule = require('matrix-seshat');
|
||||||
|
Seshat = seshatModule.Seshat;
|
||||||
|
SeshatRecovery = seshatModule.SeshatRecovery;
|
||||||
|
ReindexError = seshatModule.ReindexError;
|
||||||
|
seshatSupported = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.code === "MODULE_NOT_FOUND") {
|
if (e.code === "MODULE_NOT_FOUND") {
|
||||||
console.log("Seshat isn't installed, event indexing is disabled.");
|
console.log("Seshat isn't installed, event indexing is disabled.");
|
||||||
@ -349,18 +358,36 @@ ipcMain.on('seshat', async function(ev, payload) {
|
|||||||
|
|
||||||
switch (payload.name) {
|
switch (payload.name) {
|
||||||
case 'supportsEventIndexing':
|
case 'supportsEventIndexing':
|
||||||
if (Seshat === null) ret = false;
|
ret = seshatSupported;
|
||||||
else ret = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'initEventIndex':
|
case 'initEventIndex':
|
||||||
if (eventIndex === null) {
|
if (eventIndex === null) {
|
||||||
try {
|
try {
|
||||||
await afs.mkdir(eventStorePath, {recursive: true});
|
await afs.mkdir(eventStorePath, {recursive: true});
|
||||||
eventIndex = new Seshat(eventStorePath, {passphrase: "DEFAULT_PASSPHRASE"});
|
eventIndex = new Seshat(eventStorePath, {passphrase: seshatPassphrase});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
sendError(payload.id, e);
|
if (e instanceof ReindexError) {
|
||||||
return;
|
// If this is a reindex error, the index schema
|
||||||
|
// changed. Try to open the database in recovery mode,
|
||||||
|
// reindex the database and finally try to open the
|
||||||
|
// database again.
|
||||||
|
try {
|
||||||
|
const recoveryIndex = new SeshatRecovery(eventStorePath, {
|
||||||
|
passphrase: seshatPassphrase,
|
||||||
|
});
|
||||||
|
await recoveryIndex.reindex();
|
||||||
|
eventIndex = new Seshat(eventStorePath, {
|
||||||
|
passphrase: seshatPassphrase,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
sendError(payload.id, e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sendError(payload.id, e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -400,6 +427,15 @@ ipcMain.on('seshat', async function(ev, payload) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'deleteEvent':
|
||||||
|
try {
|
||||||
|
ret = await eventIndex.deleteEvent(args[0]);
|
||||||
|
} catch (e) {
|
||||||
|
sendError(payload.id, e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 'commitLiveEvents':
|
case 'commitLiveEvents':
|
||||||
try {
|
try {
|
||||||
ret = await eventIndex.commit();
|
ret = await eventIndex.commit();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user