Skip to content

Commit 1dbdd0a

Browse files
committed
ElectronPlatform: Add support for a event index using Seshat.
1 parent a0599e8 commit 1dbdd0a

4 files changed

Lines changed: 170 additions & 2 deletions

File tree

‎electron_app/package.json‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
"version": "1.4.2",
66
"description": "A feature-rich client for Matrix.org",
77
"author": "New Vector Ltd.",
8+
"scripts": {
9+
"build": "electron-build-env --electron 6.0.3 neon build seshat-node --release",
10+
"postinstall": "yarn build"
11+
},
812
"dependencies": {
913
"auto-launch": "^5.0.1",
1014
"electron-store": "^2.0.0",
1115
"electron-window-state": "^4.1.0",
1216
"minimist": "^1.2.0",
13-
"png-to-ico": "^1.0.2"
17+
"png-to-ico": "^1.0.2",
18+
"make-dir": "^3.0.0",
19+
"seshat-node": "^0.2.0"
1420
}
1521
}

‎electron_app/src/electron-main.js‎

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const { migrateFromOldOrigin } = require('./originMigrator');
3939

4040
const windowStateKeeper = require('electron-window-state');
4141
const Store = require('electron-store');
42+
const seshat = require('seshat-node');
43+
const makeDir = require('make-dir');
4244

4345
if (argv["help"]) {
4446
console.log("Options:");
@@ -82,8 +84,12 @@ try {
8284
// Could not load local config, this is expected in most cases.
8385
}
8486

87+
88+
const eventStorePath = path.join(app.getPath('userData'), 'EventStore');
8589
const store = new Store({ name: "electron-config" });
8690

91+
let eventIndex = null;
92+
8793
let mainWindow = null;
8894
global.appQuitting = false;
8995
global.minimizeToTray = store.get('minimizeToTray', true);
@@ -149,6 +155,17 @@ autoUpdater.on('update-downloaded', (ev, releaseNotes, releaseName, releaseDate,
149155
ipcMain.on('ipcCall', async function(ev, payload) {
150156
if (!mainWindow) return;
151157

158+
const send_error = (id, e) => {
159+
const error = {
160+
message: e.message
161+
}
162+
163+
mainWindow.webContents.send('ipcReply', {
164+
id:id,
165+
error: error
166+
});
167+
}
168+
152169
const args = payload.args || [];
153170
let ret;
154171

@@ -200,6 +217,105 @@ ipcMain.on('ipcCall', async function(ev, payload) {
200217
case 'getConfig':
201218
ret = vectorConfig;
202219
break;
220+
221+
case 'initEventIndex':
222+
if (args[0] && eventIndex === null) {
223+
let p = path.normalize(path.join(eventStorePath, args[0]));
224+
try {
225+
await makeDir(p);
226+
eventIndex = new seshat(p);
227+
console.log("Initialized event store");
228+
} catch (e) {
229+
send_error(payload.id, e);
230+
return;
231+
}
232+
}
233+
break;
234+
235+
case 'deleteEventIndex':
236+
await eventIndex.delete();
237+
eventIndex = null;
238+
239+
case 'isEventIndexEmpty':
240+
if (eventIndex === null) ret = true;
241+
else ret = await eventIndex.isEmpty();
242+
break;
243+
244+
case 'addEventToIndex':
245+
try {
246+
eventIndex.addEvent(args[0], args[1]);
247+
} catch (e) {
248+
send_error(payload.id, e);
249+
return;
250+
}
251+
break;
252+
253+
case 'commitLiveEvents':
254+
try {
255+
ret = await eventIndex.commit();
256+
} catch (e) {
257+
send_error(payload.id, e);
258+
return;
259+
}
260+
break;
261+
262+
case 'searchEventIndex':
263+
try {
264+
ret = await eventIndex.search(args[0]);
265+
} catch (e) {
266+
send_error(payload.id, e);
267+
return;
268+
}
269+
break;
270+
271+
case 'addHistoricEvents':
272+
if (eventIndex === null) ret = false;
273+
else {
274+
try {
275+
ret = await eventIndex.addHistoricEvents(
276+
args[0], args[1], args[2]);
277+
} catch (e) {
278+
send_error(payload.id, e);
279+
return;
280+
}
281+
}
282+
break;
283+
284+
case 'removeCrawlerCheckpoint':
285+
if (eventIndex === null) ret = false;
286+
else {
287+
try {
288+
ret = await eventIndex.removeCrawlerCheckpoint(args[0]);
289+
} catch (e) {
290+
send_error(payload.id, e);
291+
return;
292+
}
293+
}
294+
break;
295+
296+
case 'addCrawlerCheckpoint':
297+
if (eventIndex === null) ret = false;
298+
else {
299+
try {
300+
ret = await eventIndex.addCrawlerCheckpoint(args[0]);
301+
} catch (e) {
302+
send_error(payload.id, e);
303+
return;
304+
}
305+
}
306+
break;
307+
308+
case 'loadCheckpoints':
309+
if (eventIndex === null) ret = [];
310+
else {
311+
try {
312+
ret = await eventIndex.loadCheckpoints();
313+
} catch (e) {
314+
ret = [];
315+
}
316+
}
317+
break;
318+
203319
default:
204320
mainWindow.webContents.send('ipcReply', {
205321
id: payload.id,

‎package.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@
148148
"source-map-loader": "^0.2.4",
149149
"webpack": "^4.23.1",
150150
"webpack-cli": "^3.1.2",
151-
"webpack-dev-server": "^3.1.11"
151+
"webpack-dev-server": "^3.1.11",
152+
"electron-build-env": "^0.2.0",
153+
"neon-cli": "^0.3.1"
152154
},
153155
"build": {
154156
"appId": "im.riot.app",

‎src/vector/platform/ElectronPlatform.js‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,48 @@ export default class ElectronPlatform extends VectorBasePlatform {
293293
callbacks.resolve(payload.reply);
294294
}
295295
}
296+
297+
async initEventIndex(user_id: string): void {
298+
return this._ipcCall('initEventIndex', user_id);
299+
}
300+
301+
supportsEventIndexing(): boolean {
302+
return true
303+
}
304+
305+
async addEventToIndex(ev: {}, profile: {}) {
306+
return this._ipcCall('addEventToIndex', ev, profile);
307+
}
308+
309+
async isEventIndexEmpty(): Promise<boolean> {
310+
return this._ipcCall('isEventIndexEmpty');
311+
}
312+
313+
async commitLiveEvents(): Promise<{}> {
314+
return this._ipcCall('commitLiveEvents');
315+
}
316+
317+
async searchEventIndex(term: string): Promise<{}> {
318+
return this._ipcCall('searchEventIndex', term);
319+
}
320+
321+
async addHistoricEvents(events: string, checkpoint = null, oldCheckpoint = null): Promise<{}> {
322+
return this._ipcCall('addHistoricEvents', events, checkpoint, oldCheckpoint);
323+
}
324+
325+
async addCrawlerCheckpoint(checkpoint: {}): Promise<{}> {
326+
return this._ipcCall('addCrawlerCheckpoint', checkpoint);
327+
}
328+
329+
async removeCrawlerCheckpoint(checkpoint: {}): Promise<{}> {
330+
return this._ipcCall('removeCrawlerCheckpoint', checkpoint);
331+
}
332+
333+
async loadCheckpoints(checkpoint: {}): Promise<[{}]> {
334+
return this._ipcCall('loadCheckpoints');
335+
}
336+
337+
async deleteEventIndex(): Promise<> {
338+
return this._ipcCall('deleteEventIndex');
339+
}
296340
}

0 commit comments

Comments
 (0)