2019-11-13 14:25:16 +03:00
|
|
|
/*
|
2021-04-06 14:26:50 +03:00
|
|
|
Copyright 2019-2021 The Matrix.org Foundation C.I.C.
|
2019-11-13 14:25:16 +03:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2021-07-10 17:43:46 +03:00
|
|
|
import { IMatrixProfile, IEventWithRoomId as IMatrixEvent, IResultRoomEvents } from "matrix-js-sdk/src/@types/search";
|
2022-03-01 23:42:05 +03:00
|
|
|
import { Direction } from "matrix-js-sdk/src/matrix";
|
2021-07-10 17:43:46 +03:00
|
|
|
|
2020-07-21 18:22:17 +03:00
|
|
|
// The following interfaces take their names and member names from seshat and the spec
|
2020-07-21 12:29:05 +03:00
|
|
|
/* eslint-disable camelcase */
|
2021-06-19 17:37:06 +03:00
|
|
|
export interface ICrawlerCheckpoint {
|
2019-11-13 14:25:16 +03:00
|
|
|
roomId: string;
|
2023-02-24 18:28:40 +03:00
|
|
|
token: string | null;
|
2021-06-07 12:57:11 +03:00
|
|
|
fullCrawl?: boolean;
|
2021-07-10 17:43:46 +03:00
|
|
|
direction: Direction;
|
2019-11-13 14:25:16 +03:00
|
|
|
}
|
|
|
|
|
2021-06-19 17:37:06 +03:00
|
|
|
export interface ISearchArgs {
|
2020-07-21 12:29:05 +03:00
|
|
|
search_term: string;
|
|
|
|
before_limit: number;
|
|
|
|
after_limit: number;
|
|
|
|
order_by_recency: boolean;
|
|
|
|
room_id?: string;
|
2021-07-10 17:43:46 +03:00
|
|
|
limit: number;
|
|
|
|
next_batch?: string;
|
2019-11-13 14:25:16 +03:00
|
|
|
}
|
|
|
|
|
2021-06-19 17:37:06 +03:00
|
|
|
export interface IEventAndProfile {
|
|
|
|
event: IMatrixEvent;
|
|
|
|
profile: IMatrixProfile;
|
2019-11-13 14:25:16 +03:00
|
|
|
}
|
|
|
|
|
2021-06-19 17:37:06 +03:00
|
|
|
export interface ILoadArgs {
|
2020-01-15 14:04:27 +03:00
|
|
|
roomId: string;
|
|
|
|
limit: number;
|
2021-06-07 12:57:11 +03:00
|
|
|
fromEvent?: string;
|
|
|
|
direction?: string;
|
2020-01-15 14:04:27 +03:00
|
|
|
}
|
|
|
|
|
2021-06-19 17:37:06 +03:00
|
|
|
export interface IIndexStats {
|
2020-01-20 19:42:24 +03:00
|
|
|
size: number;
|
2021-06-07 12:57:11 +03:00
|
|
|
eventCount: number;
|
|
|
|
roomCount: number;
|
2020-01-20 19:42:24 +03:00
|
|
|
}
|
|
|
|
|
2019-11-13 14:25:16 +03:00
|
|
|
/**
|
|
|
|
* Base class for classes that provide platform-specific event indexing.
|
|
|
|
*
|
|
|
|
* Instances of this class are provided by the application.
|
|
|
|
*/
|
2020-05-21 20:06:36 +03:00
|
|
|
export default abstract class BaseEventIndexManager {
|
2019-11-13 17:39:06 +03:00
|
|
|
/**
|
|
|
|
* Does our EventIndexManager support event indexing.
|
|
|
|
*
|
2019-11-18 12:18:09 +03:00
|
|
|
* If an EventIndexManager implementor has runtime dependencies that
|
2019-11-13 17:39:06 +03:00
|
|
|
* optionally enable event indexing they may override this method to perform
|
|
|
|
* the necessary runtime checks here.
|
|
|
|
*
|
|
|
|
* @return {Promise} A promise that will resolve to true if event indexing
|
|
|
|
* is supported, false otherwise.
|
|
|
|
*/
|
2022-12-16 15:29:59 +03:00
|
|
|
public async supportsEventIndexing(): Promise<boolean> {
|
2019-11-13 17:39:06 +03:00
|
|
|
return true;
|
|
|
|
}
|
2019-11-13 14:25:16 +03:00
|
|
|
/**
|
|
|
|
* Initialize the event index for the given user.
|
|
|
|
*
|
2020-10-13 18:03:58 +03:00
|
|
|
* @param {string} userId The event that should be added to the index.
|
|
|
|
* @param {string} deviceId The profile of the event sender at the
|
2020-10-13 17:02:05 +03:00
|
|
|
*
|
2019-11-13 14:25:16 +03:00
|
|
|
* @return {Promise} A promise that will resolve when the event index is
|
|
|
|
* initialized.
|
|
|
|
*/
|
2022-12-16 15:29:59 +03:00
|
|
|
public async initEventIndex(userId: string, deviceId: string): Promise<void> {
|
2019-11-13 14:25:16 +03:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Queue up an event to be added to the index.
|
|
|
|
*
|
|
|
|
* @param {MatrixEvent} ev The event that should be added to the index.
|
2021-06-19 17:37:06 +03:00
|
|
|
* @param {IMatrixProfile} profile The profile of the event sender at the
|
2022-05-10 01:52:05 +03:00
|
|
|
* time the event was received.
|
2019-11-13 14:25:16 +03:00
|
|
|
*
|
|
|
|
* @return {Promise} A promise that will resolve when the was queued up for
|
|
|
|
* addition.
|
|
|
|
*/
|
2022-12-16 15:29:59 +03:00
|
|
|
public async addEventToIndex(ev: IMatrixEvent, profile: IMatrixProfile): Promise<void> {
|
2019-11-13 14:25:16 +03:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
|
2022-12-16 15:29:59 +03:00
|
|
|
public async deleteEvent(eventId: string): Promise<boolean> {
|
2020-03-12 13:42:02 +03:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
|
2022-12-16 15:29:59 +03:00
|
|
|
public async isEventIndexEmpty(): Promise<boolean> {
|
2021-04-06 14:26:50 +03:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
|
2019-11-13 14:25:16 +03:00
|
|
|
/**
|
|
|
|
* Check if our event index is empty.
|
|
|
|
*/
|
2022-12-16 15:29:59 +03:00
|
|
|
public indexIsEmpty(): Promise<boolean> {
|
2019-11-13 14:25:16 +03:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
|
2020-06-08 17:43:20 +03:00
|
|
|
/**
|
|
|
|
* Check if the room with the given id is already indexed.
|
|
|
|
*
|
|
|
|
* @param {string} roomId The ID of the room which we want to check if it
|
|
|
|
* has been already indexed.
|
|
|
|
*
|
|
|
|
* @return {Promise<boolean>} Returns true if the index contains events for
|
|
|
|
* the given room, false otherwise.
|
|
|
|
*/
|
2022-12-16 15:29:59 +03:00
|
|
|
public isRoomIndexed(roomId: string): Promise<boolean> {
|
2020-06-08 17:43:20 +03:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
|
2019-11-26 15:14:53 +03:00
|
|
|
/**
|
2020-01-20 19:42:24 +03:00
|
|
|
* Get statistical information of the index.
|
|
|
|
*
|
2021-06-19 17:37:06 +03:00
|
|
|
* @return {Promise<IIndexStats>} A promise that will resolve to the index
|
2020-01-20 19:42:24 +03:00
|
|
|
* statistics.
|
2019-11-26 15:14:53 +03:00
|
|
|
*/
|
2022-12-16 15:29:59 +03:00
|
|
|
public async getStats(): Promise<IIndexStats> {
|
2019-11-26 15:14:53 +03:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
|
2020-06-17 18:12:13 +03:00
|
|
|
/**
|
|
|
|
* Get the user version of the database.
|
|
|
|
* @return {Promise<number>} A promise that will resolve to the user stored
|
|
|
|
* version number.
|
|
|
|
*/
|
2022-12-16 15:29:59 +03:00
|
|
|
public async getUserVersion(): Promise<number> {
|
2020-06-17 18:12:13 +03:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the user stored version to the given version number.
|
|
|
|
*
|
|
|
|
* @param {number} version The new version that should be stored in the
|
|
|
|
* database.
|
|
|
|
*
|
|
|
|
* @return {Promise<void>} A promise that will resolve once the new version
|
|
|
|
* is stored.
|
|
|
|
*/
|
2022-12-16 15:29:59 +03:00
|
|
|
public async setUserVersion(version: number): Promise<void> {
|
2020-06-17 18:12:13 +03:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
|
2019-11-13 14:25:16 +03:00
|
|
|
/**
|
|
|
|
* Commit the previously queued up events to the index.
|
|
|
|
*
|
|
|
|
* @return {Promise} A promise that will resolve once the queued up events
|
|
|
|
* were added to the index.
|
|
|
|
*/
|
2022-12-16 15:29:59 +03:00
|
|
|
public async commitLiveEvents(): Promise<void> {
|
2019-11-13 14:25:16 +03:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search the event index using the given term for matching events.
|
|
|
|
*
|
2021-06-19 17:37:06 +03:00
|
|
|
* @param {ISearchArgs} searchArgs The search configuration for the search,
|
2020-01-28 17:06:43 +03:00
|
|
|
* sets the search term and determines the search result contents.
|
2019-11-13 14:25:16 +03:00
|
|
|
*
|
2021-07-10 17:43:46 +03:00
|
|
|
* @return {Promise<IResultRoomEvents[]>} A promise that will resolve to an array
|
2019-11-13 14:25:16 +03:00
|
|
|
* of search results once the search is done.
|
|
|
|
*/
|
2022-12-16 15:29:59 +03:00
|
|
|
public async searchEventIndex(searchArgs: ISearchArgs): Promise<IResultRoomEvents> {
|
2019-11-13 14:25:16 +03:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add events from the room history to the event index.
|
|
|
|
*
|
|
|
|
* This is used to add a batch of events to the index.
|
|
|
|
*
|
2021-06-19 17:37:06 +03:00
|
|
|
* @param {[IEventAndProfile]} events The list of events and profiles that
|
2019-11-13 14:25:16 +03:00
|
|
|
* should be added to the event index.
|
2021-06-19 17:37:06 +03:00
|
|
|
* @param {[ICrawlerCheckpoint]} checkpoint A new crawler checkpoint that
|
2019-11-13 14:25:16 +03:00
|
|
|
* should be stored in the index which should be used to continue crawling
|
|
|
|
* the room.
|
2021-06-19 17:37:06 +03:00
|
|
|
* @param {[ICrawlerCheckpoint]} oldCheckpoint The checkpoint that was used
|
2019-11-13 14:25:16 +03:00
|
|
|
* to fetch the current batch of events. This checkpoint will be removed
|
|
|
|
* from the index.
|
|
|
|
*
|
|
|
|
* @return {Promise} A promise that will resolve to true if all the events
|
|
|
|
* were already added to the index, false otherwise.
|
|
|
|
*/
|
2022-12-16 15:29:59 +03:00
|
|
|
public async addHistoricEvents(
|
2021-06-19 17:37:06 +03:00
|
|
|
events: IEventAndProfile[],
|
|
|
|
checkpoint: ICrawlerCheckpoint | null,
|
|
|
|
oldCheckpoint: ICrawlerCheckpoint | null,
|
2020-05-21 20:06:36 +03:00
|
|
|
): Promise<boolean> {
|
2019-11-13 14:25:16 +03:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new crawler checkpoint to the index.
|
|
|
|
*
|
2021-06-19 17:37:06 +03:00
|
|
|
* @param {ICrawlerCheckpoint} checkpoint The checkpoint that should be added
|
2019-11-13 14:25:16 +03:00
|
|
|
* to the index.
|
|
|
|
*
|
|
|
|
* @return {Promise} A promise that will resolve once the checkpoint has
|
|
|
|
* been stored.
|
|
|
|
*/
|
2022-12-16 15:29:59 +03:00
|
|
|
public async addCrawlerCheckpoint(checkpoint: ICrawlerCheckpoint): Promise<void> {
|
2019-11-13 14:25:16 +03:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new crawler checkpoint to the index.
|
|
|
|
*
|
2021-06-19 17:37:06 +03:00
|
|
|
* @param {ICrawlerCheckpoint} checkpoint The checkpoint that should be
|
2019-11-13 14:25:16 +03:00
|
|
|
* removed from the index.
|
|
|
|
*
|
|
|
|
* @return {Promise} A promise that will resolve once the checkpoint has
|
|
|
|
* been removed.
|
|
|
|
*/
|
2022-12-16 15:29:59 +03:00
|
|
|
public async removeCrawlerCheckpoint(checkpoint: ICrawlerCheckpoint): Promise<void> {
|
2019-11-13 14:25:16 +03:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load the stored checkpoints from the index.
|
|
|
|
*
|
2021-06-19 17:37:06 +03:00
|
|
|
* @return {Promise<[ICrawlerCheckpoint]>} A promise that will resolve to an
|
2019-11-13 14:25:16 +03:00
|
|
|
* array of crawler checkpoints once they have been loaded from the index.
|
|
|
|
*/
|
2022-12-16 15:29:59 +03:00
|
|
|
public async loadCheckpoints(): Promise<ICrawlerCheckpoint[]> {
|
2019-11-13 14:25:16 +03:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
|
2020-01-15 14:04:27 +03:00
|
|
|
/** Load events that contain an mxc URL to a file from the index.
|
|
|
|
*
|
|
|
|
* @param {object} args Arguments object for the method.
|
|
|
|
* @param {string} args.roomId The ID of the room for which the events
|
|
|
|
* should be loaded.
|
|
|
|
* @param {number} args.limit The maximum number of events to return.
|
|
|
|
* @param {string} args.fromEvent An event id of a previous event returned
|
2020-01-17 13:06:05 +03:00
|
|
|
* by this method. Passing this means that we are going to continue loading
|
|
|
|
* events from this point in the history.
|
|
|
|
* @param {string} args.direction The direction to which we should continue
|
|
|
|
* loading events from. This is used only if fromEvent is used as well.
|
|
|
|
*
|
2021-06-19 17:37:06 +03:00
|
|
|
* @return {Promise<[IEventAndProfile]>} A promise that will resolve to an
|
2020-01-17 13:06:05 +03:00
|
|
|
* array of Matrix events that contain mxc URLs accompanied with the
|
|
|
|
* historic profile of the sender.
|
2020-01-15 14:04:27 +03:00
|
|
|
*/
|
2022-12-16 15:29:59 +03:00
|
|
|
public async loadFileEvents(args: ILoadArgs): Promise<IEventAndProfile[]> {
|
2020-01-15 14:04:27 +03:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
|
2019-11-14 18:13:22 +03:00
|
|
|
/**
|
|
|
|
* close our event index.
|
|
|
|
*
|
|
|
|
* @return {Promise} A promise that will resolve once the event index has
|
|
|
|
* been closed.
|
|
|
|
*/
|
2022-12-16 15:29:59 +03:00
|
|
|
public async closeEventIndex(): Promise<void> {
|
2019-11-14 18:13:22 +03:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
|
2019-11-13 14:25:16 +03:00
|
|
|
/**
|
|
|
|
* Delete our current event index.
|
|
|
|
*
|
|
|
|
* @return {Promise} A promise that will resolve once the event index has
|
|
|
|
* been deleted.
|
|
|
|
*/
|
2022-12-16 15:29:59 +03:00
|
|
|
public async deleteEventIndex(): Promise<void> {
|
2019-11-13 14:25:16 +03:00
|
|
|
throw new Error("Unimplemented");
|
|
|
|
}
|
|
|
|
}
|