@@ -20,6 +20,7 @@ limitations under the License.
2020*/
2121
2222import VectorBasePlatform , { updateCheckStatusEnum } from './VectorBasePlatform' ;
23+ import BaseEventIndexManager from 'matrix-react-sdk/lib/BaseEventIndexManager' ;
2324import dis from 'matrix-react-sdk/lib/dispatcher' ;
2425import { _t } from 'matrix-react-sdk/lib/languageHandler' ;
2526import Promise from 'bluebird' ;
@@ -66,12 +67,100 @@ function getUpdateCheckStatus(status) {
6667 }
6768}
6869
70+ class SeshatIndexerManager extends BaseEventIndexManager {
71+ constructor ( ) {
72+ super ( ) ;
73+
74+ this . _pendingIpcCalls = { } ;
75+ this . _nextIpcCallId = 0 ;
76+ ipcRenderer . on ( 'seshatReply' , this . _onIpcReply . bind ( this ) ) ;
77+ }
78+
79+ async _ipcCall ( name : string , ...args : [ ] ) : Promise < { } > {
80+ // TODO this should be moved into the preload.js file.
81+ const ipcCallId = ++ this . _nextIpcCallId ;
82+ return new Promise ( ( resolve , reject ) => {
83+ this . _pendingIpcCalls [ ipcCallId ] = { resolve, reject} ;
84+ window . ipcRenderer . send ( 'seshat' , { id : ipcCallId , name, args} ) ;
85+ } ) ;
86+ }
87+
88+ _onIpcReply ( ev : { } , payload : { } ) {
89+ if ( payload . id === undefined ) {
90+ console . warn ( "Ignoring IPC reply with no ID" ) ;
91+ return ;
92+ }
93+
94+ if ( this . _pendingIpcCalls [ payload . id ] === undefined ) {
95+ console . warn ( "Unknown IPC payload ID: " + payload . id ) ;
96+ return ;
97+ }
98+
99+ const callbacks = this . _pendingIpcCalls [ payload . id ] ;
100+ delete this . _pendingIpcCalls [ payload . id ] ;
101+ if ( payload . error ) {
102+ callbacks . reject ( payload . error ) ;
103+ } else {
104+ callbacks . resolve ( payload . reply ) ;
105+ }
106+ }
107+
108+ async supportsEventIndexing ( ) : Promise < boolean > {
109+ return this . _ipcCall ( 'supportsEventIndexing' ) ;
110+ }
111+
112+ async initEventIndex ( userId : string ) : Promise < > {
113+ return this . _ipcCall ( 'initEventIndex' , userId ) ;
114+ }
115+
116+ async addEventToIndex ( ev : MatrixEvent , profile : MatrixProfile ) : Promise < > {
117+ return this . _ipcCall ( 'addEventToIndex' , ev , profile ) ;
118+ }
119+
120+ async isEventIndexEmpty ( ) : Promise < boolean > {
121+ return this . _ipcCall ( 'isEventIndexEmpty' ) ;
122+ }
123+
124+ async commitLiveEvents ( ) : Promise < > {
125+ return this . _ipcCall ( 'commitLiveEvents' ) ;
126+ }
127+
128+ async searchEventIndex ( searchConfig : SearchConfig ) : Promise < SearchResult > {
129+ return this . _ipcCall ( 'searchEventIndex' , searchConfig ) ;
130+ }
131+
132+ async addHistoricEvents (
133+ events : [ HistoricEvent ] ,
134+ checkpoint : CrawlerCheckpoint | null = null ,
135+ oldCheckpoint : CrawlerCheckpoint | null = null ,
136+ ) : Promise < > {
137+ return this . _ipcCall ( 'addHistoricEvents' , events , checkpoint , oldCheckpoint ) ;
138+ }
139+
140+ async addCrawlerCheckpoint ( checkpoint : CrawlerCheckpoint ) : Promise < > {
141+ return this . _ipcCall ( 'addCrawlerCheckpoint' , checkpoint ) ;
142+ }
143+
144+ async removeCrawlerCheckpoint ( checkpoint : CrawlerCheckpoint ) : Promise < > {
145+ return this . _ipcCall ( 'removeCrawlerCheckpoint' , checkpoint ) ;
146+ }
147+
148+ async loadCheckpoints ( ) : Promise < [ CrawlerCheckpoint ] > {
149+ return this . _ipcCall ( 'loadCheckpoints' ) ;
150+ }
151+
152+ async deleteEventIndex ( ) : Promise < > {
153+ return this . _ipcCall ( 'deleteEventIndex' ) ;
154+ }
155+ }
156+
69157export default class ElectronPlatform extends VectorBasePlatform {
70158 constructor ( ) {
71159 super ( ) ;
72160
73161 this . _pendingIpcCalls = { } ;
74162 this . _nextIpcCallId = 0 ;
163+ this . eventIndexManager = new SeshatIndexerManager ( ) ;
75164
76165 dis . register ( _onAction ) ;
77166 /*
@@ -294,47 +383,7 @@ export default class ElectronPlatform extends VectorBasePlatform {
294383 }
295384 }
296385
297- async initEventIndex ( userId : string ) : void {
298- return this . _ipcCall ( 'initEventIndex' , userId ) ;
299- }
300-
301- supportsEventIndexing ( ) : boolean {
302- return true ;
303- }
304-
305- async addEventToIndex ( ev : { } , profile : { } ) : void {
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' ) ;
386+ getEventIndexingManager ( ) : BaseEventIndexManager | null {
387+ return this . eventIndexManager ;
339388 }
340389}
0 commit comments