Improve and consolidate typing

This commit is contained in:
Michael Telatynski 2021-07-10 15:43:46 +01:00
parent 829169ec87
commit bd175c6f40
21 changed files with 186 additions and 257 deletions

View file

@ -14,47 +14,16 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { IMatrixProfile, IEventWithRoomId as IMatrixEvent, IResultRoomEvents } from "matrix-js-sdk/src/@types/search";
import { Direction } from "matrix-js-sdk/src";
// The following interfaces take their names and member names from seshat and the spec
/* eslint-disable camelcase */
export interface IMatrixEvent {
type: string;
sender: string;
content: {};
event_id: string;
origin_server_ts: number;
unsigned?: {};
roomId: string;
}
export interface IMatrixProfile {
avatar_url: string;
displayname: string;
}
export interface ICrawlerCheckpoint {
roomId: string;
token: string;
fullCrawl?: boolean;
direction: string;
}
export interface IResultContext {
events_before: [IMatrixEvent];
events_after: [IMatrixEvent];
profile_info: Map<string, IMatrixProfile>;
}
export interface IResultsElement {
rank: number;
result: IMatrixEvent;
context: IResultContext;
}
export interface ISearchResult {
count: number;
results: [IResultsElement];
highlights: [string];
direction: Direction;
}
export interface ISearchArgs {
@ -63,6 +32,8 @@ export interface ISearchArgs {
after_limit: number;
order_by_recency: boolean;
room_id?: string;
limit: number;
next_batch?: string;
}
export interface IEventAndProfile {
@ -205,10 +176,10 @@ export default abstract class BaseEventIndexManager {
* @param {ISearchArgs} searchArgs The search configuration for the search,
* sets the search term and determines the search result contents.
*
* @return {Promise<[ISearchResult]>} A promise that will resolve to an array
* @return {Promise<IResultRoomEvents[]>} A promise that will resolve to an array
* of search results once the search is done.
*/
async searchEventIndex(searchArgs: ISearchArgs): Promise<ISearchResult> {
async searchEventIndex(searchArgs: ISearchArgs): Promise<IResultRoomEvents> {
throw new Error("Unimplemented");
}

View file

@ -23,6 +23,7 @@ import { EventTimelineSet } from 'matrix-js-sdk/src/models/event-timeline-set';
import { RoomState } from 'matrix-js-sdk/src/models/room-state';
import { TimelineWindow } from 'matrix-js-sdk/src/timeline-window';
import { sleep } from "matrix-js-sdk/src/utils";
import { IResultRoomEvents } from "matrix-js-sdk/src/@types/search";
import PlatformPeg from "../PlatformPeg";
import { MatrixClientPeg } from "../MatrixClientPeg";
@ -114,14 +115,14 @@ export default class EventIndex extends EventEmitter {
const backCheckpoint: ICrawlerCheckpoint = {
roomId: room.roomId,
token: token,
direction: "b",
direction: Direction.Backward,
fullCrawl: true,
};
const forwardCheckpoint: ICrawlerCheckpoint = {
roomId: room.roomId,
token: token,
direction: "f",
direction: Direction.Forward,
};
try {
@ -384,7 +385,7 @@ export default class EventIndex extends EventEmitter {
roomId: room.roomId,
token: token,
fullCrawl: fullCrawl,
direction: "b",
direction: Direction.Backward,
};
console.log("EventIndex: Adding checkpoint", checkpoint);
@ -671,10 +672,10 @@ export default class EventIndex extends EventEmitter {
* @param {ISearchArgs} searchArgs The search configuration for the search,
* sets the search term and determines the search result contents.
*
* @return {Promise<[SearchResult]>} A promise that will resolve to an array
* @return {Promise<IResultRoomEvents[]>} A promise that will resolve to an array
* of search results once the search is done.
*/
public async search(searchArgs: ISearchArgs) {
public async search(searchArgs: ISearchArgs): Promise<IResultRoomEvents> {
const indexManager = PlatformPeg.get().getEventIndexingManager();
return indexManager.searchEventIndex(searchArgs);
}